clean up class header files

This commit is contained in:
hippoz 2022-05-15 10:54:30 +03:00
parent a01a3c1927
commit b781db009a
No known key found for this signature in database
GPG key ID: 7C52899193467641
6 changed files with 51 additions and 53 deletions

View file

@ -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<void()> on_click { [](){} };
void set_text(std::string text);
std::string &text() { return m_text; }
std::function<void()> 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;
};
}

View file

@ -12,7 +12,6 @@ void Label::set_text(std::string text) {
fit_text(text);
}
}
void Label::on_init() {
fit_text(m_text);

View file

@ -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;
};
}

View file

@ -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<std::shared_ptr<Widget>> m_children;
Widget *m_parent { nullptr };
Window *m_window { nullptr };
std::shared_ptr<TopLevelStyles> m_styles { nullptr };
std::shared_ptr<Layout> 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<void(Event&)> on_event { [](Event&){} };
virtual ~Widget() {};
Box &current_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<void(Event&)> on_event { [](Event&){} };
void fit_text(std::string &text);
@ -76,6 +58,14 @@ public:
bool add_child(std::shared_ptr<Widget> child);
void remove_child(std::shared_ptr<Widget> child);
Box &current_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> layout);
std::shared_ptr<Layout> 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<std::shared_ptr<Widget>> m_children;
Widget *m_parent { nullptr };
Window *m_window { nullptr };
std::shared_ptr<TopLevelStyles> m_styles { nullptr };
std::shared_ptr<Layout> 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 };
};
}

View file

@ -11,22 +11,17 @@
namespace Raven {
class Window {
private:
Widget *m_focused_widget { nullptr };
Widget *m_active_widget { nullptr };
std::shared_ptr<Widget> m_main_widget { nullptr };
Box m_current_geometry { 0, 0, 800, 600 };
Painter m_painter {};
std::shared_ptr<TopLevelStyles> m_top_level_styles = std::make_shared<TopLevelStyles>(this);
Cairo::RefPtr<Cairo::XlibSurface> 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 &current_geometry() { return m_current_geometry; }
bool spawn_window();
void run(bool block);
void start_batch();
void end_batch();
template<typename T, class... Args>
std::shared_ptr<T> set_main_widget(Args&&... args) {
std::shared_ptr<T> widget = std::make_shared<T>(std::forward<Args>(args)...);
set_main_widget(widget);
return widget;
}
private:
Widget *m_focused_widget { nullptr };
Widget *m_active_widget { nullptr };
std::shared_ptr<Widget> m_main_widget { nullptr };
Box m_current_geometry { 0, 0, 800, 600 };
Painter m_painter {};
std::shared_ptr<TopLevelStyles> m_top_level_styles = std::make_shared<TopLevelStyles>(this);
Cairo::RefPtr<Cairo::XlibSurface> 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 };
};
}

View file

@ -18,7 +18,6 @@ int main() {
auto main_widget = window.set_main_widget<Raven::Widget>();
main_widget->set_layout<Raven::DocumentLayout>(6.0);
// int number = 0;
bool is_dragging = false;
auto button = main_widget->add<Raven::Button>("hello");