feat: update layout.

This commit is contained in:
rabbitism
2024-04-28 18:06:49 +08:00
parent f5aae36754
commit 2b2259376a
4 changed files with 82 additions and 26 deletions

View File

@@ -38,8 +38,8 @@
<Rectangle <Rectangle
Name="{x:Static u:TimePickerPresenter.PART_FirstSeparator}" Name="{x:Static u:TimePickerPresenter.PART_FirstSeparator}"
Grid.Column="1" Grid.Column="1"
Width="1" Width="0.5"
Margin="0,4" Margin="0,8"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" /> Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<ScrollViewer <ScrollViewer
@@ -59,8 +59,8 @@
<Rectangle <Rectangle
Name="{x:Static u:TimePickerPresenter.PART_SecondSeparator}" Name="{x:Static u:TimePickerPresenter.PART_SecondSeparator}"
Grid.Column="3" Grid.Column="3"
Width="1" Width="0.5"
Margin="0,4" Margin="0,8"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" /> Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<ScrollViewer <ScrollViewer
@@ -80,8 +80,8 @@
<Rectangle <Rectangle
Name="{x:Static u:TimePickerPresenter.PART_ThirdSeparator}" Name="{x:Static u:TimePickerPresenter.PART_ThirdSeparator}"
Grid.Column="5" Grid.Column="5"
Width="1" Width="0.5"
Margin="0,4" Margin="0,8"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" /> Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<ScrollViewer <ScrollViewer

View File

@@ -29,25 +29,28 @@
<TextBox <TextBox
Name="{x:Static u:TimeRangePicker.PART_StartTextBox}" Name="{x:Static u:TimeRangePicker.PART_StartTextBox}"
Grid.Column="0" Grid.Column="0"
HorizontalAlignment="Stretch"
Background="Transparent"
CornerRadius="3 0 0 3"
MinHeight="{TemplateBinding MinHeight}" MinHeight="{TemplateBinding MinHeight}"
BorderThickness="1" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Background="Transparent"
BorderThickness="1"
CornerRadius="3 0 0 3"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
InnerLeftContent="{TemplateBinding InnerLeftContent}" InnerLeftContent="{TemplateBinding InnerLeftContent}"
IsReadOnly="{TemplateBinding IsReadonly}" IsReadOnly="{TemplateBinding IsReadonly}"
Watermark="{TemplateBinding StartWatermark}" /> Watermark="{TemplateBinding StartWatermark}" />
<TextBlock Grid.Column="1" Text="~" VerticalAlignment="Center"></TextBlock> <TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="~" />
<TextBox <TextBox
Name="{x:Static u:TimeRangePicker.PART_EndTextBox}" Name="{x:Static u:TimeRangePicker.PART_EndTextBox}"
MinHeight="{TemplateBinding MinHeight}"
Grid.Column="2" Grid.Column="2"
MinHeight="{TemplateBinding MinHeight}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Transparent" Background="Transparent"
CornerRadius="0" CornerRadius="0"
VerticalAlignment="Stretch"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
InnerRightContent="{TemplateBinding InnerRightContent}" InnerRightContent="{TemplateBinding InnerRightContent}"
IsReadOnly="{TemplateBinding IsReadonly}" IsReadOnly="{TemplateBinding IsReadonly}"
@@ -55,7 +58,7 @@
<Button <Button
Name="ClearButton" Name="ClearButton"
Grid.Column="3" Grid.Column="3"
Padding="0,0,8,0" Padding="8,0"
Command="{Binding $parent[iri:IClearControl].Clear}" Command="{Binding $parent[iri:IClearControl].Clear}"
Content="{DynamicResource IconButtonClearData}" Content="{DynamicResource IconButtonClearData}"
Focusable="False" Focusable="False"
@@ -64,7 +67,7 @@
<Button <Button
Name="{x:Static u:TimePicker.PART_Button}" Name="{x:Static u:TimePicker.PART_Button}"
Grid.Column="3" Grid.Column="3"
Padding="0,0,8,0" Padding="8,0"
Content="{DynamicResource TimePickerIconGlyph}" Content="{DynamicResource TimePickerIconGlyph}"
Focusable="False" Focusable="False"
Theme="{DynamicResource InnerIconButton}" /> Theme="{DynamicResource InnerIconButton}" />
@@ -72,7 +75,8 @@
<Popup <Popup
Name="{x:Static iri:PartNames.PART_Popup}" Name="{x:Static iri:PartNames.PART_Popup}"
IsLightDismissEnabled="True" IsLightDismissEnabled="True"
IsOpen="{TemplateBinding IsDropdownOpen, Mode=TwoWay}" IsOpen="{TemplateBinding IsDropdownOpen,
Mode=TwoWay}"
Placement="BottomEdgeAlignedLeft" Placement="BottomEdgeAlignedLeft"
PlacementTarget="Background"> PlacementTarget="Background">
<Border <Border
@@ -106,18 +110,50 @@
DockPanel.Dock="Bottom" DockPanel.Dock="Bottom"
IsVisible="{TemplateBinding PopupInnerBottomContent, IsVisible="{TemplateBinding PopupInnerBottomContent,
Converter={x:Static ObjectConverters.IsNotNull}}" /> Converter={x:Static ObjectConverters.IsNotNull}}" />
<UniformGrid Columns="2"> <Grid ColumnDefinitions="*, Auto, *" RowDefinitions="Auto, Auto, *">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="0,16"
HorizontalAlignment="Center"
FontWeight="Bold"
Text="Start Time" />
<TextBlock
Grid.Row="0"
Grid.Column="2"
Margin="0,16"
HorizontalAlignment="Center"
FontWeight="Bold"
Text="End Time" />
<Rectangle
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3"
Fill="{DynamicResource DateTimePickerSeparatorBackground}"
Margin="8 0"
Height="1" />
<u:TimePickerPresenter <u:TimePickerPresenter
Name="{x:Static u:TimeRangePicker.PART_StartPresenter}" Name="{x:Static u:TimeRangePicker.PART_StartPresenter}"
Grid.Row="2"
Grid.Column="0"
NeedsConfirmation="{TemplateBinding NeedConfirmation}" NeedsConfirmation="{TemplateBinding NeedConfirmation}"
PanelFormat="{TemplateBinding PanelFormat}" PanelFormat="{TemplateBinding PanelFormat}"
Time="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=StartTime, Mode=OneWayToSource}" /> Time="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=StartTime, Mode=OneWayToSource}" />
<Rectangle
Grid.Row="2"
Grid.Column="1"
Width="1"
Margin="0,4"
VerticalAlignment="Stretch"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<u:TimePickerPresenter <u:TimePickerPresenter
Name="{x:Static u:TimeRangePicker.PART_EndPresenter}" Name="{x:Static u:TimeRangePicker.PART_EndPresenter}"
Grid.Row="2"
Grid.Column="2"
NeedsConfirmation="{TemplateBinding NeedConfirmation}" NeedsConfirmation="{TemplateBinding NeedConfirmation}"
PanelFormat="{TemplateBinding PanelFormat}" PanelFormat="{TemplateBinding PanelFormat}"
Time="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EndTime, Mode=OneWayToSource}" /> Time="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EndTime, Mode=OneWayToSource}" />
</UniformGrid> </Grid>
</DockPanel> </DockPanel>
</Border> </Border>
</Popup> </Popup>

View File

@@ -94,13 +94,7 @@ public class TimePicker : TimePickerBase, IClearControl
private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e) private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e)
{ {
IsDropdownOpen = true; SetCurrentValue(IsDropdownOpenProperty, true);
}
protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
SetCurrentValue(IsDropdownOpenProperty, IsPointerOver);
} }
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)

View File

@@ -57,6 +57,25 @@ public class TimeRangePicker : TimePickerBase, IClearControl
static TimeRangePicker() static TimeRangePicker()
{ {
StartTimeProperty.Changed.AddClassHandler<TimeRangePicker, TimeSpan?>((picker, args) =>
picker.OnSelectionChanged(args, true));
EndTimeProperty.Changed.AddClassHandler<TimeRangePicker, TimeSpan?>((picker, args) =>
picker.OnSelectionChanged(args, false));
}
private void OnSelectionChanged(AvaloniaPropertyChangedEventArgs<TimeSpan?> args, bool start = true)
{
var textBox = start ? _startTextBox : _endTextBox;
if (textBox is null) return;
var time = args.NewValue.Value;
if (time is null)
{
textBox.Text = null;
return;
}
var date = new DateTime(1, 1, 1, time.Value.Hours, time.Value.Minutes, time.Value.Seconds);
var text = date.ToString(DisplayFormat);
textBox.Text = text;
} }
public string? StartWatermark public string? StartWatermark
@@ -89,6 +108,7 @@ public class TimeRangePicker : TimePickerBase, IClearControl
base.OnApplyTemplate(e); base.OnApplyTemplate(e);
GotFocusEvent.RemoveHandler(OnTextBoxGetFocus, _startTextBox, _endTextBox); GotFocusEvent.RemoveHandler(OnTextBoxGetFocus, _startTextBox, _endTextBox);
PointerPressedEvent.RemoveHandler(OnTextBoxPointerPressed, _startTextBox, _endTextBox);
_popup = e.NameScope.Find<Popup>(PartNames.PART_Popup); _popup = e.NameScope.Find<Popup>(PartNames.PART_Popup);
_startTextBox = e.NameScope.Find<TextBox>(PART_StartTextBox); _startTextBox = e.NameScope.Find<TextBox>(PART_StartTextBox);
@@ -98,6 +118,12 @@ public class TimeRangePicker : TimePickerBase, IClearControl
_button = e.NameScope.Find<Button>(PART_Button); _button = e.NameScope.Find<Button>(PART_Button);
GotFocusEvent.AddHandler(OnTextBoxGetFocus, _startTextBox, _endTextBox); GotFocusEvent.AddHandler(OnTextBoxGetFocus, _startTextBox, _endTextBox);
PointerPressedEvent.AddHandler(OnTextBoxPointerPressed, RoutingStrategies.Tunnel, false, _startTextBox, _endTextBox);
}
private void OnTextBoxPointerPressed(object sender, PointerPressedEventArgs e)
{
SetCurrentValue(IsDropdownOpenProperty, true);
} }
private void OnTextBoxGetFocus(object sender, GotFocusEventArgs e) private void OnTextBoxGetFocus(object sender, GotFocusEventArgs e)