Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from irihitech:main #8

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions demo/Sandbox/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,17 @@
</Design.DataContext>

<Grid>
<DataGrid ItemsSource="{Binding Items}" IsReadOnly="False" HorizontalAlignment="Left">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>

<DataGridTemplateColumn Width="2*" Header="Address" MaxWidth="300" MinWidth="300">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Address}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<u:IPv4Box
HorizontalAlignment="Stretch"
IPAddress="{Binding Address}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<u:Form>
<u:FormItem Label="_Numeric">
<u:NumericIntUpDown/>
</u:FormItem>
<u:FormItem Label="_AnotherNumeric">
<u:NumericIntUpDown/>
</u:FormItem>
<u:FormItem Label="_TextBox">
<TextBox/>
</u:FormItem>
</u:Form>
</Grid>

</Window>
2 changes: 1 addition & 1 deletion src/Ursa/Controls/DateTimePicker/DateTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void OnDateSelected(object? sender, CalendarDayButtonEventArgs e)
}
}

private void OnTimeSelectedChanged(object sender, TimeChangedEventArgs e)
private void OnTimeSelectedChanged(object? sender, TimeChangedEventArgs e)
{
if (SelectedDate is null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ursa/Controls/DateTimePicker/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
SyncTimeToText(SelectedTime);
}

private void OnPresenterTimeChanged(object sender, TimeChangedEventArgs e)
private void OnPresenterTimeChanged(object? sender, TimeChangedEventArgs e)
{
if (_suppressTextPresenterEvent) return;
SetCurrentValue(SelectedTimeProperty, e.NewTime);
Expand Down
2 changes: 1 addition & 1 deletion src/Ursa/Controls/DateTimePicker/TimeRangePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
SyncTimeToText(EndTime, false);
}

private void OnPresenterTimeChanged(object sender, TimeChangedEventArgs e)
private void OnPresenterTimeChanged(object? sender, TimeChangedEventArgs e)
{
if (_suppressTextPresenterEvent) return;
SetCurrentValue(Equals(sender, _startPresenter) ? StartTimeProperty : EndTimeProperty, e.NewTime);
Expand Down
30 changes: 30 additions & 0 deletions src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl, IInnerCon
protected ButtonSpinner? _spinner;
protected TextBox? _textBox;
protected internal Panel? _dragPanel;
private bool _isFocused;

private Point? _point;
protected internal bool _updateFromTextInput;
Expand Down Expand Up @@ -149,6 +150,7 @@ public bool ShowButtonSpinner

static NumericUpDown()
{
FocusableProperty.OverrideDefaultValue<NumericUpDown>(true);
NumberFormatProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
FormatStringProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
IsReadOnlyProperty.Changed.AddClassHandler<NumericUpDown, bool>((o, args) => o.OnIsReadOnlyChanged(args));
Expand Down Expand Up @@ -216,6 +218,34 @@ protected override void OnLostFocus(RoutedEventArgs e)
{
_dragPanel.IsVisible = true;
}
FocusChanged(IsKeyboardFocusWithin);
}

protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
FocusChanged(IsKeyboardFocusWithin);
}

private void FocusChanged(bool hasFocus)
{
// The OnGotFocus & OnLostFocus are asynchronously and cannot
// reliably tell you that have the focus. All they do is let you
// know that the focus changed sometime in the past. To determine
// if you currently have the focus you need to do consult the
// FocusManager.

bool wasFocused = _isFocused;
_isFocused = hasFocus;

if (hasFocus)
{

if (!wasFocused && _textBox != null)
{
_textBox.Focus();
}
}
}

protected override void OnKeyDown(KeyEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void FormItem_Generation()
window.Show();

var form = window.FindControl<Form>("Form");
Assert.NotNull(form);
var logicalChildren = form.GetLogicalChildren().ToList();
Assert.True(logicalChildren.All(a=>a is FormItem));
Assert.IsType<TextBox>(logicalChildren[0].LogicalChildren[0]);
Expand Down Expand Up @@ -65,6 +66,7 @@ public void FormGroup_Generation()
window.Show();

var form = window.FindControl<Form>("Form");
Assert.NotNull(form);
var logicalChildren = form.GetLogicalChildren().ToList();
Assert.True(logicalChildren.All(a=>a is FormGroup));
var formGroup = (FormGroup)logicalChildren[0];
Expand Down Expand Up @@ -108,6 +110,7 @@ public void Mixture_Generation()
window.Show();

var form = window.FindControl<Form>("Form");
Assert.NotNull(form);
var logicalChildren = form.GetLogicalChildren().ToList();
Assert.True(logicalChildren.All(a=>a is FormItem || a is FormGroup));
Assert.IsType<TextBox>(logicalChildren[0].LogicalChildren[0]);
Expand Down