From 8221fd5451f094defa9866f98026b74a969f7693 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 8 Mar 2021 14:46:19 -0500 Subject: resizable widgets, default widget implementation for some functions, reimplementing meminfo in raleigh --- src/user/include/cxx/raleigh/w/button.h | 4 +--- src/user/include/cxx/raleigh/w/label.h | 12 +++++------- src/user/include/cxx/raleigh/w/padding.h | 4 +--- src/user/include/cxx/raleigh/w/vbox.h | 4 +--- src/user/include/cxx/raleigh/widget.h | 28 +++++++++++++++++++--------- src/user/include/cxx/raleigh/window.h | 6 ++++++ src/user/include/cxx/structs/duple.h | 13 +++++++++++++ 7 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 src/user/include/cxx/structs/duple.h (limited to 'src/user/include/cxx') diff --git a/src/user/include/cxx/raleigh/w/button.h b/src/user/include/cxx/raleigh/w/button.h index 03e17ab..71ccae2 100644 --- a/src/user/include/cxx/raleigh/w/button.h +++ b/src/user/include/cxx/raleigh/w/button.h @@ -12,10 +12,8 @@ namespace raleigh { void notify_window_change() override; void paint(_pixel_t *pixbuf, uint32_t pitch) override; void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override; + void notify_child_size_change(widget &child, coord old_size) override; void notify_has_opaque_parent(widget *parent) override; - void handle_key(struct key_packet kp) override; - void on_focus() override; - void on_unfocus() override; private: widget &inner; void (*on_click)(button &); diff --git a/src/user/include/cxx/raleigh/w/label.h b/src/user/include/cxx/raleigh/w/label.h index 4b1dae2..a78ce46 100644 --- a/src/user/include/cxx/raleigh/w/label.h +++ b/src/user/include/cxx/raleigh/w/label.h @@ -7,19 +7,17 @@ namespace raleigh { class label : public widget { public: - //this pointer is used directly, and the contents of the string should not be changed afterward + //value's data is copied label(const char *value, const char *font="fixed-10", bool bg_transparent=true, _pixel_t fg=RGB(00, 00, 00), _pixel_t bg=RGB(bf, bf, bf)); - void notify_window_change() override; + void change_value(const char *new_value); + void paint(_pixel_t *pixbuf, uint32_t pitch) override; - void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override; void notify_has_opaque_parent(widget *parent) override; - void handle_key(struct key_packet kp) override; - void on_focus() override; - void on_unfocus() override; private: - const char *const value; + char *value; + uint32_t v_size; const struct font_info *const fi; bool bg_transparent; const _pixel_t fg; diff --git a/src/user/include/cxx/raleigh/w/padding.h b/src/user/include/cxx/raleigh/w/padding.h index 792e204..1bdb9ee 100644 --- a/src/user/include/cxx/raleigh/w/padding.h +++ b/src/user/include/cxx/raleigh/w/padding.h @@ -12,9 +12,7 @@ namespace raleigh { void paint(_pixel_t *pixbuf, uint32_t pitch) override; void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override; void notify_has_opaque_parent(widget *parent) override; - void handle_key(struct key_packet kp) override; - void on_focus() override; - void on_unfocus() override; + void notify_child_size_change(widget &child, coord old_size) override; private: widget &inner; uint32_t pad_by; diff --git a/src/user/include/cxx/raleigh/w/vbox.h b/src/user/include/cxx/raleigh/w/vbox.h index 02bffd3..f715f95 100644 --- a/src/user/include/cxx/raleigh/w/vbox.h +++ b/src/user/include/cxx/raleigh/w/vbox.h @@ -14,9 +14,7 @@ namespace raleigh { void paint(_pixel_t *pixbuf, uint32_t pitch) override; void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override; void notify_has_opaque_parent(widget *parent) override; - void handle_key(struct key_packet kp) override; - void on_focus() override; - void on_unfocus() override; + void notify_child_size_change(widget &from, coord old_size) override; private: dllist widgets; }; diff --git a/src/user/include/cxx/raleigh/widget.h b/src/user/include/cxx/raleigh/widget.h index 54b9287..1b2cf6f 100644 --- a/src/user/include/cxx/raleigh/widget.h +++ b/src/user/include/cxx/raleigh/widget.h @@ -12,12 +12,15 @@ namespace raleigh { namespace raleigh { class widget { public: - coord size; - - //set by window class (or parent widget) + //these three are set by window class (or parent widget) + widget *parent;//set to zero when root widget window *w; coord window_offset; + //derived classes should not set this outside of the initializer + //instead, they should call widget::set_size(coord) + coord size; + //fewest steps up that a widget can be redrawn without needing its parents //if a widget is opaque, it will set this to a pointer to itself, and then call // notify_has_opaque_parent on any children, passing itself as an argument. @@ -25,14 +28,21 @@ namespace raleigh { // and then call notify_has_opaque_parent on any children (with the opaque parent). widget *closest_opaque; - //called by window class (or parent widget) - virtual void notify_window_change() = 0; + //these are called by window class (or parent widgets) + virtual void notify_window_change(); virtual void paint(_pixel_t *pixbuf, uint32_t pitch) = 0; - virtual void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) = 0; + virtual void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up); virtual void notify_has_opaque_parent(widget *parent) = 0; - virtual void handle_key(struct key_packet kp) = 0; - virtual void on_focus() = 0; - virtual void on_unfocus() = 0; + virtual void handle_key(struct key_packet kp); + virtual void on_focus(); + virtual void on_unfocus(); + //this next one is not to be called by child widgets + //they should call window::notify_widget_size_change(widget &), which will call this if necessary + virtual void notify_child_size_change(widget &child, coord old_size); + + protected: + widget(); + void set_size(coord to); }; } diff --git a/src/user/include/cxx/raleigh/window.h b/src/user/include/cxx/raleigh/window.h index 21ae511..0dd9341 100644 --- a/src/user/include/cxx/raleigh/window.h +++ b/src/user/include/cxx/raleigh/window.h @@ -7,6 +7,8 @@ namespace raleigh { #include #include +#include +#include #include #include @@ -16,7 +18,10 @@ namespace raleigh { public: //pass on_close to specify a close handler. if on_close returns false, the window will not be closed. window(widget &root, _pixel_t bg_color=RGB(bf, bf, bf), bool (*on_close)(window &)=0); + void add_keybind(struct key_packet kp, void (*handler)(window &)); + void notify_needs_paint(widget &from); + void notify_widget_size_change(widget &from, coord old_size); enum try_actions_return_t {NONE, GOOD, DELETE}; try_actions_return_t try_actions(); void show(); @@ -31,6 +36,7 @@ namespace raleigh { bool needs_repaint; void paint_full(); bool (*on_close)(window &); + dllist> keybinds; }; } diff --git a/src/user/include/cxx/structs/duple.h b/src/user/include/cxx/structs/duple.h new file mode 100644 index 0000000..874e4f6 --- /dev/null +++ b/src/user/include/cxx/structs/duple.h @@ -0,0 +1,13 @@ +#ifndef STRUCTS_DUPLE_H +#define STRUCTS_DUPLE_H + +template +class duple { +public: + duple(at a, bt b) + : a(a), b(b) {} + at a; + bt b; +}; + +#endif \ No newline at end of file -- cgit v1.2.3