Compare commits
No commits in common. "dd894d1024f2969d8a3c248ed58212aba30d4f28" and "805c9ff194d3fac267566aa08a7446bd90c4a440" have entirely different histories.
dd894d1024
...
805c9ff194
7 changed files with 22 additions and 66 deletions
24
src/Box.cpp
24
src/Box.cpp
|
@ -95,28 +95,4 @@ double Box::clamp_for_dimension(Direction direction, double value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box Box::united(const Box &other) {
|
|
||||||
if (is_null()) {
|
|
||||||
return other;
|
|
||||||
}
|
|
||||||
if (other.is_null()) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Box rect;
|
|
||||||
rect.set_left(std::min(left(), other.left()));
|
|
||||||
rect.set_top(std::min(top(), other.top()));
|
|
||||||
rect.set_right(std::max(right(), other.right()));
|
|
||||||
rect.set_bottom(std::max(bottom(), other.bottom()));
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Box::is_null() const {
|
|
||||||
return !(m_x && m_y && m_width && m_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Box::debug() {
|
|
||||||
return "Box(" + std::to_string(m_x) + ", " + std::to_string(m_y) + ", " + std::to_string(m_width) + ", " + std::to_string(m_height) + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
13
src/Box.hpp
13
src/Box.hpp
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Point.hpp"
|
#include "Point.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
@ -52,11 +51,6 @@ public:
|
||||||
double min_height() const { return m_min_height; }
|
double min_height() const { return m_min_height; }
|
||||||
double max_width() const { return m_max_width; }
|
double max_width() const { return m_max_width; }
|
||||||
double max_height() const { return m_max_height; }
|
double max_height() const { return m_max_height; }
|
||||||
double top() const { return y(); }
|
|
||||||
double bottom() const { return y() + height() - 1; }
|
|
||||||
double left() const { return x(); }
|
|
||||||
double right() const { return x() + width() - 1; }
|
|
||||||
bool is_null() const;
|
|
||||||
double dimension_at(Direction direction) { return direction == Direction::Horizontal ? width() : height(); }
|
double dimension_at(Direction direction) { return direction == Direction::Horizontal ? width() : height(); }
|
||||||
double max_dimension_at(Direction direction) { return direction == Direction::Horizontal ? max_width() : max_height(); }
|
double max_dimension_at(Direction direction) { return direction == Direction::Horizontal ? max_width() : max_height(); }
|
||||||
double min_dimension_at(Direction direction) { return direction == Direction::Horizontal ? min_width() : min_height(); }
|
double min_dimension_at(Direction direction) { return direction == Direction::Horizontal ? min_width() : min_height(); }
|
||||||
|
@ -66,10 +60,6 @@ public:
|
||||||
void set_y(double y) { m_y = y; }
|
void set_y(double y) { m_y = y; }
|
||||||
void set_width(double width);
|
void set_width(double width);
|
||||||
void set_height(double height);
|
void set_height(double height);
|
||||||
void set_top(double top) { set_y(top); }
|
|
||||||
void set_bottom(double bottom) { set_height(bottom - y() + 1); }
|
|
||||||
void set_right(double right) { set_width(right - x() + 1); }
|
|
||||||
void set_left(double left) { set_x(left); }
|
|
||||||
|
|
||||||
void set_max_width(double max_width) { m_max_width = max_width; set_width(m_width); }
|
void set_max_width(double max_width) { m_max_width = max_width; set_width(m_width); }
|
||||||
void set_max_height(double max_height) { m_max_height = max_height; set_height(m_height); }
|
void set_max_height(double max_height) { m_max_height = max_height; set_height(m_height); }
|
||||||
|
@ -83,9 +73,6 @@ public:
|
||||||
bool contains_box(const Box &other) const;
|
bool contains_box(const Box &other) const;
|
||||||
|
|
||||||
Box offset(double x, double y);
|
Box offset(double x, double y);
|
||||||
Box united(const Box &other);
|
|
||||||
|
|
||||||
std::string debug();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,18 +192,18 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::handle_relayout_subtree(RelayoutSubtreeEvent &event) {
|
void Widget::handle_relayout_subtree(RelayoutSubtreeEvent &event) {
|
||||||
on_layout();
|
on_layout(); // hack
|
||||||
|
|
||||||
m_window_relative = compute_window_relative();
|
m_window_relative = compute_window_relative();
|
||||||
|
|
||||||
if (m_layout) {
|
|
||||||
m_layout->run();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto child : m_children) {
|
for (auto child : m_children) {
|
||||||
child->dispatch_event(event);
|
child->dispatch_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_layout) {
|
||||||
|
m_layout->run();
|
||||||
|
}
|
||||||
|
|
||||||
on_after_layout();
|
on_after_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ private:
|
||||||
bool m_consumes_hits { false };
|
bool m_consumes_hits { false };
|
||||||
bool m_accepts_events { true };
|
bool m_accepts_events { true };
|
||||||
bool m_absolute { false };
|
bool m_absolute { false };
|
||||||
bool m_grows { false };
|
bool m_grows { true };
|
||||||
ControlWidgetType m_control_type { ControlWidgetType::Widget };
|
ControlWidgetType m_control_type { ControlWidgetType::Widget };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,10 +76,9 @@ bool Window::dispatch_to_main_widget(Event &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::repaint(Box geometry) {
|
void Window::repaint(Box geometry) {
|
||||||
if (m_batches) {
|
m_did_repaint_during_batch = true;
|
||||||
m_invalidated_area = m_invalidated_area.united(geometry);
|
if (m_batches)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
auto event = RepaintRectEvent(true, geometry);
|
auto event = RepaintRectEvent(true, geometry);
|
||||||
dispatch_to_main_widget(event);
|
dispatch_to_main_widget(event);
|
||||||
|
@ -117,6 +116,7 @@ void Window::reflow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::start_batch() {
|
void Window::start_batch() {
|
||||||
|
//INFO << "New batch started. Current count: " << m_batches << std::endl;
|
||||||
m_batches++;
|
m_batches++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ void Window::end_batch() {
|
||||||
// we are only interested in performing batch operations for the last batch
|
// we are only interested in performing batch operations for the last batch
|
||||||
if (m_batches > 1) {
|
if (m_batches > 1) {
|
||||||
m_batches--;
|
m_batches--;
|
||||||
|
//INFO << "Consumed batch. Current count: " << m_batches << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,17 +135,17 @@ void Window::end_batch() {
|
||||||
|
|
||||||
if (m_did_relayout_during_batch) {
|
if (m_did_relayout_during_batch) {
|
||||||
reflow();
|
reflow();
|
||||||
} else if (!m_invalidated_area.is_null()) {
|
} else if (m_did_repaint_during_batch) {
|
||||||
repaint(m_invalidated_area);
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_did_relayout_during_batch = false;
|
m_did_relayout_during_batch = false;
|
||||||
m_invalidated_area = {0, 0, 0, 0};
|
m_did_repaint_during_batch = false;
|
||||||
|
INFO << "Performed all batch actions." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::run(bool block) {
|
void Window::run(bool block) {
|
||||||
XEvent e;
|
XEvent e;
|
||||||
bool is_loop_batch_started = false;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (block || XPending(m_x_display))
|
if (block || XPending(m_x_display))
|
||||||
|
@ -152,13 +153,10 @@ void Window::run(bool block) {
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!is_loop_batch_started) {
|
|
||||||
start_batch();
|
|
||||||
is_loop_batch_started = true;
|
|
||||||
}
|
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case MapNotify: {
|
case MapNotify: {
|
||||||
INFO << "[X11 EVENT] MapNotify" << std::endl;
|
INFO << "[X11 EVENT] MapNotify" << std::endl;
|
||||||
|
end_batch();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ConfigureNotify: {
|
case ConfigureNotify: {
|
||||||
|
@ -212,16 +210,14 @@ void Window::run(bool block) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (XPending(m_x_display) == 0) {
|
if (XPending(m_x_display) == 0 && !m_microtasks.empty()) {
|
||||||
|
start_batch();
|
||||||
while (!m_microtasks.empty()) {
|
while (!m_microtasks.empty()) {
|
||||||
auto callback = m_microtasks.front();
|
auto callback = m_microtasks.front();
|
||||||
callback();
|
callback();
|
||||||
m_microtasks.pop();
|
m_microtasks.pop();
|
||||||
}
|
}
|
||||||
if (is_loop_batch_started) {
|
|
||||||
end_batch();
|
end_batch();
|
||||||
is_loop_batch_started = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,8 @@ private:
|
||||||
Box m_rect { 0, 0, 800, 600 };
|
Box m_rect { 0, 0, 800, 600 };
|
||||||
Painter m_painter {};
|
Painter m_painter {};
|
||||||
Cairo::RefPtr<Cairo::XlibSurface> m_xlib_surface { nullptr };
|
Cairo::RefPtr<Cairo::XlibSurface> m_xlib_surface { nullptr };
|
||||||
int m_batches { 0 };
|
int m_batches { 1 };
|
||||||
Box m_invalidated_area {0, 0, 0, 0};
|
bool m_did_repaint_during_batch { false };
|
||||||
bool m_did_relayout_during_batch { false };
|
bool m_did_relayout_during_batch { false };
|
||||||
std::queue<std::function<void()>> m_microtasks;
|
std::queue<std::function<void()>> m_microtasks;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
int main() {
|
int main() {
|
||||||
Raven::Window window {};
|
Raven::Window window {};
|
||||||
window.spawn_window();
|
window.spawn_window();
|
||||||
window.start_batch();
|
|
||||||
|
|
||||||
auto main_widget = window.set_main_widget<Raven::Widget>();
|
auto main_widget = window.set_main_widget<Raven::Widget>();
|
||||||
auto main_widget_layout = main_widget->set_layout<Raven::BoxLayout>(Raven::Direction::Horizontal);
|
auto main_widget_layout = main_widget->set_layout<Raven::BoxLayout>(Raven::Direction::Horizontal);
|
||||||
|
@ -33,9 +32,8 @@ int main() {
|
||||||
auto list_view = main_widget->add<Raven::ListView>();
|
auto list_view = main_widget->add<Raven::ListView>();
|
||||||
|
|
||||||
auto content = main_widget->add<Raven::Widget>();
|
auto content = main_widget->add<Raven::Widget>();
|
||||||
auto content_layout = content->set_layout<Raven::BoxLayout>(Raven::Direction::Vertical);
|
auto content_layout = content->set_layout<Raven::ColumnLayout>();
|
||||||
content_layout->set_margin(6.0);
|
content_layout->set_margin(6.0);
|
||||||
content_layout->set_spacing(6.0);
|
|
||||||
content->set_style(&Raven::raised_widget_style);
|
content->set_style(&Raven::raised_widget_style);
|
||||||
|
|
||||||
auto selected_label = content->add<Raven::Label>("No selection");
|
auto selected_label = content->add<Raven::Label>("No selection");
|
||||||
|
@ -67,7 +65,6 @@ int main() {
|
||||||
}
|
}
|
||||||
list_view->elements_updated();
|
list_view->elements_updated();
|
||||||
|
|
||||||
window.end_batch();
|
|
||||||
window.run(true);
|
window.run(true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue