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/label.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/user/raleigh/w/label.cpp') 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 -- cgit v1.2.3