tidy: rename current_geometry
to rect
and tidy includes
This commit is contained in:
parent
305279c0f7
commit
9ee4acfba5
10 changed files with 51 additions and 51 deletions
|
@ -28,7 +28,7 @@ void Button::on_paint() {
|
||||||
|
|
||||||
painter.source_rgb(style()->foreground());
|
painter.source_rgb(style()->foreground());
|
||||||
painter.set_pango_font_description(style()->font_description());
|
painter.set_pango_font_description(style()->font_description());
|
||||||
painter.text(current_geometry(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, true);
|
painter.text(rect(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, true);
|
||||||
painter.fill();
|
painter.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,21 +17,21 @@ void DocumentLayout::run() {
|
||||||
if (child->absolute())
|
if (child->absolute())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (child->current_geometry().height() > largest_height_so_far) {
|
if (child->rect().height() > largest_height_so_far) {
|
||||||
largest_height_so_far = child->current_geometry().height();
|
largest_height_so_far = child->rect().height();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow && largest_height_so_far);
|
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->current_geometry().width() + m_margin) >= m_target->current_geometry().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) {
|
||||||
current_position.add(0, largest_height_so_far + m_margin);
|
current_position.add(0, largest_height_so_far + m_margin);
|
||||||
current_position.set_x(m_margin);
|
current_position.set_x(m_margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
child->current_geometry().set_x(current_position.x());
|
child->rect().set_x(current_position.x());
|
||||||
child->current_geometry().set_y(current_position.y());
|
child->rect().set_y(current_position.y());
|
||||||
current_position.add(child->current_geometry().width() + m_margin, 0);
|
current_position.add(child->rect().width() + m_margin, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ void Label::on_paint() {
|
||||||
|
|
||||||
painter.source_rgb(style()->foreground());
|
painter.source_rgb(style()->foreground());
|
||||||
painter.set_pango_font_description(style()->font_description());
|
painter.set_pango_font_description(style()->font_description());
|
||||||
painter.text(current_geometry(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, true);
|
painter.text(rect(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, true);
|
||||||
painter.fill();
|
painter.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Styles.hpp"
|
#include "Styles.hpp"
|
||||||
|
|
||||||
#include "pango/pango-font.h"
|
#include "pango/pango-font.h"
|
||||||
#include "src/RGB.hpp"
|
#include "RGB.hpp"
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "src/GenericStyle.hpp"
|
#include "GenericStyle.hpp"
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Raven {
|
||||||
Point Widget::window_relative() {
|
Point Widget::window_relative() {
|
||||||
Point point = { 0, 0 };
|
Point point = { 0, 0 };
|
||||||
for (Widget* parent = m_parent; parent; parent = parent->parent()) {
|
for (Widget* parent = m_parent; parent; parent = parent->parent()) {
|
||||||
point.add(parent->current_geometry().x(), parent->current_geometry().y());
|
point.add(parent->rect().x(), parent->rect().y());
|
||||||
}
|
}
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
@ -22,31 +22,31 @@ void Widget::fit_text(std::string &text) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window()->painter().set_pango_font_description(m_style->font_description());
|
window()->painter().set_pango_font_description(m_style->font_description());
|
||||||
auto size = window()->painter().compute_text_size(current_geometry(), text);
|
auto size = window()->painter().compute_text_size(rect(), text);
|
||||||
if (!resize(size)) {
|
if (!resize(size)) {
|
||||||
reflow();
|
reflow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::resize(double width, double height) {
|
bool Widget::resize(double width, double height) {
|
||||||
if (m_current_geometry.width() == width && m_current_geometry.height() == height)
|
if (m_rect.width() == width && m_rect.height() == height)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (width < 0 || height < 0)
|
if (width < 0 || height < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_current_geometry.set_width(width);
|
m_rect.set_width(width);
|
||||||
m_current_geometry.set_height(height);
|
m_rect.set_height(height);
|
||||||
reflow();
|
reflow();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::move_to(double x, double y) {
|
void Widget::move_to(double x, double y) {
|
||||||
if (m_current_geometry.x() == x && m_current_geometry.y() == y)
|
if (m_rect.x() == x && m_rect.y() == y)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_current_geometry.set_x(x);
|
m_rect.set_x(x);
|
||||||
m_current_geometry.set_y(y);
|
m_rect.set_y(y);
|
||||||
reflow();
|
reflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) {
|
||||||
if (!m_did_init || !painter.can_paint())
|
if (!m_did_init || !painter.can_paint())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!event.box().contains_box(current_geometry()))
|
if (!event.box().contains_box(m_rect))
|
||||||
return; // widgets contain their children, thus we don't need to recurse further
|
return; // widgets contain their children, thus we don't need to recurse further
|
||||||
|
|
||||||
// using a "group" in cairo reduces flickering
|
// using a "group" in cairo reduces flickering
|
||||||
|
@ -121,7 +121,7 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) {
|
||||||
cr->save();
|
cr->save();
|
||||||
|
|
||||||
// clip this widget. this ensures that the background fill or children won't overflow the bounds of it
|
// clip this widget. this ensures that the background fill or children won't overflow the bounds of it
|
||||||
painter.rounded_rectangle(m_current_geometry, m_style->border_radius());
|
painter.rounded_rectangle(m_rect, m_style->border_radius());
|
||||||
cr->clip();
|
cr->clip();
|
||||||
|
|
||||||
// paint the background fill
|
// paint the background fill
|
||||||
|
@ -145,12 +145,12 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) {
|
||||||
// translate to the widget's position
|
// translate to the widget's position
|
||||||
// the origin of the painter is now the widget's origin
|
// the origin of the painter is now the widget's origin
|
||||||
// this is because the position of children is relative to the origin of their parent
|
// this is because the position of children is relative to the origin of their parent
|
||||||
cr->translate(current_geometry().x(), current_geometry().y());
|
cr->translate(rect().x(), rect().y());
|
||||||
|
|
||||||
on_paint();
|
on_paint();
|
||||||
|
|
||||||
// convert the paint event's origin to our coordinate space because all positions of children are relative to the origin of their parent
|
// convert the paint event's origin to our coordinate space because all positions of children are relative to the origin of their parent
|
||||||
auto local_box = event.box().offset(-m_current_geometry.x(), -m_current_geometry.y());
|
auto local_box = event.box().offset(-m_rect.x(), -m_rect.y());
|
||||||
auto local_event = RepaintRectEvent(false, local_box);
|
auto local_event = RepaintRectEvent(false, local_box);
|
||||||
for (auto child : m_children) {
|
for (auto child : m_children) {
|
||||||
child->dispatch_event(local_event);
|
child->dispatch_event(local_event);
|
||||||
|
@ -171,7 +171,7 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
|
||||||
event.accept(); // we will do our own propagation logic
|
event.accept(); // we will do our own propagation logic
|
||||||
|
|
||||||
bool update_focus_to = true;
|
bool update_focus_to = true;
|
||||||
if (!m_current_geometry.contains_point(event.point())) {
|
if (!m_rect.contains_point(event.point())) {
|
||||||
// we just became unfocused
|
// we just became unfocused
|
||||||
update_focus_to = false;
|
update_focus_to = false;
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,8 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
|
||||||
if (!m_consumes_hits) {
|
if (!m_consumes_hits) {
|
||||||
// translate the event's point to our coordinate space because the position of all children is relative to the origin of their parent
|
// translate the event's point to our coordinate space because the position of all children is relative to the origin of their parent
|
||||||
auto local_event = MouseMoveEvent(Point(
|
auto local_event = MouseMoveEvent(Point(
|
||||||
event.point().x() - m_current_geometry.x(),
|
event.point().x() - m_rect.x(),
|
||||||
event.point().y() - m_current_geometry.y()
|
event.point().y() - m_rect.y()
|
||||||
));
|
));
|
||||||
for (auto child : m_children) {
|
for (auto child : m_children) {
|
||||||
child->dispatch_event(local_event);
|
child->dispatch_event(local_event);
|
||||||
|
@ -208,7 +208,7 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
|
||||||
|
|
||||||
bool update_activation_to = event.was_left_button_pressed();
|
bool update_activation_to = event.was_left_button_pressed();
|
||||||
|
|
||||||
if (!m_current_geometry.contains_point(event.point())) {
|
if (!m_rect.contains_point(event.point())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,8 +230,8 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
|
||||||
if (!m_consumes_hits) {
|
if (!m_consumes_hits) {
|
||||||
// translate the event's point to our coordinate space because the position of all children is relative to the origin of their parent
|
// translate the event's point to our coordinate space because the position of all children is relative to the origin of their parent
|
||||||
auto local_event = MouseButtonEvent(event.was_left_button_pressed(), event.was_right_button_pressed(), Point(
|
auto local_event = MouseButtonEvent(event.was_left_button_pressed(), event.was_right_button_pressed(), Point(
|
||||||
event.point().x() - m_current_geometry.x(),
|
event.point().x() - m_rect.x(),
|
||||||
event.point().y() - m_current_geometry.y()
|
event.point().y() - m_rect.y()
|
||||||
));
|
));
|
||||||
for (auto child : m_children) {
|
for (auto child : m_children) {
|
||||||
child->dispatch_event(local_event);
|
child->dispatch_event(local_event);
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#include "Events.hpp"
|
#include "Events.hpp"
|
||||||
#include "Forward.hpp"
|
#include "Forward.hpp"
|
||||||
#include "RGB.hpp"
|
#include "RGB.hpp"
|
||||||
#include "src/GenericStyle.hpp"
|
#include "GenericStyle.hpp"
|
||||||
#include "src/Styles.hpp"
|
#include "Styles.hpp"
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public:
|
||||||
bool add_child(std::shared_ptr<Widget> child);
|
bool add_child(std::shared_ptr<Widget> child);
|
||||||
void remove_child(std::shared_ptr<Widget> child);
|
void remove_child(std::shared_ptr<Widget> child);
|
||||||
|
|
||||||
Box ¤t_geometry() { return m_current_geometry; }
|
Box &rect() { return m_rect; }
|
||||||
void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; reflow(); }
|
void set_rect(Box rect) { m_rect = rect; reflow(); }
|
||||||
void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { reflow(); } }
|
void set_rect(Box rect, bool is_pure) { m_rect = rect; if (!is_pure) { reflow(); } }
|
||||||
|
|
||||||
Point window_relative();
|
Point window_relative();
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ private:
|
||||||
void handle_mouse_move_event(MouseMoveEvent &event);
|
void handle_mouse_move_event(MouseMoveEvent &event);
|
||||||
void handle_mouse_button_event(MouseButtonEvent &event);
|
void handle_mouse_button_event(MouseButtonEvent &event);
|
||||||
|
|
||||||
Box m_current_geometry { 0, 0, 0, 0 };
|
Box m_rect { 0, 0, 0, 0 };
|
||||||
std::vector<std::shared_ptr<Widget>> m_children;
|
std::vector<std::shared_ptr<Widget>> m_children;
|
||||||
Widget *m_parent { nullptr };
|
Widget *m_parent { nullptr };
|
||||||
Window *m_window { nullptr };
|
Window *m_window { nullptr };
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Raven {
|
||||||
void Window::set_main_widget(std::shared_ptr<Widget> main_widget) {
|
void Window::set_main_widget(std::shared_ptr<Widget> main_widget) {
|
||||||
m_main_widget = main_widget;
|
m_main_widget = main_widget;
|
||||||
m_main_widget->set_window(this);
|
m_main_widget->set_window(this);
|
||||||
m_main_widget->set_current_geometry(m_current_geometry);
|
m_main_widget->set_rect(m_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::spawn_window() {
|
bool Window::spawn_window() {
|
||||||
|
@ -33,8 +33,8 @@ bool Window::spawn_window() {
|
||||||
DefaultRootWindow(dsp),
|
DefaultRootWindow(dsp),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
m_current_geometry.width(),
|
m_rect.width(),
|
||||||
m_current_geometry.height(),
|
m_rect.height(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
CopyFromParent,
|
CopyFromParent,
|
||||||
|
@ -50,8 +50,8 @@ bool Window::spawn_window() {
|
||||||
dsp,
|
dsp,
|
||||||
da,
|
da,
|
||||||
DefaultVisual(dsp, screen),
|
DefaultVisual(dsp, screen),
|
||||||
current_geometry().width(),
|
rect().width(),
|
||||||
current_geometry().height()
|
rect().height()
|
||||||
);
|
);
|
||||||
auto cairo_context = Cairo::Context::create(m_xlib_surface);
|
auto cairo_context = Cairo::Context::create(m_xlib_surface);
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ void Window::repaint(Box geometry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::repaint(Widget *target) {
|
void Window::repaint(Widget *target) {
|
||||||
repaint(target->current_geometry().offset(target->window_relative().x(), target->window_relative().y()));
|
repaint(target->rect().offset(target->window_relative().x(), target->window_relative().y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::repaint() {
|
void Window::repaint() {
|
||||||
repaint(m_current_geometry);
|
repaint(m_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::relayout(Widget *target) {
|
void Window::relayout(Widget *target) {
|
||||||
|
@ -148,14 +148,14 @@ void Window::run(bool block) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ConfigureNotify: {
|
case ConfigureNotify: {
|
||||||
if (e.xconfigure.width != m_current_geometry.width() || e.xconfigure.height != m_current_geometry.height()) {
|
if (e.xconfigure.width != m_rect.width() || e.xconfigure.height != m_rect.height()) {
|
||||||
m_xlib_surface->set_size(e.xconfigure.width, e.xconfigure.height);
|
m_xlib_surface->set_size(e.xconfigure.width, e.xconfigure.height);
|
||||||
m_current_geometry.set_width(e.xconfigure.width);
|
m_rect.set_width(e.xconfigure.width);
|
||||||
m_current_geometry.set_height(e.xconfigure.height);
|
m_rect.set_height(e.xconfigure.height);
|
||||||
// if we have a main widget, we are going to have to resize it as well
|
// if we have a main widget, we are going to have to resize it as well
|
||||||
if (m_main_widget) {
|
if (m_main_widget) {
|
||||||
m_main_widget->current_geometry().set_width(m_current_geometry.width());
|
m_main_widget->rect().set_width(m_rect.width());
|
||||||
m_main_widget->current_geometry().set_height(m_current_geometry.height());
|
m_main_widget->rect().set_height(m_rect.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include "Widget.hpp"
|
#include "Widget.hpp"
|
||||||
#include "Painter.hpp"
|
#include "Painter.hpp"
|
||||||
#include "src/Events.hpp"
|
#include "Events.hpp"
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <cairomm/xlib_surface.h>
|
#include <cairomm/xlib_surface.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -41,7 +41,7 @@ public:
|
||||||
void relayout();
|
void relayout();
|
||||||
void reflow();
|
void reflow();
|
||||||
|
|
||||||
Box ¤t_geometry() { return m_current_geometry; }
|
Box &rect() { return m_rect; }
|
||||||
|
|
||||||
template<typename T, class... Args>
|
template<typename T, class... Args>
|
||||||
std::shared_ptr<T> set_main_widget(Args&&... args) {
|
std::shared_ptr<T> set_main_widget(Args&&... args) {
|
||||||
|
@ -53,7 +53,7 @@ private:
|
||||||
Widget *m_focused_widget { nullptr };
|
Widget *m_focused_widget { nullptr };
|
||||||
Widget *m_active_widget { nullptr };
|
Widget *m_active_widget { nullptr };
|
||||||
std::shared_ptr<Widget> m_main_widget { nullptr };
|
std::shared_ptr<Widget> m_main_widget { nullptr };
|
||||||
Box m_current_geometry { 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 };
|
||||||
bool m_is_batching { true };
|
bool m_is_batching { true };
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include "Label.hpp"
|
#include "Label.hpp"
|
||||||
#include "Layout.hpp"
|
#include "Layout.hpp"
|
||||||
#include "RGB.hpp"
|
#include "RGB.hpp"
|
||||||
#include "src/DocumentLayout.hpp"
|
#include "DocumentLayout.hpp"
|
||||||
#include "src/Events.hpp"
|
#include "Events.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
Loading…
Reference in a new issue