Skip to content

Commit

Permalink
Expand the TitleBar on touch when the title can't fit in one line
Browse files Browse the repository at this point in the history
  • Loading branch information
aetherstrata committed Feb 9, 2024
1 parent 76c97e7 commit 107fc67
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
18 changes: 10 additions & 8 deletions Aosta.Ava/Aosta.Ava/Assets/Resources/Colors.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@
<Color x:Key="Analogous3">#0077FF</Color>
<Color x:Key="Analogous4">#0044FF</Color>

<Color x:Key="Gray100">#E1E1E1</Color>
<Color x:Key="Gray200">#C8C8C8</Color>
<Color x:Key="Gray300">#ACACAC</Color>
<Color x:Key="Gray400">#919191</Color>
<Color x:Key="Gray500">#6E6E6E</Color>
<Color x:Key="Gray600">#404040</Color>
<Color x:Key="Gray100">#F5F5F5</Color>
<Color x:Key="Gray200">#EEEEEE</Color>
<Color x:Key="Gray300">#E0E0E0</Color>
<Color x:Key="Gray400">#BDBDBD</Color>
<Color x:Key="Gray500">#9E9E9E</Color>
<Color x:Key="Gray600">#757575</Color>
<Color x:Key="Gray700">#616161</Color>
<Color x:Key="Gray800">#424242</Color>
<Color x:Key="Gray900">#212121</Color>
<Color x:Key="Gray950">#141414</Color>

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="MainBackgroundBrush" Color="{StaticResource Gray100}"/>
<SolidColorBrush x:Key="FloatingBackgroundBrush" Color="{StaticResource BaseColor80L}"/>
<SolidColorBrush x:Key="TitleBarBackgroundBrush" Color="{StaticResource Gray100}"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="MainBackgroundBrush" Color="{StaticResource Gray950}"/>
<SolidColorBrush x:Key="FloatingBackgroundBrush" Color="{StaticResource BaseColor20L}"/>
<SolidColorBrush x:Key="TitleBarBackgroundBrush" Color="{StaticResource Gray900}"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
23 changes: 14 additions & 9 deletions Aosta.Ava/Aosta.Ava/Controls/TitleBar.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,37 @@
<Setter Property="Template">
<ControlTemplate>
<Grid ColumnDefinitions="10,Auto,5,*,5,Auto,10"
Background="{TemplateBinding Background}"
VerticalAlignment="Top">
Background="{DynamicResource TitleBarBackgroundBrush}"
VerticalAlignment="Top"
IsHitTestVisible="True">
<Button Grid.Column="1"
Margin="0,5"
IsVisible="{TemplateBinding IsBackEnabled}"
Command="{TemplateBinding BackCommand}"
Theme="{StaticResource TransparentButton}">
Command="{TemplateBinding BackCommand}">
<fluent:FontIcon Glyph="{StaticResource ChevronLeftGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="20"/>
</Button>
<TextBlock Grid.Column="3"
<TextBlock Name="PART_TitleText"
Grid.Column="3"
Margin="0,5"
Text="{TemplateBinding Title}"
FontWeight="Bold"
FontSize="24"
VerticalAlignment="Center"/>
<Button Grid.Column="5"
Margin="0,5"
IsVisible="{TemplateBinding IsMenuEnabled}"
Command="{TemplateBinding MenuCommand}"
Theme="{StaticResource TransparentButton}">
Command="{TemplateBinding MenuCommand}">
<fluent:FontIcon Glyph="{StaticResource MoreVerticalGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="20"/>
</Button>
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Margin" Value="0,9,0,5"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Theme" Value="{StaticResource TransparentButton}"/>
</Style>
</Grid.Styles>
</Grid>
</ControlTemplate>
</Setter>
Expand Down
20 changes: 19 additions & 1 deletion Aosta.Ava/Aosta.Ava/Controls/TitleBar.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright (c) Davide Pierotti <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using System.Windows.Input;

using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Media;

namespace Aosta.Ava.Controls;

Expand Down Expand Up @@ -55,5 +59,19 @@ public ICommand MenuCommand
get => GetValue(MenuCommandProperty);
set => SetValue(MenuCommandProperty, value);
}
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);

var textBlock = this.GetTemplateChildren()
.OfType<TextBlock>()
.First(static x => x.Name == "PART_TitleText");

Tapped += (_, _) =>
{
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
textBlock.TextWrapping ^= TextWrapping.WrapWithOverflow;
};
}
}

0 comments on commit 107fc67

Please sign in to comment.