mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 22:17:43 +00:00
LibGfx: Add SystemTheme::load_system_theme(Core::ConfigFile const&)
This makes loading system themes possible via FileSystemAccessClient (needed for the Theme Editor). :^)
This commit is contained in:
parent
09314ad611
commit
f878e4464f
2 changed files with 12 additions and 6 deletions
|
@ -26,15 +26,14 @@ void set_system_theme(Core::AnonymousBuffer buffer)
|
||||||
theme_page = theme_buffer.data<SystemTheme>();
|
theme_page = theme_buffer.data<SystemTheme>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::AnonymousBuffer load_system_theme(const String& path)
|
Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
||||||
{
|
{
|
||||||
auto file = Core::ConfigFile::open(path);
|
|
||||||
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme));
|
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme));
|
||||||
|
|
||||||
auto* data = buffer.data<SystemTheme>();
|
auto* data = buffer.data<SystemTheme>();
|
||||||
|
|
||||||
auto get_color = [&](auto& name) {
|
auto get_color = [&](auto& name) {
|
||||||
auto color_string = file->read_entry("Colors", name);
|
auto color_string = file.read_entry("Colors", name);
|
||||||
auto color = Color::from_string(color_string);
|
auto color = Color::from_string(color_string);
|
||||||
if (!color.has_value())
|
if (!color.has_value())
|
||||||
return Color(Color::Black);
|
return Color(Color::Black);
|
||||||
|
@ -42,7 +41,7 @@ Core::AnonymousBuffer load_system_theme(const String& path)
|
||||||
};
|
};
|
||||||
|
|
||||||
auto get_metric = [&](auto& name, auto role) {
|
auto get_metric = [&](auto& name, auto role) {
|
||||||
int metric = file->read_num_entry("Metrics", name, -1);
|
int metric = file.read_num_entry("Metrics", name, -1);
|
||||||
if (metric == -1) {
|
if (metric == -1) {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case (int)MetricRole::TitleHeight:
|
case (int)MetricRole::TitleHeight:
|
||||||
|
@ -60,7 +59,7 @@ Core::AnonymousBuffer load_system_theme(const String& path)
|
||||||
};
|
};
|
||||||
|
|
||||||
auto get_path = [&](auto& name, auto role, bool allow_empty) {
|
auto get_path = [&](auto& name, auto role, bool allow_empty) {
|
||||||
auto path = file->read_entry("Paths", name);
|
auto path = file.read_entry("Paths", name);
|
||||||
if (path.is_empty()) {
|
if (path.is_empty()) {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case (int)PathRole::TitleButtonIcons:
|
case (int)PathRole::TitleButtonIcons:
|
||||||
|
@ -102,4 +101,9 @@ Core::AnonymousBuffer load_system_theme(const String& path)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Core::AnonymousBuffer load_system_theme(String const& path)
|
||||||
|
{
|
||||||
|
return load_system_theme(Core::ConfigFile::open(path));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <LibCore/AnonymousBuffer.h>
|
#include <LibCore/AnonymousBuffer.h>
|
||||||
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibGfx/Color.h>
|
#include <LibGfx/Color.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
@ -145,7 +146,8 @@ struct SystemTheme {
|
||||||
|
|
||||||
Core::AnonymousBuffer& current_system_theme_buffer();
|
Core::AnonymousBuffer& current_system_theme_buffer();
|
||||||
void set_system_theme(Core::AnonymousBuffer);
|
void set_system_theme(Core::AnonymousBuffer);
|
||||||
Core::AnonymousBuffer load_system_theme(const String& path);
|
Core::AnonymousBuffer load_system_theme(Core::ConfigFile const&);
|
||||||
|
Core::AnonymousBuffer load_system_theme(String const& path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue