Compare commits

..

No commits in common. "2a5ae1f1005795eb1afab2540830e7c95faab1d9" and "3a9b530a08c5c14896de289db153d57a19a0e99b" have entirely different histories.

6 changed files with 43 additions and 103 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); bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow && largest_height_so_far);
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,11 +31,8 @@ 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,7 +1,5 @@
#pragma once #pragma once
#include <iostream>
namespace Raven { namespace Raven {
class RGB { class RGB {
@ -16,12 +14,6 @@ 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,32 +5,12 @@
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"),
black6, RGB(0.00000, 0.00000, 0.00000),
white3, RGB(1.00000, 1.00000, 1.00000),
white3, RGB(1.00000, 1.00000, 1.00000),
white3, RGB(1.00000, 1.00000, 1.00000),
0.0, 0.0,
true, true,
false false
@ -38,32 +18,21 @@ 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"),
black6, RGB(0.00000, 0.00000, 0.00000),
white2, RGB(0.73333, 0.40392, 0.89412),
white1, RGB(0.63922, 0.27843, 0.81961),
white0, RGB(0.54118, 0.18039, 0.72157),
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"),
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, RGB(0.00000, 0.00000, 0.00000),
0.0, 0.0,
false, false,
false false

View file

@ -4,29 +4,8 @@
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_active) { if (m_is_focused) {
painter.source_rgb(m_style->background_active());
} else if (m_is_focused) {
painter.source_rgb(m_style->background_focused()); painter.source_rgb(m_style->background_focused());
} else if (m_is_active) {
painter.source_rgb(m_style->background_active());
} else { } else {
painter.source_rgb(m_style->background_norm()); painter.source_rgb(m_style->background_norm());
} }

View file

@ -8,43 +8,46 @@
#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 count_label = main_widget->add<Raven::Label>("you have clicked the button 0 times"); auto second_widget = main_widget->add<Raven::Widget>();
second_widget->set_layout<Raven::DocumentLayout>(20.0);
second_widget->resize(800, 800);
main_widget->add<Raven::Widget>(Raven::ControlWidgetType::NewRow); auto inner_widget = second_widget->add<Raven::Widget>();
inner_widget->set_layout<Raven::DocumentLayout>(8.0);
inner_widget->resize(600, 600);
auto increment_button = main_widget->add<Raven::Button>("click me"); int number = 0;
increment_button->set_style(&Raven::accent_button_style);
increment_button->on_click = [&]() { for (int i = 0; i < 250; i++) {
number++; auto button = inner_widget->add<Raven::Button>("click me");
update_count_label_text(count_label, number); auto label = inner_widget->add<Raven::Label>("click one of the buttons!");
}; button->on_click = [&]() {
number += 10;
auto reset_button = main_widget->add<Raven::Button>("reset");
reset_button->on_click = [&]() { window.start_batch();
number = 0; auto& children = inner_widget->children();
update_count_label_text(count_label, number); for (auto& child : children) {
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;