Compare commits

..

No commits in common. "e76e2b43a1c8f2749bb549073303f9650c750ff9" and "fc59ad6e105f2a6b7cdbd670baf305f128f0ea76" have entirely different histories.

14 changed files with 23 additions and 48 deletions

View file

@ -61,8 +61,7 @@ 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<typename T, class... Args> template<class... Args>
std::shared_ptr<T> add_window(Args&&... args) { std::shared_ptr<Window> add_window(Args&&... args) {
std::shared_ptr<T> child = std::make_shared<T>(std::forward<Args>(args)...); std::shared_ptr<Window> child = std::make_shared<Window>(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 "Events.hpp" #include "src/Events.hpp"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@ -25,11 +25,6 @@ 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);
@ -94,13 +89,8 @@ 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,7 +1,6 @@
#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 {
@ -10,20 +9,15 @@ 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();
} }
@ -33,7 +27,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);
desired_height += largest_height_so_far + m_margin; bound.add(0, largest_height_so_far + m_margin);
current_position.set_x(m_margin); current_position.set_x(m_margin);
} }
@ -45,17 +39,13 @@ 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 */
desired_height += largest_height_so_far; bound.add(0, largest_height_so_far);
m_target->rect().set_height(desired_height); m_target->rect().set_width(bound.x());
m_target->rect().set_height(bound.y());
return true; return false;
} }
} }

View file

@ -15,13 +15,10 @@ public:
: Layout() : Layout()
, m_margin(margin) {} , m_margin(margin) {}
bool run() override; bool run();
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,7 +16,6 @@ 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 "Events.hpp" #include "src/Events.hpp"
namespace Raven { namespace Raven {

View file

@ -12,7 +12,7 @@ public:
: Layout() : Layout()
, m_direction(direction) {} , m_direction(direction) {}
bool run() override; bool run();
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,8 +22,6 @@ 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 "Painter.hpp" #include "src/Painter.hpp"
namespace Raven { namespace Raven {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Widget.hpp" #include "src/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 "Styles.hpp" #include "src/Styles.hpp"
#include <cctype> #include <cctype>
#include <string> #include <string>
#include <locale> #include <locale>

View file

@ -202,7 +202,9 @@ void Widget::handle_relayout_subtree(RelayoutSubtreeEvent &event) {
m_window_relative = compute_window_relative(); m_window_relative = compute_window_relative();
if (!m_layout || !m_layout->run()) { if (m_layout) {
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<Raven::Window>(); auto window = application.add_window();
auto test_window = application.add_window<Raven::Window>(); auto test_window = application.add_window();
window->spawn_window(); window->spawn_window();
test_window->spawn_window(); test_window->spawn_window();