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/raleigh/w/button.cpp | 11 +++++------ src/user/raleigh/w/label.cpp | 27 ++++++++++++++++++--------- src/user/raleigh/w/padding.cpp | 7 ++++--- src/user/raleigh/w/vbox.cpp | 21 ++++++++++++++++++--- 4 files changed, 45 insertions(+), 21 deletions(-) (limited to 'src/user/raleigh/w') diff --git a/src/user/raleigh/w/button.cpp b/src/user/raleigh/w/button.cpp index a92167e..2abf9a9 100644 --- a/src/user/raleigh/w/button.cpp +++ b/src/user/raleigh/w/button.cpp @@ -8,6 +8,7 @@ namespace raleigh { size = coord(inner.size.x + 2, inner.size.y + 2); closest_opaque = this; inner.notify_has_opaque_parent(this); + inner.parent = this; } void button::notify_window_change() { @@ -49,11 +50,9 @@ namespace raleigh { } } - void button::notify_has_opaque_parent(widget *parent) {} - - void button::handle_key(struct key_packet kp) {} - - void button::on_focus() {} + void button::notify_child_size_change(widget &child, coord old_size) { + set_size(coord(inner.size.x + 2, inner.size.y + 2)); + } - void button::on_unfocus() {} + void button::notify_has_opaque_parent(widget *parent) {} } \ No newline at end of file diff --git a/src/user/raleigh/w/label.cpp b/src/user/raleigh/w/label.cpp index 046737f..21df2a2 100644 --- a/src/user/raleigh/w/label.cpp +++ b/src/user/raleigh/w/label.cpp @@ -4,12 +4,27 @@ namespace raleigh { label::label(const char *value, const char *font, bool bg_transparent, _pixel_t fg, _pixel_t bg) - : value(value), fi(get_font(font)), bg_transparent(bg_transparent), fg(fg), bg(bg) { - size = coord(fi->space_width * (strlen(value) - 1) + fi->char_width, fi->char_height); + : fi(get_font(font)), bg_transparent(bg_transparent), fg(fg), bg(bg) { + + v_size = strlen(value) + 1; + this->value = new char[v_size]; + blockcpy(this->value, value, v_size); + size = coord(fi->space_width * (v_size - 2) + fi->char_width, fi->char_height); + closest_opaque = 0; } - void label::notify_window_change() {} + void label::change_value(const char *new_value) { + delete[] value; + const uint32_t ns = strlen(new_value) + 1; + if (ns != v_size) { + v_size = ns; + value = new char[ns]; + set_size(coord(fi->space_width * (ns - 2) + fi->char_width, fi->char_height)); + } + blockcpy(value, new_value, ns); + w->notify_needs_paint(*this); + } void label::paint(_pixel_t *pixbuf, uint32_t pitch) { if (!bg_transparent) @@ -23,13 +38,7 @@ namespace raleigh { } } - void label::handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) { } - void label::notify_has_opaque_parent(widget *parent) { closest_opaque = parent; } - - void label::handle_key(struct key_packet kp) {}; - void label::on_focus() {}; - void label::on_unfocus() {}; } \ No newline at end of file diff --git a/src/user/raleigh/w/padding.cpp b/src/user/raleigh/w/padding.cpp index 87167c3..c1f7b85 100644 --- a/src/user/raleigh/w/padding.cpp +++ b/src/user/raleigh/w/padding.cpp @@ -5,6 +5,7 @@ namespace raleigh { : inner(inner), pad_by(pad_by) { size = coord(inner.size.x + pad_by * 2, inner.size.y + pad_by * 2); closest_opaque = 0; + inner.parent = this; } void padding::notify_window_change() { @@ -30,7 +31,7 @@ namespace raleigh { inner.notify_has_opaque_parent(parent); } - void padding::handle_key(struct key_packet kp) {}; - void padding::on_focus() {}; - void padding::on_unfocus() {}; + void padding::notify_child_size_change(widget &child, coord old_size) { + set_size(coord(inner.size.x + pad_by * 2, inner.size.y + pad_by * 2)); + } } \ No newline at end of file diff --git a/src/user/raleigh/w/vbox.cpp b/src/user/raleigh/w/vbox.cpp index 08c2539..263da2a 100644 --- a/src/user/raleigh/w/vbox.cpp +++ b/src/user/raleigh/w/vbox.cpp @@ -4,6 +4,7 @@ namespace raleigh { vbox::vbox(dllist widgets) : widgets(widgets) { uint32_t w = 0, h = 0; for (dllist::node *n = widgets.first; n; n = n->next) { + n->d.parent = this; h += n->d.size.y; if (n->d.size.x > w) w = n->d.size.x; @@ -45,7 +46,21 @@ namespace raleigh { n->d.notify_has_opaque_parent(parent); } - void vbox::handle_key(struct key_packet kp) {}; - void vbox::on_focus() {}; - void vbox::on_unfocus() {}; + void vbox::notify_child_size_change(widget &from, coord old_size) { + if ((old_size.y == from.size.y) && (from.size.x <= size.x)) { + from.window_offset.x = window_offset.x + size.x / 2 - from.size.x / 2; + from.notify_window_change(); + } + + else {//lazy, less efficient approach + uint32_t h = 0, w = 0; + for (dllist::node *n = widgets.first; n; n = n->next) { + h += n->d.size.y; + if (n->d.size.x > w) + w = n->d.size.x; + } + set_size(coord(w, h)); + notify_window_change(); + } + } } \ No newline at end of file -- cgit v1.2.3