Compare commits
No commits in common. "93b33c433b84b215169a3fe9b700624f8d980032" and "2a5ae1f1005795eb1afab2540830e7c95faab1d9" have entirely different histories.
93b33c433b
...
2a5ae1f100
3 changed files with 26 additions and 37 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Raven {
|
||||
|
||||
Point Widget::compute_window_relative() {
|
||||
Point Widget::window_relative() {
|
||||
Point point = { 0, 0 };
|
||||
for (Widget* parent = m_parent; parent; parent = parent->parent()) {
|
||||
point.add(parent->rect().x(), parent->rect().y());
|
||||
|
@ -51,11 +51,8 @@ void Widget::move_to(double x, double y) {
|
|||
}
|
||||
|
||||
void Widget::do_layout() {
|
||||
if (m_layout) {
|
||||
if (m_layout)
|
||||
m_layout->run();
|
||||
}
|
||||
|
||||
m_window_relative = compute_window_relative();
|
||||
}
|
||||
|
||||
void Widget::set_layout(std::shared_ptr<Layout> layout) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
void set_rect(Box rect) { m_rect = rect; reflow(); }
|
||||
void set_rect(Box rect, bool is_pure) { m_rect = rect; if (!is_pure) { reflow(); } }
|
||||
|
||||
Point &window_relative() { return m_window_relative; };
|
||||
Point window_relative();
|
||||
|
||||
WidgetType type() { return m_type; }
|
||||
ControlWidgetType control_type() { return m_control_type; }
|
||||
|
@ -114,19 +114,16 @@ protected:
|
|||
virtual void on_paint() {}
|
||||
|
||||
void set_did_init(bool did_init) { m_did_init = did_init; }
|
||||
Point compute_window_relative();
|
||||
|
||||
void do_layout();
|
||||
|
||||
void repaint();
|
||||
void reflow();
|
||||
private:
|
||||
void do_layout();
|
||||
void handle_repaint_rect(RepaintRectEvent &event);
|
||||
void handle_relayout_subtree(RelayoutSubtreeEvent &event);
|
||||
void handle_mouse_move_event(MouseMoveEvent &event);
|
||||
void handle_mouse_button_event(MouseButtonEvent &event);
|
||||
|
||||
Point m_window_relative { 0, 0 };
|
||||
Box m_rect { 0, 0, 0, 0 };
|
||||
std::vector<std::shared_ptr<Widget>> m_children;
|
||||
Widget *m_parent { nullptr };
|
||||
|
|
49
src/main.cpp
49
src/main.cpp
|
@ -11,45 +11,40 @@
|
|||
#include "src/Styles.hpp"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#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() {
|
||||
Raven::Window window {};
|
||||
int number = 0;
|
||||
|
||||
window.spawn_window();
|
||||
|
||||
auto main_widget = window.set_main_widget<Raven::Widget>();
|
||||
main_widget->set_layout<Raven::DocumentLayout>(10.0);
|
||||
|
||||
auto second_widget = main_widget->add<Raven::Widget>();
|
||||
second_widget->set_layout<Raven::DocumentLayout>(20.0);
|
||||
second_widget->resize(800, 800);
|
||||
auto count_label = main_widget->add<Raven::Label>("you have clicked the button 0 times");
|
||||
|
||||
auto inner_widget = second_widget->add<Raven::Widget>();
|
||||
inner_widget->set_layout<Raven::DocumentLayout>(8.0);
|
||||
inner_widget->resize(600, 600);
|
||||
main_widget->add<Raven::Widget>(Raven::ControlWidgetType::NewRow);
|
||||
|
||||
int number = 0;
|
||||
|
||||
for (int i = 0; i < 250; i++) {
|
||||
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!");
|
||||
button->on_click = [&]() {
|
||||
number += 10;
|
||||
|
||||
window.start_batch();
|
||||
auto& children = inner_widget->children();
|
||||
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();
|
||||
auto increment_button = main_widget->add<Raven::Button>("click me");
|
||||
increment_button->set_style(&Raven::accent_button_style);
|
||||
increment_button->on_click = [&]() {
|
||||
number++;
|
||||
update_count_label_text(count_label, number);
|
||||
};
|
||||
|
||||
auto reset_button = main_widget->add<Raven::Button>("reset");
|
||||
reset_button->on_click = [&]() {
|
||||
number = 0;
|
||||
update_count_label_text(count_label, number);
|
||||
};
|
||||
}
|
||||
|
||||
window.run(true);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue