improve styles

This commit is contained in:
hippoz 2022-06-12 22:16:26 +03:00
parent 3a9b530a08
commit 23bde79967
Signed by: hippoz
GPG key ID: 7C52899193467641
5 changed files with 57 additions and 15 deletions

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <iostream>
namespace Raven { namespace Raven {
class RGB { class RGB {
@ -14,6 +16,12 @@ public:
, m_g(g) , m_g(g)
, m_b(b) {} , 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_r(double r) { m_r = r; }
void set_g(double g) { m_g = g; } void set_g(double g) { m_g = g; }
void set_b(double b) { m_b = b; } void set_b(double b) { m_b = b; }

View file

@ -5,12 +5,32 @@
namespace Raven { 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 { GenericStyle default_widget_style {
pango_font_description_from_string("sans-serif"), pango_font_description_from_string("sans-serif"),
RGB(0.00000, 0.00000, 0.00000), black6,
RGB(1.00000, 1.00000, 1.00000), white3,
RGB(1.00000, 1.00000, 1.00000), white3,
RGB(1.00000, 1.00000, 1.00000), white3,
0.0, 0.0,
true, true,
false false
@ -18,21 +38,32 @@ GenericStyle default_widget_style {
GenericStyle default_button_style { GenericStyle default_button_style {
pango_font_description_from_string("sans-serif"), pango_font_description_from_string("sans-serif"),
RGB(0.00000, 0.00000, 0.00000), black6,
RGB(0.73333, 0.40392, 0.89412), white2,
RGB(0.63922, 0.27843, 0.81961), white1,
RGB(0.54118, 0.18039, 0.72157), white0,
6.0, 6.0,
true, true,
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 { GenericStyle default_label_style {
pango_font_description_from_string("sans-serif"), pango_font_description_from_string("sans-serif"),
RGB(0.00000, 0.00000, 0.00000), black6,
RGB(0.00000, 0.00000, 0.00000), unused,
RGB(0.00000, 0.00000, 0.00000), unused,
RGB(0.00000, 0.00000, 0.00000), unused,
0.0, 0.0,
false, false,
false false

View file

@ -6,6 +6,7 @@ namespace Raven {
extern GenericStyle default_widget_style; extern GenericStyle default_widget_style;
extern GenericStyle default_button_style; extern GenericStyle default_button_style;
extern GenericStyle accent_button_style;
extern GenericStyle default_label_style; extern GenericStyle default_label_style;
} }

View file

@ -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. // 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->fill_background()) {
if (m_style->update_background()) { if (m_style->update_background()) {
if (m_is_focused) { if (m_is_active) {
painter.source_rgb(m_style->background_focused());
} else if (m_is_active) {
painter.source_rgb(m_style->background_active()); painter.source_rgb(m_style->background_active());
} else if (m_is_focused) {
painter.source_rgb(m_style->background_focused());
} else { } else {
painter.source_rgb(m_style->background_norm()); painter.source_rgb(m_style->background_norm());
} }

View file

@ -8,6 +8,7 @@
#include "RGB.hpp" #include "RGB.hpp"
#include "DocumentLayout.hpp" #include "DocumentLayout.hpp"
#include "Events.hpp" #include "Events.hpp"
#include "src/Styles.hpp"
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <string> #include <string>
@ -31,6 +32,7 @@ int main() {
for (int i = 0; i < 250; i++) { for (int i = 0; i < 250; i++) {
auto button = inner_widget->add<Raven::Button>("click me"); auto button = inner_widget->add<Raven::Button>("click me");
button->set_style(&Raven::accent_button_style);
auto label = inner_widget->add<Raven::Label>("click one of the buttons!"); auto label = inner_widget->add<Raven::Label>("click one of the buttons!");
button->on_click = [&]() { button->on_click = [&]() {
number += 10; number += 10;