refactor: launcher tab bar scroller visibility

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-02-10 16:42:42 +08:00
parent 59e4f0d388
commit e757e63bf7
No known key found for this signature in database
2 changed files with 35 additions and 40 deletions

View file

@ -6,9 +6,14 @@
xmlns:c="using:SourceGit.Converters" xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.LauncherTabBar" x:Class="SourceGit.Views.LauncherTabBar"
x:DataType="vm:Launcher"> x:DataType="vm:Launcher"
x:Name="ThisControl">
<Grid ColumnDefinitions="Auto,*,Auto,Auto"> <Grid ColumnDefinitions="Auto,*,Auto,Auto">
<RepeatButton x:Name="LeftScrollIndicator" Grid.Column="0" Classes="icon_button" Width="18" Height="30" Click="ScrollTabsLeft"> <RepeatButton Grid.Column="0"
Classes="icon_button"
Width="18" Height="30"
Click="ScrollTabsLeft"
IsVisible="{Binding #ThisControl.IsScrollerVisible}">
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleLeft}"/> <Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleLeft}"/>
</RepeatButton> </RepeatButton>
@ -96,11 +101,11 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<Button x:Name="InnerNewTabBtn" <Button Classes="icon_button"
Classes="icon_button"
Width="16" Height="16" Width="16" Height="16"
Margin="8,0" Margin="8,0"
Command="{Binding AddNewTab}"> Command="{Binding AddNewTab}"
IsVisible="{Binding !#ThisControl.IsScrollerVisible}">
<ToolTip.Tip> <ToolTip.Tip>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/> <TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>
@ -113,16 +118,12 @@
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
<RepeatButton x:Name="RightScrollIndicator" Grid.Column="2" Classes="icon_button" Width="18" Height="30" Click="ScrollTabsRight"> <StackPanel Grid.Column="2" Orientation="Horizontal" IsVisible="{Binding #ThisControl.IsScrollerVisible}">
<RepeatButton Classes="icon_button" Width="18" Height="30" Click="ScrollTabsRight">
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/> <Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/>
</RepeatButton> </RepeatButton>
<Button x:Name="OuterNewTabBtn" <Button Classes="icon_button" Width="16" Height="16" Margin="8,0" Command="{Binding AddNewTab}">
Grid.Column="3"
Classes="icon_button"
Width="16" Height="16"
Margin="8,0"
Command="{Binding AddNewTab}">
<ToolTip.Tip> <ToolTip.Tip>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/> <TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>
@ -132,5 +133,6 @@
<Path Width="12" Height="12" Data="{StaticResource Icons.Plus}"/> <Path Width="12" Height="12" Data="{StaticResource Icons.Plus}"/>
</Button> </Button>
</StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -10,6 +10,15 @@ namespace SourceGit.Views
{ {
public partial class LauncherTabBar : UserControl public partial class LauncherTabBar : UserControl
{ {
public static readonly StyledProperty<bool> IsScrollerVisibleProperty =
AvaloniaProperty.Register<LauncherTabBar, bool>(nameof(IsScrollerVisible));
public bool IsScrollerVisible
{
get => GetValue(IsScrollerVisibleProperty);
set => SetValue(IsScrollerVisibleProperty, value);
}
public LauncherTabBar() public LauncherTabBar()
{ {
InitializeComponent(); InitializeComponent();
@ -43,7 +52,7 @@ namespace SourceGit.Views
if (containerEndX < startX || containerEndX > endX) if (containerEndX < startX || containerEndX > endX)
continue; continue;
if (OuterNewTabBtn.IsVisible && i == count - 1) if (IsScrollerVisible && i == count - 1)
break; break;
var separatorX = containerEndX - startX + LauncherTabsScroller.Bounds.X; var separatorX = containerEndX - startX + LauncherTabsScroller.Bounds.X;
@ -143,23 +152,7 @@ namespace SourceGit.Views
private void OnTabsLayoutUpdated(object _1, EventArgs _2) private void OnTabsLayoutUpdated(object _1, EventArgs _2)
{ {
if (LauncherTabsScroller.Extent.Width > LauncherTabsScroller.Viewport.Width) SetCurrentValue(IsScrollerVisibleProperty, LauncherTabsScroller.Extent.Width > LauncherTabsScroller.Viewport.Width);
{
LeftScrollIndicator.IsVisible = true;
LeftScrollIndicator.IsEnabled = LauncherTabsScroller.Offset.X > 0;
RightScrollIndicator.IsVisible = true;
RightScrollIndicator.IsEnabled = LauncherTabsScroller.Offset.X < LauncherTabsScroller.Extent.Width - LauncherTabsScroller.Viewport.Width;
InnerNewTabBtn.IsVisible = false;
OuterNewTabBtn.IsVisible = true;
}
else
{
LeftScrollIndicator.IsVisible = false;
RightScrollIndicator.IsVisible = false;
InnerNewTabBtn.IsVisible = true;
OuterNewTabBtn.IsVisible = false;
}
InvalidateVisual(); InvalidateVisual();
} }