From 23bde79967df2cb37fafccfdc46b02472616b18f Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 12 Jun 2022 22:16:26 +0300 Subject: [PATCH] improve styles --- src/RGB.hpp | 8 ++++++++ src/Styles.cpp | 55 +++++++++++++++++++++++++++++++++++++++----------- src/Styles.hpp | 1 + src/Widget.cpp | 6 +++--- src/main.cpp | 2 ++ 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/RGB.hpp b/src/RGB.hpp index 5ecb908..4c5c267 100644 --- a/src/RGB.hpp +++ b/src/RGB.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace Raven { class RGB { @@ -14,6 +16,12 @@ public: , m_g(g) , m_b(b) {} + RGB(unsigned int hex) { + m_r = (((hex) >> (2 * 8)) & 0xFF) / 255.0; + m_g = (((hex) >> (1 * 8)) & 0xFF) / 255.0; + m_b = (((hex) >> (0 * 8)) & 0xFF) / 255.0; + } + void set_r(double r) { m_r = r; } void set_g(double g) { m_g = g; } void set_b(double b) { m_b = b; } diff --git a/src/Styles.cpp b/src/Styles.cpp index 3beecd4..569716d 100644 --- a/src/Styles.cpp +++ b/src/Styles.cpp @@ -5,12 +5,32 @@ namespace Raven { +RGB unused = RGB(0); + +RGB white4 = RGB(0xffffff); +RGB white3 = RGB(0xfafafa); +RGB white2 = RGB(0xe6e6e6); +RGB white1 = RGB(0xd0d0d0); +RGB white0 = RGB(0xc1c1c1); + +RGB black0 = RGB(0x000000); +RGB black1 = RGB(0x030303); +RGB black2 = RGB(0x101010); +RGB black3 = RGB(0x171717); +RGB black4 = RGB(0x1E1E1E); +RGB black5 = RGB(0x242424); +RGB black6 = RGB(0x2E2E2E); + +RGB accent0 = RGB(0x7f465f); +RGB accent1 = RGB(0x995473); +RGB accent2 = RGB(0xb16286); + GenericStyle default_widget_style { pango_font_description_from_string("sans-serif"), - RGB(0.00000, 0.00000, 0.00000), - RGB(1.00000, 1.00000, 1.00000), - RGB(1.00000, 1.00000, 1.00000), - RGB(1.00000, 1.00000, 1.00000), + black6, + white3, + white3, + white3, 0.0, true, false @@ -18,21 +38,32 @@ GenericStyle default_widget_style { GenericStyle default_button_style { pango_font_description_from_string("sans-serif"), - RGB(0.00000, 0.00000, 0.00000), - RGB(0.73333, 0.40392, 0.89412), - RGB(0.63922, 0.27843, 0.81961), - RGB(0.54118, 0.18039, 0.72157), + black6, + white2, + white1, + white0, 6.0, true, true }; +GenericStyle accent_button_style { + pango_font_description_from_string("sans-serif"), + black0, + accent2, + accent1, + accent0, + 5.0, + true, + true +}; + GenericStyle default_label_style { pango_font_description_from_string("sans-serif"), - RGB(0.00000, 0.00000, 0.00000), - RGB(0.00000, 0.00000, 0.00000), - RGB(0.00000, 0.00000, 0.00000), - RGB(0.00000, 0.00000, 0.00000), + black6, + unused, + unused, + unused, 0.0, false, false diff --git a/src/Styles.hpp b/src/Styles.hpp index 152ab74..5c1f9f0 100644 --- a/src/Styles.hpp +++ b/src/Styles.hpp @@ -6,6 +6,7 @@ namespace Raven { extern GenericStyle default_widget_style; extern GenericStyle default_button_style; +extern GenericStyle accent_button_style; extern GenericStyle default_label_style; } diff --git a/src/Widget.cpp b/src/Widget.cpp index 8bc060a..fada833 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -126,10 +126,10 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) { // note that we're using the bounds of the paint event as the rectangle, this ensures that we dont draw over other widgets which won't be repainted. if (m_style->fill_background()) { if (m_style->update_background()) { - if (m_is_focused) { - painter.source_rgb(m_style->background_focused()); - } else if (m_is_active) { + if (m_is_active) { painter.source_rgb(m_style->background_active()); + } else if (m_is_focused) { + painter.source_rgb(m_style->background_focused()); } else { painter.source_rgb(m_style->background_norm()); } diff --git a/src/main.cpp b/src/main.cpp index 9cafb48..f495601 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "RGB.hpp" #include "DocumentLayout.hpp" #include "Events.hpp" +#include "src/Styles.hpp" #include #include #include @@ -31,6 +32,7 @@ int main() { for (int i = 0; i < 250; i++) { auto button = inner_widget->add("click me"); + button->set_style(&Raven::accent_button_style); auto label = inner_widget->add("click one of the buttons!"); button->on_click = [&]() { number += 10;