Compare commits

...

4 commits

Author SHA1 Message Date
hippoz
2a5ae1f100
add a simpler example program 2022-06-12 23:40:04 +03:00
hippoz
c96fc98f37
export colors 2022-06-12 23:39:48 +03:00
hippoz
cd38bad6ea
fix DocumentLayout 2022-06-12 23:39:38 +03:00
hippoz
23bde79967
improve styles 2022-06-12 22:16:26 +03:00
6 changed files with 103 additions and 43 deletions

View file

@ -21,7 +21,7 @@ void DocumentLayout::run() {
largest_height_so_far = child->rect().height(); largest_height_so_far = child->rect().height();
} }
bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow && largest_height_so_far); bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow);
bool new_row_because_of_justification = (current_position.x() + child->rect().width() + m_margin) >= m_target->rect().width(); bool new_row_because_of_justification = (current_position.x() + child->rect().width() + m_margin) >= m_target->rect().width();
bool should_do_new_row = new_row_because_of_control_widget || new_row_because_of_justification; bool should_do_new_row = new_row_because_of_control_widget || new_row_because_of_justification;
if (should_do_new_row) { if (should_do_new_row) {
@ -31,8 +31,11 @@ void DocumentLayout::run() {
child->rect().set_x(current_position.x()); child->rect().set_x(current_position.x());
child->rect().set_y(current_position.y()); child->rect().set_y(current_position.y());
if (!new_row_because_of_control_widget) {
current_position.add(child->rect().width() + m_margin, 0); current_position.add(child->rect().width() + m_margin, 0);
} }
} }
}
} }

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

@ -4,8 +4,29 @@
namespace Raven { namespace Raven {
extern RGB unused;
extern RGB white4;
extern RGB white3;
extern RGB white2;
extern RGB white1;
extern RGB white0;
extern RGB black0;
extern RGB black1;
extern RGB black2;
extern RGB black3;
extern RGB black4;
extern RGB black5;
extern RGB black6;
extern RGB accent0;
extern RGB accent1;
extern RGB accent2;
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,46 +8,43 @@
#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 <sstream>
#include <string> #include <string>
void update_count_label_text(std::shared_ptr<Raven::Label> label, int number) {
std::stringstream text;
text << "you have clicked the button " << std::to_string(number) << " times";
label->set_text(text.str());
}
int main() { int main() {
Raven::Window window {}; Raven::Window window {};
int number = 0;
window.spawn_window(); window.spawn_window();
auto main_widget = window.set_main_widget<Raven::Widget>(); auto main_widget = window.set_main_widget<Raven::Widget>();
main_widget->set_layout<Raven::DocumentLayout>(10.0); main_widget->set_layout<Raven::DocumentLayout>(10.0);
auto second_widget = main_widget->add<Raven::Widget>(); auto count_label = main_widget->add<Raven::Label>("you have clicked the button 0 times");
second_widget->set_layout<Raven::DocumentLayout>(20.0);
second_widget->resize(800, 800);
auto inner_widget = second_widget->add<Raven::Widget>(); main_widget->add<Raven::Widget>(Raven::ControlWidgetType::NewRow);
inner_widget->set_layout<Raven::DocumentLayout>(8.0);
inner_widget->resize(600, 600);
int number = 0; auto increment_button = main_widget->add<Raven::Button>("click me");
increment_button->set_style(&Raven::accent_button_style);
for (int i = 0; i < 250; i++) { increment_button->on_click = [&]() {
auto button = inner_widget->add<Raven::Button>("click me"); number++;
auto label = inner_widget->add<Raven::Label>("click one of the buttons!"); update_count_label_text(count_label, number);
button->on_click = [&]() { };
number += 10;
auto reset_button = main_widget->add<Raven::Button>("reset");
window.start_batch(); reset_button->on_click = [&]() {
auto& children = inner_widget->children(); number = 0;
for (auto& child : children) { update_count_label_text(count_label, number);
if (child->type() == Raven::WidgetType::Button) {
std::static_pointer_cast<Raven::Button>(child)->set_text(std::to_string(number));
}
if (child->type() == Raven::WidgetType::Label) {
std::static_pointer_cast<Raven::Label>(child)->set_text(std::to_string(number));
}
}
window.end_batch();
}; };
}
window.run(true); window.run(true);
return 0; return 0;