Compare commits

...

5 commits

Author SHA1 Message Date
hippoz
e76e2b43a1
add dirty hack for documentlayout 2022-10-29 13:08:00 +03:00
hippoz
ce47b21e02
fix include paths 2022-10-29 00:10:42 +03:00
hippoz
55b19a3834
allow using custom class for window in application 2022-10-28 23:58:07 +03:00
hippoz
9b2655beb2
fix relayout subtree logic 2022-10-28 23:24:07 +03:00
hippoz
abbedd9db1
fix documentlayout by requiring fixed width of target 2022-10-28 19:46:33 +03:00
14 changed files with 48 additions and 23 deletions

View file

@ -61,7 +61,8 @@ raven_header_files = [
'./src/Widget.hpp', './src/Widget.hpp',
'./src/SvgWidget.hpp', './src/SvgWidget.hpp',
'./src/Application.hpp', './src/Application.hpp',
'./src/Window.hpp' './src/Window.hpp',
'./src/TextInput.hpp',
] ]

View file

@ -17,9 +17,9 @@ public:
int turn(); int turn();
int run(); int run();
template<class... Args> template<typename T, class... Args>
std::shared_ptr<Window> add_window(Args&&... args) { std::shared_ptr<T> add_window(Args&&... args) {
std::shared_ptr<Window> child = std::make_shared<Window>(std::forward<Args>(args)...); std::shared_ptr<T> child = std::make_shared<T>(std::forward<Args>(args)...);
add_window(child); add_window(child);
return child; return child;
} }

View file

@ -1,7 +1,7 @@
#include "BoxLayout.hpp" #include "BoxLayout.hpp"
#include "Box.hpp" #include "Box.hpp"
#include "Widget.hpp" #include "Widget.hpp"
#include "src/Events.hpp" #include "Events.hpp"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@ -25,6 +25,11 @@ bool BoxLayout::run() {
for (unsigned int i = 0; i < m_target->children().size(); i++) { for (unsigned int i = 0; i < m_target->children().size(); i++) {
auto child = m_target->children()[i]; auto child = m_target->children()[i];
// dirty hack for DocumentLayout
if (child->layout() && child->layout()->depends_on_width() && m_direction == Direction::Vertical && !m_justify_secondary_dimension) {
child->rect().set_width(m_target->rect().width() - 2 * m_margin);
}
if (child->layout() && child->layout()->dynamically_sizes_target()) { if (child->layout() && child->layout()->dynamically_sizes_target()) {
auto event = RelayoutSubtreeEvent(); auto event = RelayoutSubtreeEvent();
child->dispatch_event(event); child->dispatch_event(event);
@ -89,8 +94,13 @@ bool BoxLayout::run() {
auto child = m_target->children()[i]; auto child = m_target->children()[i];
Slot slot = working_slots[i]; Slot slot = working_slots[i];
std::cout << "SLOT! " << i << std::endl;
if (slot.type == SlotType::Auto) { if (slot.type == SlotType::Auto) {
std::cout << "auto - setting to " << space_per_unslotted_widget << std::endl;
slot.pixel = space_per_unslotted_widget; slot.pixel = space_per_unslotted_widget;
} else {
std::cout << "pixel: " << slot.pixel << std::endl;
} }
// make sure pixel values are aligned to the pixel grid // make sure pixel values are aligned to the pixel grid

View file

@ -1,6 +1,7 @@
#include "DocumentLayout.hpp" #include "DocumentLayout.hpp"
#include "Point.hpp" #include "Point.hpp"
#include "Widget.hpp" #include "Widget.hpp"
#include "Events.hpp"
#include <iostream> #include <iostream>
namespace Raven { namespace Raven {
@ -9,15 +10,20 @@ bool DocumentLayout::run() {
if (!m_target) if (!m_target)
return false; return false;
Point bound { m_margin + m_target->rect().max_geometry().width(), m_margin };
Point current_position { m_margin, m_margin }; Point current_position { m_margin, m_margin };
double largest_height_so_far = -1.0; double largest_height_so_far = -1.0;
double desired_height = m_margin * 2;
auto& children = m_target->children(); auto& children = m_target->children();
for (auto child : children) { for (auto child : children) {
if (child->absolute()) if (child->absolute())
continue; continue;
if (child->layout() && child->layout()->dynamically_sizes_target()) {
auto event = RelayoutSubtreeEvent();
child->dispatch_event(event);
}
if (child->rect().height() > largest_height_so_far) { if (child->rect().height() > largest_height_so_far) {
largest_height_so_far = child->rect().height(); largest_height_so_far = child->rect().height();
} }
@ -27,7 +33,7 @@ bool DocumentLayout::run() {
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) {
current_position.add(0, largest_height_so_far + m_margin); current_position.add(0, largest_height_so_far + m_margin);
bound.add(0, largest_height_so_far + m_margin); desired_height += largest_height_so_far + m_margin;
current_position.set_x(m_margin); current_position.set_x(m_margin);
} }
@ -39,13 +45,17 @@ bool DocumentLayout::run() {
} }
} }
for (auto &child : m_target->children()) {
auto event = RelayoutSubtreeEvent();
child->dispatch_event(event);
}
/* account for the first row */ /* account for the first row */
bound.add(0, largest_height_so_far); desired_height += largest_height_so_far;
m_target->rect().set_width(bound.x()); m_target->rect().set_height(desired_height);
m_target->rect().set_height(bound.y());
return false; return true;
} }
} }

View file

@ -15,10 +15,13 @@ public:
: Layout() : Layout()
, m_margin(margin) {} , m_margin(margin) {}
bool run(); bool run() override;
double margin() { return m_margin; } double margin() { return m_margin; }
void set_margin(double margin) { m_margin = margin; run(); } void set_margin(double margin) { m_margin = margin; run(); }
bool dynamically_sizes_target() override { return true; }
bool depends_on_width() override { return true; }
}; };
} }

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "pango/pango-font.h" #include <pango/pango-font.h>
#include "RGB.hpp" #include "RGB.hpp"
#define __RAVEN_STYLE_PROP(name, type, ...) \ #define __RAVEN_STYLE_PROP(name, type, ...) \

View file

@ -16,6 +16,7 @@ public:
Widget *target() { return m_target; } Widget *target() { return m_target; }
virtual bool dynamically_sizes_target() { return false; } virtual bool dynamically_sizes_target() { return false; }
virtual bool depends_on_width() { return false; }
virtual ~Layout() {} virtual ~Layout() {}
}; };

View file

@ -1,7 +1,7 @@
#include "ListLayout.hpp" #include "ListLayout.hpp"
#include "Widget.hpp" #include "Widget.hpp"
#include "Box.hpp" #include "Box.hpp"
#include "src/Events.hpp" #include "Events.hpp"
namespace Raven { namespace Raven {

View file

@ -12,7 +12,7 @@ public:
: Layout() : Layout()
, m_direction(direction) {} , m_direction(direction) {}
bool run(); bool run() override;
double margin() { return m_margin; } double margin() { return m_margin; }
void set_margin(double margin) { m_margin = margin; run(); } void set_margin(double margin) { m_margin = margin; run(); }
@ -22,6 +22,8 @@ public:
bool inherit_secondary_dimension() { return m_inherit_secondary_dimension; } bool inherit_secondary_dimension() { return m_inherit_secondary_dimension; }
void set_inherit_secondary_dimension(bool inherit_secondary_dimension) { m_inherit_secondary_dimension = inherit_secondary_dimension; } void set_inherit_secondary_dimension(bool inherit_secondary_dimension) { m_inherit_secondary_dimension = inherit_secondary_dimension; }
bool dynamically_sizes_target() override { return true; }
private: private:
double m_margin { 0.0 }; double m_margin { 0.0 };
double m_spacing { 0.0 }; double m_spacing { 0.0 };

View file

@ -1,6 +1,6 @@
#include "ListView.hpp" #include "ListView.hpp"
#include "pango/pango-layout.h" #include "pango/pango-layout.h"
#include "src/Painter.hpp" #include "Painter.hpp"
namespace Raven { namespace Raven {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "src/Widget.hpp" #include "Widget.hpp"
namespace Raven { namespace Raven {

View file

@ -2,7 +2,7 @@
#include "Events.hpp" #include "Events.hpp"
#include "Logging.hpp" #include "Logging.hpp"
#include "Painter.hpp" #include "Painter.hpp"
#include "src/Styles.hpp" #include "Styles.hpp"
#include <cctype> #include <cctype>
#include <string> #include <string>
#include <locale> #include <locale>

View file

@ -202,9 +202,7 @@ void Widget::handle_relayout_subtree(RelayoutSubtreeEvent &event) {
m_window_relative = compute_window_relative(); m_window_relative = compute_window_relative();
if (m_layout) { if (!m_layout || !m_layout->run()) {
m_layout->run();
} else {
for (auto child : m_children) { for (auto child : m_children) {
child->dispatch_event(event); child->dispatch_event(event);
} }

View file

@ -23,8 +23,8 @@
int main() { int main() {
Raven::Application application {}; Raven::Application application {};
auto window = application.add_window(); auto window = application.add_window<Raven::Window>();
auto test_window = application.add_window(); auto test_window = application.add_window<Raven::Window>();
window->spawn_window(); window->spawn_window();
test_window->spawn_window(); test_window->spawn_window();