mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
LibGfx: Add 'IsDark' flag to SystemTheme and Palette
This explicitly states whether a given theme is a dark theme, so that applications not using the system palette colors can still attempt to match the overall theme.
This commit is contained in:
parent
2eaed880b1
commit
4f42e4ba90
4 changed files with 48 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -56,6 +57,14 @@ void Palette::set_color(ColorRole role, Color color)
|
|||
theme.color[(int)role] = color.value();
|
||||
}
|
||||
|
||||
void Palette::set_flag(FlagRole role, bool value)
|
||||
{
|
||||
if (m_impl->ref_count() != 1)
|
||||
m_impl = m_impl->clone();
|
||||
auto& theme = const_cast<SystemTheme&>(impl().theme());
|
||||
theme.flag[(int)role] = value;
|
||||
}
|
||||
|
||||
void Palette::set_metric(MetricRole role, int value)
|
||||
{
|
||||
if (m_impl->ref_count() != 1)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -30,6 +31,12 @@ public:
|
|||
return Color::from_rgba(theme().color[(int)role]);
|
||||
}
|
||||
|
||||
bool flag(FlagRole role) const
|
||||
{
|
||||
VERIFY((int)role < (int)FlagRole::__Count);
|
||||
return theme().flag[(int)role];
|
||||
}
|
||||
|
||||
int metric(MetricRole) const;
|
||||
String path(PathRole) const;
|
||||
const SystemTheme& theme() const { return *m_theme_buffer.data<SystemTheme>(); }
|
||||
|
@ -118,6 +125,8 @@ public:
|
|||
Color syntax_preprocessor_statement() const { return color(ColorRole::SyntaxPreprocessorStatement); }
|
||||
Color syntax_preprocessor_value() const { return color(ColorRole::SyntaxPreprocessorValue); }
|
||||
|
||||
bool is_dark() const { return flag(FlagRole::IsDark); }
|
||||
|
||||
int window_title_height() const { return metric(MetricRole::TitleHeight); }
|
||||
int window_title_button_width() const { return metric(MetricRole::TitleButtonWidth); }
|
||||
int window_title_button_height() const { return metric(MetricRole::TitleButtonHeight); }
|
||||
|
@ -130,10 +139,12 @@ public:
|
|||
String tooltip_shadow_path() const { return path(PathRole::TooltipShadow); }
|
||||
|
||||
Color color(ColorRole role) const { return m_impl->color(role); }
|
||||
bool flag(FlagRole role) const { return m_impl->flag(role); }
|
||||
int metric(MetricRole role) const { return m_impl->metric(role); }
|
||||
String path(PathRole role) const { return m_impl->path(role); }
|
||||
|
||||
void set_color(ColorRole, Color);
|
||||
void set_flag(FlagRole, bool);
|
||||
void set_metric(MetricRole, int);
|
||||
void set_path(PathRole, String);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -40,6 +41,11 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
|||
return color.value();
|
||||
};
|
||||
|
||||
auto get_flag = [&](auto& name) {
|
||||
auto flag_string = file.read_entry("Flags", name);
|
||||
return flag_string.equals_ignoring_case("true");
|
||||
};
|
||||
|
||||
auto get_metric = [&](auto& name, auto role) {
|
||||
int metric = file.read_num_entry("Metrics", name, -1);
|
||||
if (metric == -1) {
|
||||
|
@ -77,6 +83,12 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
|||
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
|
||||
#undef __ENUMERATE_COLOR_ROLE
|
||||
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
#define __ENUMERATE_FLAG_ROLE(role) \
|
||||
data->flag[(int)FlagRole::role] = get_flag(#role);
|
||||
ENUMERATE_FLAG_ROLES(__ENUMERATE_FLAG_ROLE)
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
|
||||
#undef __ENUMERATE_METRIC_ROLE
|
||||
#define __ENUMERATE_METRIC_ROLE(role) \
|
||||
data->metric[(int)MetricRole::role] = get_metric(#role, (int)MetricRole::role);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -89,6 +90,9 @@ namespace Gfx {
|
|||
C(Window) \
|
||||
C(WindowText)
|
||||
|
||||
#define ENUMERATE_FLAG_ROLES(C) \
|
||||
C(IsDark)
|
||||
|
||||
#define ENUMERATE_METRIC_ROLES(C) \
|
||||
C(TitleHeight) \
|
||||
C(TitleButtonWidth) \
|
||||
|
@ -132,6 +136,17 @@ inline const char* to_string(ColorRole role)
|
|||
}
|
||||
}
|
||||
|
||||
enum class FlagRole {
|
||||
NoRole,
|
||||
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
#define __ENUMERATE_FLAG_ROLE(role) role,
|
||||
ENUMERATE_FLAG_ROLES(__ENUMERATE_FLAG_ROLE)
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
|
||||
__Count,
|
||||
};
|
||||
|
||||
enum class MetricRole {
|
||||
NoRole,
|
||||
|
||||
|
@ -188,6 +203,7 @@ inline const char* to_string(PathRole role)
|
|||
|
||||
struct SystemTheme {
|
||||
RGBA32 color[(int)ColorRole::__Count];
|
||||
bool flag[(int)FlagRole::__Count];
|
||||
int metric[(int)MetricRole::__Count];
|
||||
char path[(int)PathRole::__Count][256]; // TODO: PATH_MAX?
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue