From a4e5d47690fb49e0122ce788cf83589042ca901c Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 28 Sep 2022 12:41:52 +0300 Subject: [PATCH] improve style naming --- src/Button.cpp | 6 +++++- src/Button.hpp | 11 +++++++++-- src/Label.cpp | 2 +- src/Styles.cpp | 19 +++++++++++++++---- src/Styles.hpp | 9 +++++---- src/Widget.hpp | 2 +- src/main.cpp | 16 ++++++++-------- 7 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/Button.cpp b/src/Button.cpp index 53f270c..8bff785 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -18,7 +18,11 @@ void Button::set_text(std::string text) { } void Button::on_init() { - set_style_pure(&default_button_style); + if (m_button_type == ButtonType::Flat) { + set_style_pure(&flat_button_style); + } else if (m_button_type == ButtonType::Accent) { + set_style_pure(&accent_button_style); + } set_did_init(true); if (!fit_text(m_text)) { diff --git a/src/Button.hpp b/src/Button.hpp index 47ebddf..f37bb62 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -11,9 +11,15 @@ namespace Raven { class Button : public Widget { public: - Button(std::string text) + enum class ButtonType { + Flat, + Accent + }; +public: + Button(std::string text, ButtonType button_type = ButtonType::Flat) : Widget(WidgetType::Button) - , m_text(text) {} + , m_text(text) + , m_button_type(button_type) {} void set_text(std::string text); std::string &text() { return m_text; } @@ -22,6 +28,7 @@ protected: void on_init(); private: std::string m_text; + ButtonType m_button_type; }; } diff --git a/src/Label.cpp b/src/Label.cpp index 11c40af..5f09d60 100644 --- a/src/Label.cpp +++ b/src/Label.cpp @@ -15,7 +15,7 @@ void Label::set_text(std::string text) { } void Label::on_init() { - set_style_pure(&default_label_style); + set_style_pure(&flat_label_style); set_did_init(true); if (!fit_text(m_text)) { diff --git a/src/Styles.cpp b/src/Styles.cpp index 07e4978..69ec3fb 100644 --- a/src/Styles.cpp +++ b/src/Styles.cpp @@ -25,7 +25,7 @@ RGB accent0 = RGB(0x7f465f); RGB accent1 = RGB(0x995473); RGB accent2 = RGB(0xb16286); -GenericStyle default_widget_style { +GenericStyle flat_widget_style { pango_font_description_from_string("sans-serif"), black6, white3, @@ -36,7 +36,7 @@ GenericStyle default_widget_style { false }; -GenericStyle accent_widget_style { +GenericStyle raised_widget_style { pango_font_description_from_string("sans-serif"), black6, white2, @@ -58,7 +58,18 @@ GenericStyle clear_widget_style { false }; -GenericStyle default_button_style { +GenericStyle flat_button_style { + pango_font_description_from_string("sans-serif"), + black6, + white3, + white2, + white1, + 5.0, + true, + true +}; + +GenericStyle raised_button_style { pango_font_description_from_string("sans-serif"), black6, white2, @@ -80,7 +91,7 @@ GenericStyle accent_button_style { true }; -GenericStyle default_label_style { +GenericStyle flat_label_style { pango_font_description_from_string("sans-serif"), black6, unused, diff --git a/src/Styles.hpp b/src/Styles.hpp index d9ef9a6..1b55765 100644 --- a/src/Styles.hpp +++ b/src/Styles.hpp @@ -24,11 +24,12 @@ extern RGB accent0; extern RGB accent1; extern RGB accent2; -extern GenericStyle default_widget_style; -extern GenericStyle accent_widget_style; +extern GenericStyle flat_widget_style; +extern GenericStyle raised_widget_style; extern GenericStyle clear_widget_style; -extern GenericStyle default_button_style; +extern GenericStyle flat_button_style; +extern GenericStyle raised_button_style; extern GenericStyle accent_button_style; -extern GenericStyle default_label_style; +extern GenericStyle flat_label_style; } diff --git a/src/Widget.hpp b/src/Widget.hpp index eb00c59..015fda6 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -141,7 +141,7 @@ private: std::vector> m_children; Widget *m_parent { nullptr }; Window *m_window { nullptr }; - GenericStyle *m_style { &default_widget_style }; + GenericStyle *m_style { &flat_widget_style }; std::shared_ptr m_layout { nullptr }; bool m_did_init { false }; bool m_is_focused { false }; diff --git a/src/main.cpp b/src/main.cpp index ecc3c46..8989721 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,23 +25,23 @@ int main() { main_layout->slot_pixel(30); // top bar auto top_bar = main_widget->add(); - top_bar->set_style(&Raven::accent_widget_style); + top_bar->set_style(&Raven::raised_widget_style); top_bar->set_layout(Raven::Direction::Horizontal); auto container_widget = main_widget->add(); - container_widget->set_layout(); + container_widget->set_style(&Raven::raised_widget_style); + auto container_widget_layout = container_widget->set_layout(Raven::Direction::Vertical); + container_widget_layout->set_margin(24.0); + container_widget_layout->set_spacing(8.0); - auto new_button = top_bar->add("add"); - new_button->rect().set_max_width(50); + auto new_button = top_bar->add("add", Raven::Button::ButtonType::Accent); new_button->on_click = [&window, container_widget]() { window.queue_microtask([container_widget]() { - for (int i = 0; i < 5000; i++) { - container_widget->add("hello"); - } + container_widget->add("hello"); }); }; - auto remove_button = top_bar->add("remove"); + auto remove_button = top_bar->add("remove", Raven::Button::ButtonType::Flat); remove_button->on_click = [container_widget]() { container_widget->clear_children(); };