Skip to content

Commit

Permalink
WinUI - TitleBar Subtitle Support
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Jun 13, 2024
1 parent c578e87 commit 222aa7f
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 23 deletions.
2 changes: 2 additions & 0 deletions org.nickvision.spotlight.winui/Controls/TitleBar.idl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ namespace Nickvision.Spotlight.WinUI.Controls
{
TitleBar();
static Microsoft.UI.Xaml.DependencyProperty TitleProperty{ get; };
static Microsoft.UI.Xaml.DependencyProperty SubtitleProperty{ get; };
static Microsoft.UI.Xaml.DependencyProperty TitleForegroundProperty{ get; };
static Microsoft.UI.Xaml.DependencyProperty SearchVisibilityProperty{ get; };
String Title;
String Subtitle;
Microsoft.UI.Xaml.Media.Brush TitleForeground;
Microsoft.UI.Xaml.Visibility SearchVisibility;
Microsoft.UI.Windowing.AppWindow AppWindow;
Expand Down
5 changes: 4 additions & 1 deletion org.nickvision.spotlight.winui/Controls/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
<ColumnDefinition x:Name="IconColumn" Width="Auto"/>
<ColumnDefinition x:Name="TitleColumn" Width="Auto"/>
<ColumnDefinition x:Name="SubtitleColumn" Width="Auto"/>
<ColumnDefinition x:Name="LeftDragColumn" Width="*"/>
<ColumnDefinition x:Name="SearchColumn" Width="4*"/>
<ColumnDefinition x:Name="RightDragColumn" Width="*" MinWidth="48"/>
Expand All @@ -22,6 +23,8 @@

<TextBlock x:Name="LblTitle" Grid.Column="2" VerticalAlignment="Center" Margin="4,0,0,0" Style="{ThemeResource CaptionTextBlockStyle}" Text="{x:Bind Title, Mode=OneWay}" Foreground="{x:Bind TitleForeground, Mode=OneWay}"/>

<AutoSuggestBox x:Name="AsbSearch" Grid.Column="4" QueryIcon="Find" VerticalAlignment="Center" MaxWidth="600" Visibility="{x:Bind SearchVisibility, Mode=OneWay}" TextChanged="OnSearchTextChanged"/>
<TextBlock x:Name="LblSubtitle" Grid.Column="3" VerticalAlignment="Center" Margin="12,0,0,0" Style="{ThemeResource CaptionTextBlockStyle}" Text="{x:Bind Subtitle, Mode=OneWay}" Foreground="Gray"/>

<AutoSuggestBox x:Name="AsbSearch" Grid.Column="5" QueryIcon="Find" VerticalAlignment="Center" MaxWidth="600" Visibility="{x:Bind SearchVisibility, Mode=OneWay}" TextChanged="OnSearchTextChanged"/>
</Grid>
</UserControl>
21 changes: 21 additions & 0 deletions org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace winrt::Windows::Graphics;
namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation
{
DependencyProperty TitleBar::m_titleProperty = DependencyProperty::Register(L"Title", winrt::xaml_typename<winrt::hstring>(), winrt::xaml_typename<Nickvision::Spotlight::WinUI::Controls::TitleBar>(), PropertyMetadata{ winrt::box_value(L""), PropertyChangedCallback{ &TitleBar::OnPropertyChanged } });
DependencyProperty TitleBar::m_subtitleProperty = DependencyProperty::Register(L"Subtitle", winrt::xaml_typename<winrt::hstring>(), winrt::xaml_typename<Nickvision::Spotlight::WinUI::Controls::TitleBar>(), PropertyMetadata{ winrt::box_value(L""), PropertyChangedCallback{ &TitleBar::OnPropertyChanged } });
DependencyProperty TitleBar::m_titleForegroundProperty = DependencyProperty::Register(L"TitleForeground", winrt::xaml_typename<Microsoft::UI::Xaml::Media::Brush>(), winrt::xaml_typename<Nickvision::Spotlight::WinUI::Controls::TitleBar>(), PropertyMetadata{ winrt::box_value(Microsoft::UI::Xaml::Media::Brush(nullptr)), PropertyChangedCallback{ &TitleBar::OnPropertyChanged } });
DependencyProperty TitleBar::m_searchVisibilityProperty = DependencyProperty::Register(L"SearchVisibility", winrt::xaml_typename<Microsoft::UI::Xaml::Visibility>(), winrt::xaml_typename<Nickvision::Spotlight::WinUI::Controls::TitleBar>(), PropertyMetadata{ winrt::box_value(Visibility::Collapsed), PropertyChangedCallback{ &TitleBar::OnPropertyChanged } });

Expand All @@ -42,6 +43,17 @@ namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation
}
}

winrt::hstring TitleBar::Subtitle() const
{
return winrt::unbox_value<winrt::hstring>(GetValue(m_subtitleProperty));
}

void TitleBar::Subtitle(const winrt::hstring& subtitle)
{
SetValue(m_subtitleProperty, winrt::box_value(subtitle));
m_propertyChangedEvent(*this, PropertyChangedEventArgs{ L"Subtitle" });
}

Microsoft::UI::Xaml::Media::Brush TitleBar::TitleForeground() const
{
return winrt::unbox_value<Microsoft::UI::Xaml::Media::Brush>(GetValue(m_titleForegroundProperty));
Expand Down Expand Up @@ -172,6 +184,11 @@ namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation
return m_titleProperty;
}

const DependencyProperty& TitleBar::SubtitleProperty()
{
return m_subtitleProperty;
}

const DependencyProperty& TitleBar::TitleForegroundProperty()
{
return m_titleForegroundProperty;
Expand All @@ -191,6 +208,10 @@ namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation
{
ptr->m_propertyChangedEvent(*ptr, PropertyChangedEventArgs{ L"Title" });
}
else if(args.Property() == m_subtitleProperty)
{
ptr->m_propertyChangedEvent(*ptr, PropertyChangedEventArgs{ L"Subtitle" });
}
else if(args.Property() == m_titleForegroundProperty)
{
ptr->m_propertyChangedEvent(*ptr, PropertyChangedEventArgs{ L"TitleForeground" });
Expand Down
16 changes: 16 additions & 0 deletions org.nickvision.spotlight.winui/Controls/TitleBar.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation
* @param title The new title
*/
void Title(const winrt::hstring& title);
/**
* @brief Gets the subtitle for the titlebar.
* @return The titlebar subtitle
*/
winrt::hstring Subtitle() const;
/**
* @brief Sets the subtitle for the titlebar.
* @param title The new subtitle
*/
void Subtitle(const winrt::hstring& subtitle);
/**
* @brief Gets the foreground brush for the titlebar.
* @return The titlebar foreground brush
Expand Down Expand Up @@ -117,6 +127,11 @@ namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation
* @return The title dependency property
*/
static const Microsoft::UI::Xaml::DependencyProperty& TitleProperty();
/**
* @brief Gets the titlebar's subtitle dependency property.
* @return The subtitle dependency property
*/
static const Microsoft::UI::Xaml::DependencyProperty& SubtitleProperty();
/**
* @brief Gets the titlebar's foreground dependency property.
* @return The foreground dependency property
Expand All @@ -136,6 +151,7 @@ namespace winrt::Nickvision::Spotlight::WinUI::Controls::implementation

private:
static Microsoft::UI::Xaml::DependencyProperty m_titleProperty;
static Microsoft::UI::Xaml::DependencyProperty m_subtitleProperty;
static Microsoft::UI::Xaml::DependencyProperty m_titleForegroundProperty;
static Microsoft::UI::Xaml::DependencyProperty m_searchVisibilityProperty;
};
Expand Down
2 changes: 1 addition & 1 deletion org.nickvision.spotlight.winui/MainWindow.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace winrt::Nickvision::Spotlight::WinUI::implementation
m_controller->imagesSynced() += [&](const EventArgs& args) { OnImagesSynced(args); };
//Localize Strings
TitleBar().Title(winrt::to_hstring(m_controller->getAppInfo().getShortName()));
NavView().PaneTitle(m_controller->isDevVersion() ? winrt::to_hstring(_("PREVIEW")) : L"");
TitleBar().Subtitle(m_controller->isDevVersion() ? winrt::to_hstring(_("Preview")) : L"");
LblAppName().Text(winrt::to_hstring(m_controller->getAppInfo().getShortName()));
LblAppDescription().Text(winrt::to_hstring(m_controller->getAppInfo().getDescription()));
LblAppVersion().Text(winrt::to_hstring(m_controller->getAppInfo().getVersion().str()));
Expand Down
6 changes: 3 additions & 3 deletions resources/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:06-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -76,7 +76,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -170,7 +170,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down
6 changes: 3 additions & 3 deletions resources/po/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:06-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: 2024-06-04 18:22+0000\n"
"Last-Translator: Nick Logozzo <nlogozzo225@gmail.com>\n"
"Language-Team: Italian <https://hosted.weblate.org/projects/nickvision-"
Expand Down Expand Up @@ -79,7 +79,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -173,7 +173,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down
6 changes: 3 additions & 3 deletions resources/po/pl.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:06-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -76,7 +76,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -170,7 +170,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down
6 changes: 3 additions & 3 deletions resources/po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:06-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -76,7 +76,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -170,7 +170,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down
6 changes: 3 additions & 3 deletions resources/po/spotlight.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:07-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -77,7 +77,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -171,7 +171,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down
6 changes: 3 additions & 3 deletions resources/po/ta.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:06-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -76,7 +76,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -170,7 +170,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down
6 changes: 3 additions & 3 deletions resources/po/uk.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-11 23:06-0400\n"
"POT-Creation-Date: 2024-06-13 17:51-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -76,7 +76,7 @@ msgstr ""
msgid "Unable to export images"
msgstr ""

#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:120
#: org.nickvision.spotlight.winui/Controls/TitleBar.xaml.cpp:132
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -170,7 +170,7 @@ msgid "Export All (Ctrl+Shift+S)"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:93
msgid "PREVIEW"
msgid "Preview"
msgstr ""

#: org.nickvision.spotlight.winui/MainWindow.xaml.cpp:192
Expand Down

0 comments on commit 222aa7f

Please sign in to comment.