remove annoying style_ prefix from DEF_STYLE and rename it to DEF_PROP

This commit is contained in:
hippoz 2022-03-18 03:04:34 +02:00
parent c2a605f172
commit 26858b795d
Signed by: hippoz
GPG key ID: 7C52899193467641
8 changed files with 46 additions and 46 deletions

View file

@ -10,14 +10,14 @@ namespace Raven {
void Button::on_init() { void Button::on_init() {
auto top_level_styles = get_top_level_styles(); auto top_level_styles = get_top_level_styles();
set_style_text_fill_color(top_level_styles->get_style_text_color()); set_text_fill_color(top_level_styles->get_text_color());
set_style_active_background_fill_color(top_level_styles->get_style_button_active_color()); set_active_background_fill_color(top_level_styles->get_button_active_color());
set_style_focused_background_fill_color(top_level_styles->get_style_button_focused_color()); set_focused_background_fill_color(top_level_styles->get_button_focused_color());
set_style_normal_background_fill_color(top_level_styles->get_style_button_normal_color()); set_normal_background_fill_color(top_level_styles->get_button_normal_color());
set_style_do_background_fill(true); set_do_background_fill(true);
set_style_background_fill_color(m_style_normal_background_fill_color); set_background_fill_color(m_normal_background_fill_color);
set_style_font_description(top_level_styles->get_style_controls_font_description()); set_font_description(top_level_styles->get_controls_font_description());
set_did_init(true); set_did_init(true);
} }
@ -25,17 +25,17 @@ void Button::on_init() {
void Button::on_paint() { void Button::on_paint() {
auto painter = get_window()->get_painter(); auto painter = get_window()->get_painter();
painter.source_rgb(m_style_text_fill_color); painter.source_rgb(m_text_fill_color);
painter.set_pango_font_description(m_style_font_description); painter.set_pango_font_description(m_font_description);
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center); painter.text(get_current_geometry(), m_text, PaintTextAlign::Center);
painter.fill(); painter.fill();
} }
void Button::on_focus_update(FocusUpdateEvent &event) { void Button::on_focus_update(FocusUpdateEvent &event) {
if (is_focused()) { if (is_focused()) {
set_style_background_fill_color(m_style_focused_background_fill_color); set_background_fill_color(m_focused_background_fill_color);
} else { } else {
set_style_background_fill_color(m_style_normal_background_fill_color); set_background_fill_color(m_normal_background_fill_color);
} }
} }

View file

@ -9,13 +9,13 @@
namespace Raven { namespace Raven {
class Button : public Widget { 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_PROP(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_PROP(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(active_background_fill_color, RGB, 0.0, 0.0, 0.0)
DEF_STYLE(font_description, PangoFontDescription*, nullptr) DEF_PROP(font_description, PangoFontDescription*, nullptr)
private: private:
std::string m_text; std::string m_text;

9
src/PropMacros.hpp Normal file
View file

@ -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:

View file

@ -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:

View file

@ -3,22 +3,22 @@
#include <iostream> #include <iostream>
#include "Forward.hpp" #include "Forward.hpp"
#include "pango/pango-font.h" #include "pango/pango-font.h"
#include "StyleMacros.hpp" #include "PropMacros.hpp"
#include "RGB.hpp" #include "RGB.hpp"
namespace Raven { namespace Raven {
class TopLevelStyles { 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_PROP(text_color, RGB, 0.0, 0.0, 0.0)
DEF_STYLE(accent_color, RGB, 0.6941, 0.3843, 0.5254) DEF_PROP(accent_color, RGB, 0.6941, 0.3843, 0.5254)
DEF_STYLE(accent_color_darker, RGB, 0.5607, 0.2470, 0.4431) DEF_PROP(accent_color_darker, RGB, 0.5607, 0.2470, 0.4431)
DEF_STYLE(background_color, RGB, 0.9764, 0.9607, 0.8431) DEF_PROP(background_color, RGB, 0.9764, 0.9607, 0.8431)
DEF_STYLE(button_normal_color, RGB, m_style_accent_color) DEF_PROP(button_normal_color, RGB, m_accent_color)
DEF_STYLE(button_focused_color, RGB, m_style_accent_color_darker) DEF_PROP(button_focused_color, RGB, m_accent_color_darker)
DEF_STYLE(button_active_color, RGB, m_style_accent_color_darker) DEF_PROP(button_active_color, RGB, m_accent_color_darker)
private: private:
Window *m_window; Window *m_window;
@ -32,12 +32,12 @@ public:
pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL);
pango_font_description_set_absolute_size(font_description, 16 * PANGO_SCALE); 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() { ~TopLevelStyles() {
if (m_style_controls_font_description) { if (m_controls_font_description) {
pango_font_description_free(m_style_controls_font_description); pango_font_description_free(m_controls_font_description);
} }
} }

View file

@ -37,14 +37,14 @@ void Widget::remove_child(Widget *child) {
} }
void Widget::do_generic_paint() { void Widget::do_generic_paint() {
if (m_style_do_background_fill) { if (m_do_background_fill) {
auto painter = m_window->get_painter(); auto painter = m_window->get_painter();
auto cr = painter.get_cairo(); auto cr = painter.get_cairo();
cr->save(); cr->save();
painter.source_rgb(m_style_background_fill_color); painter.source_rgb(m_background_fill_color);
painter.rounded_rectangle(m_current_geometry, m_style_background_border_radius); painter.rounded_rectangle(m_current_geometry, m_background_border_radius);
painter.fill(); painter.fill();
cr->restore(); cr->restore();

View file

@ -8,15 +8,15 @@
#include "Forward.hpp" #include "Forward.hpp"
#include "RGB.hpp" #include "RGB.hpp"
#include "TopLevelStyles.hpp" #include "TopLevelStyles.hpp"
#include "StyleMacros.hpp" #include "PropMacros.hpp"
namespace Raven { namespace Raven {
class Widget { class Widget {
DEF_STYLE(do_background_fill, bool, false) DEF_PROP(do_background_fill, bool, false)
DEF_STYLE(background_fill_color, RGB, 0, 0, 0) DEF_PROP(background_fill_color, RGB, 0, 0, 0)
DEF_STYLE(background_border_radius, double, 0.0) DEF_PROP(background_border_radius, double, 0.0)
private: private:

View file

@ -13,8 +13,8 @@ int main() {
button.set_current_geometry(Raven::Box(10, 10, 100, 30)); button.set_current_geometry(Raven::Box(10, 10, 100, 30));
main_widget.set_current_geometry(window.get_current_geometry()); 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_background_fill_color(window.get_top_level_styles()->get_background_color());
main_widget.set_style_do_background_fill(true); main_widget.set_do_background_fill(true);
window.set_main_widget(&main_widget); window.set_main_widget(&main_widget);
main_widget.add_child(&button); main_widget.add_child(&button);