you've seen WINRT_PROPERTY now get ready for RUNTIME_PROPERTY

and as soon ad I typed that out I realized that WINRT_PROPERTY already has
    setters and setting an optional override gets me nothing

    sure I could stealth the new value in underneath the runtime value, so
    reloading the settings doesn't reset font size, colors, etc

    I could

    but it sure does feel like overkill for "refactor but don't change anything"
This commit is contained in:
Mike Griese 2021-10-21 15:53:22 -05:00
parent 17829f438b
commit 1aa2849d94
3 changed files with 54 additions and 29 deletions

View file

@ -9,20 +9,45 @@ Licensed under the MIT license.
#include <DefaultSettings.h>
#include <conattrs.hpp>
#define RUNTIME_PROPERTY(type, name, setting, ...) \
private: \
type _##name{ __VA_ARGS__ }; \
std::optional<type> _runtime##name{ std::nullopt }; \
\
public: \
void name(const type newValue) { _runtime##name = newValue; } \
\
type name() const { return _runtime##name ? *_runtime##name : _##name; }
namespace winrt::Microsoft::Terminal::Control::implementation
{
struct ControlAppearance : public winrt::implements<ControlAppearance, Microsoft::Terminal::Core::ICoreAppearance, Microsoft::Terminal::Control::IControlAppearance>
{
#define SETTINGS_GEN(type, name, ...) WINRT_PROPERTY(type, name, __VA_ARGS__);
#define SETTINGS_GEN(type, name, ...) RUNTIME_PROPERTY(type, name, __VA_ARGS__);
CORE_APPEARANCE_SETTINGS(SETTINGS_GEN)
CONTROL_APPEARANCE_SETTINGS(SETTINGS_GEN)
#undef SETTINGS_GEN
private:
// Color Table is special because it's an array
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> _ColorTable;
// Color table is _extra_ special because each individual color is
// overridable, not the whole array.
std::array<std::optional<winrt::Microsoft::Terminal::Core::Color>, COLOR_TABLE_SIZE> _runtimeColorTable;
public:
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept { return _ColorTable.at(index); }
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept
{
return _runtimeColorTable.at(index) ? *_runtimeColorTable.at(index) :
_ColorTable.at(index);
}
void SetColorTableEntry(int32_t index,
winrt::Microsoft::Terminal::Core::Color color) noexcept
{
_runtimeColorTable.at(index) = color;
}
std::array<winrt::Microsoft::Terminal::Core::Color, 16> ColorTable() { return _ColorTable; }
void ColorTable(std::array<winrt::Microsoft::Terminal::Core::Color, 16> /*colors*/) {}

View file

@ -1610,10 +1610,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
_terminal->ApplyScheme(scheme);
// _settings->FocusedAppearance()->DefaultForeground(colorScheme.Foreground);
// _settings->FocusedAppearance()->DefaultBackground(colorScheme.Background);
// _settings->FocusedAppearance()->CursorColor(colorScheme.CursorColor);
// _settings->FocusedAppearance()->SelectionBackground(colorScheme.SelectionBackground);
_settings->FocusedAppearance()->DefaultForeground(scheme.Foreground);
_settings->FocusedAppearance()->DefaultBackground(scheme.Background);
_settings->FocusedAppearance()->CursorColor(scheme.CursorColor);
_settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground);
// // _defaultFg = colorScheme.Foreground;
// // // Set the default background as transparent to prevent the
@ -1621,22 +1621,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// // til::color newBackgroundColor{ colorScheme.Background };
// // _defaultBg = newBackgroundColor.with_alpha(0);
// _settings->FocusedAppearance()->Table()[0] = scheme.Black;
// _settings->FocusedAppearance()->Table()[1] = scheme.Red;
// _settings->FocusedAppearance()->Table()[2] = scheme.Green;
// _settings->FocusedAppearance()->Table()[3] = scheme.Yellow;
// _settings->FocusedAppearance()->Table()[4] = scheme.Blue;
// _settings->FocusedAppearance()->Table()[5] = scheme.Purple;
// _settings->FocusedAppearance()->Table()[6] = scheme.Cyan;
// _settings->FocusedAppearance()->Table()[7] = scheme.White;
// _settings->FocusedAppearance()->Table()[8] = scheme.BrightBlack;
// _settings->FocusedAppearance()->Table()[9] = scheme.BrightRed;
// _settings->FocusedAppearance()->Table()[10] = scheme.BrightGreen;
// _settings->FocusedAppearance()->Table()[11] = scheme.BrightYellow;
// _settings->FocusedAppearance()->Table()[12] = scheme.BrightBlue;
// _settings->FocusedAppearance()->Table()[13] = scheme.BrightPurple;
// _settings->FocusedAppearance()->Table()[14] = scheme.BrightCyan;
// _settings->FocusedAppearance()->Table()[15] = scheme.BrightWhite;
_settings->FocusedAppearance()->SetColorTableEntry(0, scheme.Black);
_settings->FocusedAppearance()->SetColorTableEntry(1, scheme.Red);
_settings->FocusedAppearance()->SetColorTableEntry(2, scheme.Green);
_settings->FocusedAppearance()->SetColorTableEntry(3, scheme.Yellow);
_settings->FocusedAppearance()->SetColorTableEntry(4, scheme.Blue);
_settings->FocusedAppearance()->SetColorTableEntry(5, scheme.Purple);
_settings->FocusedAppearance()->SetColorTableEntry(6, scheme.Cyan);
_settings->FocusedAppearance()->SetColorTableEntry(7, scheme.White);
_settings->FocusedAppearance()->SetColorTableEntry(8, scheme.BrightBlack);
_settings->FocusedAppearance()->SetColorTableEntry(9, scheme.BrightRed);
_settings->FocusedAppearance()->SetColorTableEntry(10, scheme.BrightGreen);
_settings->FocusedAppearance()->SetColorTableEntry(11, scheme.BrightYellow);
_settings->FocusedAppearance()->SetColorTableEntry(12, scheme.BrightBlue);
_settings->FocusedAppearance()->SetColorTableEntry(13, scheme.BrightPurple);
_settings->FocusedAppearance()->SetColorTableEntry(14, scheme.BrightCyan);
_settings->FocusedAppearance()->SetColorTableEntry(15, scheme.BrightWhite);
// _buffer->GetCursor().SetColor(til::color{ colorScheme.CursorColor });

View file

@ -1501,13 +1501,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_blinkTimer->Start();
}
// // Only update the appearance here if an unfocused config exists -
// // if an unfocused config does not exist then we never would have switched
// // appearances anyway so there's no need to switch back upon gaining focus
// if (_core.UnfocusedAppearance())
// {
// UpdateAppearance(_core.FocusedAppearance());
// }
// Only update the appearance here if an unfocused config exists -
// if an unfocused config does not exist then we never would have switched
// appearances anyway so there's no need to switch back upon gaining focus
if (_core.UnfocusedAppearance())
{
UpdateAppearance(_core.FocusedAppearance());
}
}
// Method Description: