style<Launcher>: supports two size rules for tabs in titlebar - fixed width or size to content

This commit is contained in:
leo 2024-03-01 14:09:39 +08:00
parent e3a7abe776
commit 7b70951c93
6 changed files with 40 additions and 10 deletions

View file

@ -138,19 +138,17 @@
</ContextMenu>
</Border.ContextMenu>
<Grid Classes="launcher_pagetab_container" Width="200" Height="30" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
<Path Classes="launcher_pagetab_icon"
Grid.Column="0"
Width="12" Height="12" Margin="12,0,8,0"
<v:LauncherTab UseFixedTabWidth="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFixedTabWidth}" Height="30" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
<Path Grid.Column="0"
Width="12" Height="12" Margin="12,0"
Fill="{Binding Node.Bookmark, Converter={x:Static c:BookmarkConverters.ToBrush}}"
StrokeThickness="{Binding Node.Bookmark, Converter={x:Static c:BookmarkConverters.ToStrokeThickness}}"
Stroke="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Bookmark}"
IsVisible="{Binding Node.IsRepository}"
IsHitTestVisible="False"/>
<Path Classes="launcher_pagetab_icon"
Grid.Column="0"
Width="12" Height="12" Margin="12,0,8,0"
<Path Grid.Column="0"
Width="12" Height="12" Margin="12,0"
Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Repositories}"
IsVisible="{Binding !Node.IsRepository}"
@ -171,7 +169,7 @@
IsHitTestVisible="False"/>
<Button Grid.Column="2"
Classes="icon_button"
Width="16" Height="16" Margin="8,0"
Width="16" Height="16" Margin="12,0"
Command="{Binding #me.DataContext.(vm:Launcher).CloseTab}"
CommandParameter="{Binding}"
ToolTip.Tip="{DynamicResource Text.PageTabBar.Tab.Close}">
@ -186,7 +184,7 @@
</MultiBinding>
</Rectangle.IsVisible>
</Rectangle>
</Grid>
</v:LauncherTab>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>

View file

@ -2,8 +2,27 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using System;
namespace SourceGit.Views {
public class LauncherTab : Grid {
public static readonly StyledProperty<bool> UseFixedTabWidthProperty =
AvaloniaProperty.Register<LauncherTab, bool>(nameof(UseFixedTabWidth), false);
public bool UseFixedTabWidth {
get => GetValue(UseFixedTabWidthProperty);
set => SetValue(UseFixedTabWidthProperty, value);
}
protected override Type StyleKeyOverride => typeof(Grid);
static LauncherTab() {
UseFixedTabWidthProperty.Changed.AddClassHandler<LauncherTab>((tab, ev) => {
tab.Width = tab.UseFixedTabWidth ? 200.0 : double.NaN;
});
}
}
public partial class Launcher : Window, Models.INotificationReceiver {
public Launcher() {
DataContext = new ViewModels.Launcher();

View file

@ -57,7 +57,7 @@
<TabItem.Header>
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preference.General}"/>
</TabItem.Header>
<Grid Margin="8" RowDefinitions="32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Text="{DynamicResource Text.Preference.General.Locale}"
HorizontalAlignment="Right"
@ -135,6 +135,11 @@
IsChecked="{Binding RestoreTabs, Mode=TwoWay}"/>
<CheckBox Grid.Row="5" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preference.General.UseFixedTabWidth}"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFixedTabWidth, Mode=TwoWay}"/>
<CheckBox Grid.Row="6" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preference.General.UseMacOSStyle}"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseMacOSStyle, Mode=TwoWay}"