diff options
Diffstat (limited to 'src/user/raleigh')
-rw-r--r-- | src/user/raleigh/w/button.cpp | 11 | ||||
-rw-r--r-- | src/user/raleigh/w/label.cpp | 27 | ||||
-rw-r--r-- | src/user/raleigh/w/padding.cpp | 7 | ||||
-rw-r--r-- | src/user/raleigh/w/vbox.cpp | 21 | ||||
-rw-r--r-- | src/user/raleigh/widget.cpp | 22 | ||||
-rw-r--r-- | src/user/raleigh/window.cpp | 31 |
6 files changed, 95 insertions, 24 deletions
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<widget &> widgets) : widgets(widgets) { uint32_t w = 0, h = 0; for (dllist<widget &>::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<widget &>::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 diff --git a/src/user/raleigh/widget.cpp b/src/user/raleigh/widget.cpp new file mode 100644 index 0000000..719cc06 --- /dev/null +++ b/src/user/raleigh/widget.cpp @@ -0,0 +1,22 @@ +#include <raleigh/widget.h> + +#include <knob/format.h> + +namespace raleigh { + widget::widget() + : parent(0) {} + + void widget::notify_window_change() {} + void widget::handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) {} + void widget::handle_key(struct key_packet kp) {} + void widget::on_focus() {} + void widget::on_unfocus() {} + void widget::notify_child_size_change(widget &child, coord old_size) {} + + void widget::set_size(coord new_size) { + coord old_size = size; + size = new_size; + if (w) + w->notify_widget_size_change(*this, old_size); + } +}
\ No newline at end of file diff --git a/src/user/raleigh/window.cpp b/src/user/raleigh/window.cpp index 052422e..5d1a3de 100644 --- a/src/user/raleigh/window.cpp +++ b/src/user/raleigh/window.cpp @@ -1,7 +1,6 @@ #include <raleigh/runtime.h> #include <raleigh/window.h> -#include <popups/info.h> -#include <knob/heap.h> +#include <knob/key.h> #include <knob/format.h> @@ -44,8 +43,16 @@ namespace raleigh { root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); else if (wa.action_type == wa.MOUSE_UP) root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); - else if (wa.action_type == wa.KEY_DOWN) + else if (wa.action_type == wa.KEY_DOWN) { + for (dllist<duple<struct key_packet, void (*)(window &)>>::node *n = keybinds.first; n; n = n->next) + if (match_side_agnostic(wa.as_key, n->d.a)) { + n->d.b(*this); + goto next_loop; + } focussed->handle_key(wa.as_key); + next_loop: + ; + } else if (wa.action_type == wa.FOCUS_ENTER) focussed->on_focus(); else if (wa.action_type == wa.FOCUS_LEAVE) @@ -83,4 +90,22 @@ namespace raleigh { focussed->on_focus(); } } + + void window::notify_widget_size_change(widget &from, coord old_size) { + if (from.parent) + from.parent->notify_child_size_change(from, old_size); + else { + size = root.size; + delete[] pixbuf; + pixbuf = new _pixel_t[size.x * size.y]; + if (!pixbuf) + show_error_and_quitf("Failed to allocate %u byte buffer while\nresizing window to %ux%u pixels.", size.x * size.y, size.x, size.y); + paint_full(); + _resize_window(handle, size.x, size.y, pixbuf); + } + } + + void window::add_keybind(struct key_packet kp, void (*handler)(window &)) { + keybinds.add_front(duple<struct key_packet, void (*)(window &)>(kp, handler)); + } }
\ No newline at end of file |