mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
Theming: Add alignment section
This commit removes the IsTitleCenter property and replaces it with the TitleAlignment property that supports "Left", "Right" & "Center".
This commit is contained in:
parent
2bb32a87f9
commit
35dac843b4
21 changed files with 181 additions and 32 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -45,6 +46,29 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
|||
return file.read_bool_entry("Flags", name, false);
|
||||
};
|
||||
|
||||
auto get_alignment = [&](auto& name, auto role) {
|
||||
auto alignment = file.read_entry("Alignments", name).to_lowercase();
|
||||
if (alignment.is_empty()) {
|
||||
switch (role) {
|
||||
case (int)AlignmentRole::TitleAlignment:
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
default:
|
||||
dbgln("Alignment {} has no fallback value!", name);
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
}
|
||||
}
|
||||
|
||||
if (alignment == "left" || alignment == "centerleft")
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
else if (alignment == "right" || alignment == "centerright")
|
||||
return Gfx::TextAlignment::CenterRight;
|
||||
else if (alignment == "center")
|
||||
return Gfx::TextAlignment::Center;
|
||||
|
||||
dbgln("Alignment {} has an invalid value!", name);
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
};
|
||||
|
||||
auto get_metric = [&](auto& name, auto role) {
|
||||
int metric = file.read_num_entry("Metrics", name, -1);
|
||||
if (metric == -1) {
|
||||
|
@ -86,6 +110,12 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
|||
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
|
||||
#undef __ENUMERATE_COLOR_ROLE
|
||||
|
||||
#undef __ENUMERATE_ALIGNMENT_ROLE
|
||||
#define __ENUMERATE_ALIGNMENT_ROLE(role) \
|
||||
data->alignment[(int)AlignmentRole::role] = get_alignment(#role, (int)AlignmentRole::role);
|
||||
ENUMERATE_ALIGNMENT_ROLES(__ENUMERATE_ALIGNMENT_ROLE)
|
||||
#undef __ENUMERATE_ALIGNMENT_ROLE
|
||||
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
#define __ENUMERATE_FLAG_ROLE(role) \
|
||||
data->flag[(int)FlagRole::role] = get_flag(#role);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue