mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibGfx: Add Paths to themes
Paths allows themes to specify directories/files where custom resources are located.
This commit is contained in:
parent
044b4cc090
commit
41aacdf815
Notes:
sideshowbarker
2024-07-19 04:26:16 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/41aacdf8158 Pull-request: https://github.com/SerenityOS/serenity/pull/2923
4 changed files with 45 additions and 0 deletions
|
@ -67,6 +67,12 @@ int PaletteImpl::metric(MetricRole role) const
|
|||
return theme().metric[(int)role];
|
||||
}
|
||||
|
||||
String PaletteImpl::path(PathRole role) const
|
||||
{
|
||||
ASSERT((int)role < (int)PathRole::__Count);
|
||||
return theme().path[(int)role];
|
||||
}
|
||||
|
||||
NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const
|
||||
{
|
||||
auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size());
|
||||
|
@ -90,6 +96,14 @@ void Palette::set_metric(MetricRole role, int value)
|
|||
theme.metric[(int)role] = value;
|
||||
}
|
||||
|
||||
void Palette::set_path(PathRole role, String path)
|
||||
{
|
||||
if (m_impl->ref_count() != 1)
|
||||
m_impl = m_impl->clone();
|
||||
auto& theme = const_cast<SystemTheme&>(impl().theme());
|
||||
theme.path[(int)role] = path;
|
||||
}
|
||||
|
||||
PaletteImpl::~PaletteImpl()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
|
||||
Color color(ColorRole) const;
|
||||
int metric(MetricRole) const;
|
||||
String path(PathRole) const;
|
||||
const SystemTheme& theme() const;
|
||||
|
||||
void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer);
|
||||
|
@ -124,11 +125,15 @@ public:
|
|||
int window_title_button_width() const { return metric(MetricRole::TitleButtonWidth); }
|
||||
int window_title_button_height() const { return metric(MetricRole::TitleButtonHeight); }
|
||||
|
||||
String title_button_icons_path() const { return path(PathRole::TitleButtonIcons); }
|
||||
|
||||
Color color(ColorRole role) const { return m_impl->color(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_metric(MetricRole, int);
|
||||
void set_path(PathRole, String);
|
||||
|
||||
const SystemTheme& theme() const { return m_impl->theme(); }
|
||||
|
||||
|
|
|
@ -85,6 +85,19 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
return metric;
|
||||
};
|
||||
|
||||
auto get_path = [&](auto& name, auto role) {
|
||||
auto path = file->read_entry("Paths", name);
|
||||
if (path.is_empty()) {
|
||||
switch (role) {
|
||||
case (int)PathRole::TitleButtonIcons:
|
||||
return "/res/icons/16x16/";
|
||||
default:
|
||||
return "/res/";
|
||||
}
|
||||
}
|
||||
return &path[0];
|
||||
};
|
||||
|
||||
#define DO_COLOR(x) \
|
||||
data->color[(int)ColorRole::x] = get_color(#x)
|
||||
|
||||
|
@ -153,6 +166,11 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
DO_METRIC(TitleButtonWidth);
|
||||
DO_METRIC(TitleButtonHeight);
|
||||
|
||||
#define DO_PATH(x) \
|
||||
data->path[(int)PathRole::x] = get_path(#x, (int)PathRole::x)
|
||||
|
||||
DO_PATH(TitleButtonIcons);
|
||||
|
||||
buffer->seal();
|
||||
buffer->share_globally();
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibGfx/Color.h>
|
||||
|
||||
|
@ -105,9 +106,16 @@ enum class MetricRole {
|
|||
__Count,
|
||||
};
|
||||
|
||||
enum class PathRole {
|
||||
NoRole,
|
||||
TitleButtonIcons,
|
||||
__Count,
|
||||
};
|
||||
|
||||
struct SystemTheme {
|
||||
Color color[(int)ColorRole::__Count];
|
||||
int metric[(int)MetricRole::__Count];
|
||||
String path[(int)PathRole::__Count];
|
||||
};
|
||||
|
||||
const SystemTheme& current_system_theme();
|
||||
|
|
Loading…
Add table
Reference in a new issue