From 26858b795d30f9ab5d66270b7b952aa4e2b143cb Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Fri, 18 Mar 2022 03:04:34 +0200 Subject: [PATCH] remove annoying style_ prefix from DEF_STYLE and rename it to DEF_PROP --- src/Button.cpp | 22 +++++++++++----------- src/Button.hpp | 10 +++++----- src/PropMacros.hpp | 9 +++++++++ src/StyleMacros.hpp | 9 --------- src/TopLevelStyles.hpp | 24 ++++++++++++------------ src/Widget.cpp | 6 +++--- src/Widget.hpp | 8 ++++---- src/main.cpp | 4 ++-- 8 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 src/PropMacros.hpp delete mode 100644 src/StyleMacros.hpp diff --git a/src/Button.cpp b/src/Button.cpp index 4b106df..7d322c8 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -10,14 +10,14 @@ namespace Raven { void Button::on_init() { auto top_level_styles = get_top_level_styles(); - set_style_text_fill_color(top_level_styles->get_style_text_color()); - set_style_active_background_fill_color(top_level_styles->get_style_button_active_color()); - set_style_focused_background_fill_color(top_level_styles->get_style_button_focused_color()); - set_style_normal_background_fill_color(top_level_styles->get_style_button_normal_color()); + set_text_fill_color(top_level_styles->get_text_color()); + set_active_background_fill_color(top_level_styles->get_button_active_color()); + set_focused_background_fill_color(top_level_styles->get_button_focused_color()); + set_normal_background_fill_color(top_level_styles->get_button_normal_color()); - set_style_do_background_fill(true); - set_style_background_fill_color(m_style_normal_background_fill_color); - set_style_font_description(top_level_styles->get_style_controls_font_description()); + set_do_background_fill(true); + set_background_fill_color(m_normal_background_fill_color); + set_font_description(top_level_styles->get_controls_font_description()); set_did_init(true); } @@ -25,17 +25,17 @@ void Button::on_init() { void Button::on_paint() { auto painter = get_window()->get_painter(); - painter.source_rgb(m_style_text_fill_color); - painter.set_pango_font_description(m_style_font_description); + painter.source_rgb(m_text_fill_color); + painter.set_pango_font_description(m_font_description); painter.text(get_current_geometry(), m_text, PaintTextAlign::Center); painter.fill(); } void Button::on_focus_update(FocusUpdateEvent &event) { if (is_focused()) { - set_style_background_fill_color(m_style_focused_background_fill_color); + set_background_fill_color(m_focused_background_fill_color); } else { - set_style_background_fill_color(m_style_normal_background_fill_color); + set_background_fill_color(m_normal_background_fill_color); } } diff --git a/src/Button.hpp b/src/Button.hpp index 4c29b7d..194c3eb 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -9,13 +9,13 @@ namespace Raven { class Button : public Widget { -DEF_STYLE(text_fill_color, RGB, 0.0, 0.0, 0.0) +DEF_PROP(text_fill_color, RGB, 0.0, 0.0, 0.0) -DEF_STYLE(normal_background_fill_color, RGB, 0.0, 0.0, 0.0) -DEF_STYLE(focused_background_fill_color, RGB, 0.0, 0.0, 0.0) -DEF_STYLE(active_background_fill_color, RGB, 0.0, 0.0, 0.0) +DEF_PROP(normal_background_fill_color, RGB, 0.0, 0.0, 0.0) +DEF_PROP(focused_background_fill_color, RGB, 0.0, 0.0, 0.0) +DEF_PROP(active_background_fill_color, RGB, 0.0, 0.0, 0.0) -DEF_STYLE(font_description, PangoFontDescription*, nullptr) +DEF_PROP(font_description, PangoFontDescription*, nullptr) private: std::string m_text; diff --git a/src/PropMacros.hpp b/src/PropMacros.hpp new file mode 100644 index 0000000..de2ff3d --- /dev/null +++ b/src/PropMacros.hpp @@ -0,0 +1,9 @@ +#pragma once + +#define DEF_PROP(name, type, ...) \ + private: \ + type m_##name {__VA_ARGS__}; \ + public: \ + void set_##name(type new_prop_value) { m_##name = new_prop_value; wants_repaint(); } \ + type get_##name() { return m_##name; } \ + private: diff --git a/src/StyleMacros.hpp b/src/StyleMacros.hpp deleted file mode 100644 index fcacc7f..0000000 --- a/src/StyleMacros.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#define DEF_STYLE(name, type, ...) \ - private: \ - type m_style_##name {__VA_ARGS__}; \ - public: \ - void set_style_##name(type new_style_value) { m_style_##name = new_style_value; wants_repaint(); } \ - type get_style_##name() { return m_style_##name; } \ - private: diff --git a/src/TopLevelStyles.hpp b/src/TopLevelStyles.hpp index db80098..23e45de 100644 --- a/src/TopLevelStyles.hpp +++ b/src/TopLevelStyles.hpp @@ -3,22 +3,22 @@ #include #include "Forward.hpp" #include "pango/pango-font.h" -#include "StyleMacros.hpp" +#include "PropMacros.hpp" #include "RGB.hpp" namespace Raven { class TopLevelStyles { -DEF_STYLE(controls_font_description, PangoFontDescription*, nullptr) +DEF_PROP(controls_font_description, PangoFontDescription*, nullptr) -DEF_STYLE(text_color, RGB, 0.0, 0.0, 0.0) -DEF_STYLE(accent_color, RGB, 0.6941, 0.3843, 0.5254) -DEF_STYLE(accent_color_darker, RGB, 0.5607, 0.2470, 0.4431) -DEF_STYLE(background_color, RGB, 0.9764, 0.9607, 0.8431) +DEF_PROP(text_color, RGB, 0.0, 0.0, 0.0) +DEF_PROP(accent_color, RGB, 0.6941, 0.3843, 0.5254) +DEF_PROP(accent_color_darker, RGB, 0.5607, 0.2470, 0.4431) +DEF_PROP(background_color, RGB, 0.9764, 0.9607, 0.8431) -DEF_STYLE(button_normal_color, RGB, m_style_accent_color) -DEF_STYLE(button_focused_color, RGB, m_style_accent_color_darker) -DEF_STYLE(button_active_color, RGB, m_style_accent_color_darker) +DEF_PROP(button_normal_color, RGB, m_accent_color) +DEF_PROP(button_focused_color, RGB, m_accent_color_darker) +DEF_PROP(button_active_color, RGB, m_accent_color_darker) private: Window *m_window; @@ -32,12 +32,12 @@ public: pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_absolute_size(font_description, 16 * PANGO_SCALE); - m_style_controls_font_description = font_description; + m_controls_font_description = font_description; } ~TopLevelStyles() { - if (m_style_controls_font_description) { - pango_font_description_free(m_style_controls_font_description); + if (m_controls_font_description) { + pango_font_description_free(m_controls_font_description); } } diff --git a/src/Widget.cpp b/src/Widget.cpp index 92e55b6..2f561f9 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -37,14 +37,14 @@ void Widget::remove_child(Widget *child) { } void Widget::do_generic_paint() { - if (m_style_do_background_fill) { + if (m_do_background_fill) { auto painter = m_window->get_painter(); auto cr = painter.get_cairo(); cr->save(); - painter.source_rgb(m_style_background_fill_color); - painter.rounded_rectangle(m_current_geometry, m_style_background_border_radius); + painter.source_rgb(m_background_fill_color); + painter.rounded_rectangle(m_current_geometry, m_background_border_radius); painter.fill(); cr->restore(); diff --git a/src/Widget.hpp b/src/Widget.hpp index dc86b2d..d0cd98d 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -8,15 +8,15 @@ #include "Forward.hpp" #include "RGB.hpp" #include "TopLevelStyles.hpp" -#include "StyleMacros.hpp" +#include "PropMacros.hpp" namespace Raven { class Widget { -DEF_STYLE(do_background_fill, bool, false) -DEF_STYLE(background_fill_color, RGB, 0, 0, 0) -DEF_STYLE(background_border_radius, double, 0.0) +DEF_PROP(do_background_fill, bool, false) +DEF_PROP(background_fill_color, RGB, 0, 0, 0) +DEF_PROP(background_border_radius, double, 0.0) private: diff --git a/src/main.cpp b/src/main.cpp index 9e143bd..f676ae5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,8 +13,8 @@ int main() { button.set_current_geometry(Raven::Box(10, 10, 100, 30)); main_widget.set_current_geometry(window.get_current_geometry()); - main_widget.set_style_background_fill_color(window.get_top_level_styles()->get_style_background_color()); - main_widget.set_style_do_background_fill(true); + main_widget.set_background_fill_color(window.get_top_level_styles()->get_background_color()); + main_widget.set_do_background_fill(true); window.set_main_widget(&main_widget); main_widget.add_child(&button);