background brush, done

This commit is contained in:
Mike Griese
2023-08-07 15:17:09 -05:00
parent 521e301541
commit 9531069538
9 changed files with 54 additions and 16 deletions

View File

@@ -21,6 +21,8 @@ namespace TerminalApp
UInt64 TaskbarProgress { get; };
Boolean ReadOnly { get; };
String Icon { get; };
Windows.Foundation.IReference<Windows.UI.Color> TabColor { get; };
Windows.UI.Xaml.Media.Brush BackgroundBrush { get; };
Microsoft.Terminal.Settings.Model.NewTerminalArgs GetNewTerminalArgs(Boolean asContent);

View File

@@ -61,4 +61,9 @@ namespace winrt::TerminalApp::implementation
static constexpr std::wstring_view glyph{ L"\xe70b" }; // QuickNote
return winrt::hstring{ glyph };
}
winrt::Windows::UI::Xaml::Media::Brush ScratchpadContent::BackgroundBrush()
{
return _root.Background();
}
}

View File

@@ -24,6 +24,8 @@ namespace winrt::TerminalApp::implementation
uint64_t TaskbarProgress() { return 0; }
bool ReadOnly() { return false; }
winrt::hstring Icon() const;
Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() const noexcept { return nullptr; }
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush();
til::typed_event<> CloseRequested;
til::typed_event<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::BellEventArgs> BellRequested;

View File

@@ -5,6 +5,7 @@
#include "SettingsPaneContent.h"
#include "PaneArgs.h"
#include "SettingsPaneContent.g.cpp"
#include "Utils.h"
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Xaml;
@@ -17,6 +18,10 @@ namespace winrt::TerminalApp::implementation
SettingsPaneContent::SettingsPaneContent(CascadiaSettings settings)
{
_sui = winrt::Microsoft::Terminal::Settings::Editor::MainPage{ settings };
// Stash away the current requested theme of the app. We'll need that in
// _BackgroundBrush() to do a theme-aware resource lookup
_requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme();
}
void SettingsPaneContent::UpdateSettings(const CascadiaSettings& settings)
@@ -24,9 +29,7 @@ namespace winrt::TerminalApp::implementation
ASSERT_UI_THREAD();
_sui.UpdateSettings(settings);
// Stash away the current requested theme of the app. We'll need that in
// _BackgroundBrush() to do a theme-aware resource lookup
// _requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme();
_requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme();
}
winrt::Windows::UI::Xaml::FrameworkElement SettingsPaneContent::GetRoot()
@@ -61,4 +64,21 @@ namespace winrt::TerminalApp::implementation
static constexpr std::wstring_view glyph{ L"\xE713" };
return winrt::hstring{ glyph };
}
Windows::Foundation::IReference<winrt::Windows::UI::Color> SettingsPaneContent::TabColor() const noexcept
{
return nullptr;
}
winrt::Windows::UI::Xaml::Media::Brush SettingsPaneContent::BackgroundBrush()
{
// Look up the color we should use for the settings tab item from our
// resources. This should only be used for when "terminalBackground" is
// requested.
static const auto key = winrt::box_value(L"SettingsUiTabBrush");
// You can't just do a Application::Current().Resources().TryLookup
// lookup, cause the app theme never changes! Do the hacky version
// instead.
return ThemeLookup(Application::Current().Resources(), _requestedTheme, key).try_as<winrt::Windows::UI::Xaml::Media::Brush>();
}
}

View File

@@ -26,6 +26,8 @@ namespace winrt::TerminalApp::implementation
uint64_t TaskbarProgress() { return 0; }
bool ReadOnly() { return false; }
winrt::hstring Icon() const;
Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() const noexcept;
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush();
til::typed_event<> CloseRequested;
til::typed_event<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::BellEventArgs> BellRequested;
@@ -37,6 +39,7 @@ namespace winrt::TerminalApp::implementation
private:
winrt::Microsoft::Terminal::Settings::Editor::MainPage _sui{ nullptr };
winrt::Windows::UI::Xaml::ElementTheme _requestedTheme;
};
}

View File

@@ -38,7 +38,6 @@ namespace winrt::TerminalApp::implementation
void SettingsTab::UpdateSettings(CascadiaSettings settings)
{
// TODO! oh noes, we need to do this too in the content
ASSERT_UI_THREAD();
auto settingsUI{ Content().as<MainPage>() };
@@ -110,8 +109,6 @@ namespace winrt::TerminalApp::implementation
// - <none>
void SettingsTab::_CreateIcon()
{
// TODO! make sure this works
// This is the Setting icon (looks like a gear)
static constexpr std::wstring_view glyph{ L"\xE713" };
@@ -122,9 +119,6 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::UI::Xaml::Media::Brush SettingsTab::_BackgroundBrush()
{
// TODO! make sure this still works. It would be ironic if this _just
// worked_ because the SUI was the same color as a tab with no styling.
// Look up the color we should use for the settings tab item from our
// resources. This should only be used for when "terminalBackground" is
// requested.

View File

@@ -81,6 +81,11 @@ namespace winrt::TerminalApp::implementation
return _profile.Icon();
}
Windows::Foundation::IReference<winrt::Windows::UI::Color> TerminalPaneContent::TabColor() const noexcept
{
return _control.TabColor();
}
NewTerminalArgs TerminalPaneContent::GetNewTerminalArgs(const bool asContent) const
{
NewTerminalArgs args{};
@@ -311,6 +316,11 @@ namespace winrt::TerminalApp::implementation
_isDefTermSession = true;
}
winrt::Windows::UI::Xaml::Media::Brush TerminalPaneContent::BackgroundBrush()
{
return _control.BackgroundBrush();
}
float TerminalPaneContent::SnapDownToGrid(const TerminalApp::PaneSnapDirection direction, const float sizeToSnap)
{
return _control.SnapDimensionToGrid(direction == PaneSnapDirection::Width, sizeToSnap);

View File

@@ -37,6 +37,8 @@ namespace winrt::TerminalApp::implementation
uint64_t TaskbarProgress() { return _control.TaskbarProgress(); }
bool ReadOnly() { return _control.ReadOnly(); }
winrt::hstring Icon() const;
Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() const noexcept;
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush();
float SnapDownToGrid(const TerminalApp::PaneSnapDirection direction, const float sizeToSnap);
Windows::Foundation::Size GridSize();

View File

@@ -1470,12 +1470,12 @@ namespace winrt::TerminalApp::implementation
{
ASSERT_UI_THREAD();
std::optional<winrt::Windows::UI::Color> controlTabColor;
if (const auto& control = GetActiveTerminalControl())
std::optional<winrt::Windows::UI::Color> contentTabColor;
if (const auto& content{ GetActiveContent() })
{
if (const auto color = control.TabColor())
if (const auto color = content.TabColor())
{
controlTabColor = color.Value();
contentTabColor = color.Value();
}
}
@@ -1485,7 +1485,7 @@ namespace winrt::TerminalApp::implementation
// Color | | Set by
// -------------------- | -- | --
// Runtime Color | _optional_ | Color Picker / `setTabColor` action
// Control Tab Color | _optional_ | Profile's `tabColor`, or a color set by VT
// Content Tab Color | _optional_ | Profile's `tabColor`, or a color set by VT (whatever the tab's content wants)
// Theme Tab Background | _optional_ | `tab.backgroundColor` in the theme (handled in _RecalculateAndApplyTabColor)
// Tab Default Color | **default** | TabView in XAML
//
@@ -1494,7 +1494,7 @@ namespace winrt::TerminalApp::implementation
// tabview color" (and clear out any colors we've set).
return til::coalesce(_runtimeTabColor,
controlTabColor,
contentTabColor,
std::optional<Windows::UI::Color>(std::nullopt));
}
@@ -1533,7 +1533,7 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::UI::Xaml::Media::Brush TerminalTab::_BackgroundBrush()
{
Media::Brush terminalBrush{ nullptr };
if (const auto& c{ GetActiveTerminalControl() })
if (const auto& c{ GetActiveContent() })
{
terminalBrush = c.BackgroundBrush();
}