mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
Color themes are loaded from .ini files in /res/themes/
The theme can be switched from the "Themes" section in the system menu.
The basic mechanism is that WindowServer broadcasts a SharedBuffer with
all of the color values of the current theme. Clients receive this with
the response to their initial WindowServer::Greet handshake.
When the theme is changed, WindowServer tells everyone by sending out
an UpdateSystemTheme message with a new SharedBuffer to use.
This does feel somewhat bloated somehow, but I'm sure we can iterate on
it over time and improve things.
To get one of the theme colors, use the Color(SystemColor) constructor:
painter.fill_rect(rect, SystemColor::HoverHighlight);
Some things don't work 100% right without a reboot. Specifically, when
constructing a GWidget, it will set its own background and foreground
colors based on the current SystemColor::Window and SystemColor::Text.
The widget is then stuck with these values, and they don't update on
system theme change, only on app restart.
All in all though, this is pretty cool. Merry Christmas! :^)
99 lines
2.9 KiB
C++
99 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/NonnullOwnPtrVector.h>
|
|
#include <AK/WeakPtr.h>
|
|
#include <LibCore/CObject.h>
|
|
#include <LibDraw/Rect.h>
|
|
#include <WindowServer/WSMenuItem.h>
|
|
|
|
class WSClientConnection;
|
|
class WSMenuBar;
|
|
class WSEvent;
|
|
class WSWindow;
|
|
class Font;
|
|
|
|
class WSMenu final : public CObject {
|
|
C_OBJECT(WSMenu)
|
|
public:
|
|
WSMenu(WSClientConnection*, int menu_id, const String& name);
|
|
virtual ~WSMenu() override;
|
|
|
|
WSClientConnection* client() { return m_client; }
|
|
const WSClientConnection* client() const { return m_client; }
|
|
int menu_id() const { return m_menu_id; }
|
|
|
|
WSMenuBar* menubar() { return m_menubar; }
|
|
const WSMenuBar* menubar() const { return m_menubar; }
|
|
void set_menubar(WSMenuBar* menubar) { m_menubar = menubar; }
|
|
|
|
bool is_empty() const { return m_items.is_empty(); }
|
|
int item_count() const { return m_items.size(); }
|
|
const WSMenuItem& item(int index) const { return m_items.at(index); }
|
|
|
|
void add_item(NonnullOwnPtr<WSMenuItem>&& item) { m_items.append(move(item)); }
|
|
|
|
String name() const { return m_name; }
|
|
|
|
template<typename Callback>
|
|
void for_each_item(Callback callback) const
|
|
{
|
|
for (auto& item : m_items)
|
|
callback(item);
|
|
}
|
|
|
|
Rect text_rect_in_menubar() const { return m_text_rect_in_menubar; }
|
|
void set_text_rect_in_menubar(const Rect& rect) { m_text_rect_in_menubar = rect; }
|
|
|
|
Rect rect_in_menubar() const { return m_rect_in_menubar; }
|
|
void set_rect_in_menubar(const Rect& rect) { m_rect_in_menubar = rect; }
|
|
|
|
WSWindow* menu_window() { return m_menu_window.ptr(); }
|
|
WSWindow& ensure_menu_window();
|
|
|
|
int width() const;
|
|
int height() const;
|
|
|
|
int item_height() const { return 20; }
|
|
int frame_thickness() const { return 3; }
|
|
int horizontal_padding() const { return left_padding() + right_padding(); }
|
|
int left_padding() const { return 14; }
|
|
int right_padding() const { return 14; }
|
|
|
|
void draw();
|
|
const Font& font() const;
|
|
|
|
WSMenuItem* item_with_identifier(unsigned);
|
|
WSMenuItem* item_at(const Point&);
|
|
void redraw();
|
|
|
|
const WSMenuItem* hovered_item() const { return m_hovered_item; }
|
|
void clear_hovered_item();
|
|
|
|
Function<void(WSMenuItem&)> on_item_activation;
|
|
|
|
void close();
|
|
|
|
void popup(const Point&, bool is_submenu = false);
|
|
|
|
bool is_menu_ancestor_of(const WSMenu&) const;
|
|
|
|
void redraw_if_theme_changed();
|
|
|
|
private:
|
|
virtual void event(CEvent&) override;
|
|
|
|
int padding_between_text_and_shortcut() const { return 50; }
|
|
void did_activate(WSMenuItem&);
|
|
WSClientConnection* m_client { nullptr };
|
|
int m_menu_id { 0 };
|
|
String m_name;
|
|
Rect m_rect_in_menubar;
|
|
Rect m_text_rect_in_menubar;
|
|
WSMenuBar* m_menubar { nullptr };
|
|
WSMenuItem* m_hovered_item { nullptr };
|
|
NonnullOwnPtrVector<WSMenuItem> m_items;
|
|
RefPtr<WSWindow> m_menu_window;
|
|
int m_theme_index_at_last_paint { -1 };
|
|
};
|