diff --git a/src/Button.hpp b/src/Button.hpp index 1063524..13634be 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -10,17 +10,15 @@ namespace Raven { class Button : public Widget { -private: - std::string m_text; public: Button(std::string text) : Widget(WidgetType::Button) , m_text(text) {} + std::function on_click { [](){} }; + void set_text(std::string text); std::string &text() { return m_text; } - - std::function on_click { [](){} }; protected: void on_paint(); void on_init(); @@ -29,6 +27,8 @@ protected: private: void update_color(); void recompute_text_size(); + + std::string m_text; }; } diff --git a/src/Label.cpp b/src/Label.cpp index d336837..c6d6fa1 100644 --- a/src/Label.cpp +++ b/src/Label.cpp @@ -12,7 +12,6 @@ void Label::set_text(std::string text) { fit_text(text); } } - void Label::on_init() { fit_text(m_text); diff --git a/src/Label.hpp b/src/Label.hpp index c2486d7..7697956 100644 --- a/src/Label.hpp +++ b/src/Label.hpp @@ -6,8 +6,6 @@ namespace Raven { class Label : public Widget { -private: - std::string m_text; public: Label(std::string text) : Widget(WidgetType::Label) @@ -15,11 +13,13 @@ public: ~Label() {} - std::string &text() { return m_text; } void set_text(std::string text); + std::string &text() { return m_text; } protected: void on_paint(); void on_init(); +private: + std::string m_text; }; } diff --git a/src/Widget.hpp b/src/Widget.hpp index e0d7c83..111ebc6 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -27,26 +27,10 @@ enum class ControlWidgetType { }; class Widget { - DEF_WIDGET_STYLE_PROP(do_background_fill, bool, false) DEF_WIDGET_STYLE_PROP(background_fill_color, RGB, 0, 0, 0) DEF_WIDGET_STYLE_PROP(background_border_radius, double, 0.0) - -private: - Box m_current_geometry { 0, 0, 0, 0 }; - std::vector> m_children; - Widget *m_parent { nullptr }; - Window *m_window { nullptr }; - std::shared_ptr m_styles { nullptr }; - std::shared_ptr m_layout { nullptr }; - bool m_did_init { false }; - bool m_is_focused { false }; - bool m_is_active { false }; - bool m_consumes_hits { false }; - bool m_accepts_events { true }; - bool m_absolute { false }; - ControlWidgetType m_control_type { ControlWidgetType::Widget }; public: Widget() {} @@ -60,11 +44,9 @@ public: m_accepts_events = false; } - std::function on_event { [](Event&){} }; + virtual ~Widget() {}; - Box ¤t_geometry() { return m_current_geometry; } - void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; wants_full_relayout(); } - void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { wants_full_relayout(); } } + std::function on_event { [](Event&){} }; void fit_text(std::string &text); @@ -76,6 +58,14 @@ public: bool add_child(std::shared_ptr child); void remove_child(std::shared_ptr child); + Box ¤t_geometry() { return m_current_geometry; } + void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; wants_full_relayout(); } + void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { wants_full_relayout(); } } + + WidgetType type() { return m_type; } + ControlWidgetType control_type() { return m_control_type; } + + Widget *parent() { return m_parent; } void set_parent(Widget *parent) { m_parent = parent; } @@ -104,9 +94,6 @@ public: void set_layout(std::shared_ptr layout); std::shared_ptr layout() { return m_layout; } - WidgetType type() { return m_type; } - ControlWidgetType control_type() { return m_control_type; } - void dispatch_event(Event &event); void wants_repaint(); void wants_relayout(); @@ -124,8 +111,6 @@ public: add_child(child); return child; } - - virtual ~Widget() {}; protected: WidgetType m_type { WidgetType::Widget }; @@ -144,6 +129,20 @@ private: void handle_reflow(ReflowEvent& event); void handle_mouse_move_event(MouseMoveEvent &event); void handle_mouse_button_event(MouseButtonEvent &event); + + Box m_current_geometry { 0, 0, 0, 0 }; + std::vector> m_children; + Widget *m_parent { nullptr }; + Window *m_window { nullptr }; + std::shared_ptr m_styles { nullptr }; + std::shared_ptr m_layout { nullptr }; + bool m_did_init { false }; + bool m_is_focused { false }; + bool m_is_active { false }; + bool m_consumes_hits { false }; + bool m_accepts_events { true }; + bool m_absolute { false }; + ControlWidgetType m_control_type { ControlWidgetType::Widget }; }; } diff --git a/src/Window.hpp b/src/Window.hpp index 1e1ae00..ece35c5 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -11,22 +11,17 @@ namespace Raven { class Window { -private: - Widget *m_focused_widget { nullptr }; - Widget *m_active_widget { nullptr }; - std::shared_ptr m_main_widget { nullptr }; - Box m_current_geometry { 0, 0, 800, 600 }; - Painter m_painter {}; - std::shared_ptr m_top_level_styles = std::make_shared(this); - Cairo::RefPtr m_xlib_surface { nullptr }; - bool m_is_batching { true }; - bool m_did_relayout_during_batch { true }; - bool m_did_repaint_during_batch { false }; - Display *m_x_display { nullptr }; public: Window() {} + bool spawn_window(); + void run(bool block); + + void start_batch(); + void end_batch(); + + Painter &painter() { return m_painter; } Widget *focused_widget() { return m_focused_widget; } @@ -43,25 +38,31 @@ public: void widget_repaint(Widget *target); void widget_relayout(Widget *target); - bool dispatch_repaint_on_box(Box box); bool dispatch_full_repaint(); bool dispatch_full_relayout(); bool dispatch_to_main_widget(Event &event); Box ¤t_geometry() { return m_current_geometry; } - bool spawn_window(); - void run(bool block); - - void start_batch(); - void end_batch(); - template std::shared_ptr set_main_widget(Args&&... args) { std::shared_ptr widget = std::make_shared(std::forward(args)...); set_main_widget(widget); return widget; } +private: + Widget *m_focused_widget { nullptr }; + Widget *m_active_widget { nullptr }; + std::shared_ptr m_main_widget { nullptr }; + Box m_current_geometry { 0, 0, 800, 600 }; + Painter m_painter {}; + std::shared_ptr m_top_level_styles = std::make_shared(this); + Cairo::RefPtr m_xlib_surface { nullptr }; + bool m_is_batching { true }; + bool m_did_relayout_during_batch { true }; + bool m_did_repaint_during_batch { false }; + + Display *m_x_display { nullptr }; }; } diff --git a/src/main.cpp b/src/main.cpp index 7b5ebc2..4e6646f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,6 @@ int main() { auto main_widget = window.set_main_widget(); main_widget->set_layout(6.0); - // int number = 0; bool is_dragging = false; auto button = main_widget->add("hello");