ltk

Socket-based GUI for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

commit 185426535af1a1f3ba649607d5346f59fa687803
parent e5bdbd74dfdd1a238bde307a3613b995021ffeda
Author: lumidify <nobody@lumidify.org>
Date:   Tue, 24 May 2022 17:49:11 +0200

Fix bug with resizing widget surfaces

Diffstat:
Msrc/box.c | 5+++++
Msrc/graphics_xlib.c | 4++++
Msrc/grid.c | 6++++++
Msrc/menu.c | 2+-
Msrc/surface_cache.c | 2+-
Msrc/widget.c | 2++
Mtest.gui | 0
Mtest2.gui | 2+-
8 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/box.c b/src/box.c @@ -215,6 +215,9 @@ ltk_box_child_size_change(ltk_widget *self, ltk_widget *widget) { rect if it doesn't have sticky set? Of course, the resize function could also set all widgets even if they don't have any sticky settings, but there'd probably be some catch as well. */ + /* FIXME: the same comment as in grid.c applies */ + int orig_w = widget->rect.w; + int orig_h = widget->rect.h; widget->rect.w = widget->ideal_w; widget->rect.h = widget->ideal_h; int sc_w = box->sc->widget.rect.w; @@ -231,6 +234,8 @@ ltk_box_child_size_change(ltk_widget *self, ltk_widget *widget) { box->widget.parent->vtable->child_size_change(box->widget.parent, (ltk_widget *)box); else ltk_recalculate_box((ltk_widget *)box); + if (orig_w != widget->rect.w || orig_h != widget->rect.h) + ltk_widget_resize(widget); } static int diff --git a/src/graphics_xlib.c b/src/graphics_xlib.c @@ -38,6 +38,10 @@ struct ltk_surface { ltk_surface * ltk_surface_create(ltk_window *window, int w, int h) { ltk_surface *s = ltk_malloc(sizeof(ltk_surface)); + if (w <= 0) + w = 1; + if (h <= 0) + h = 1; s->w = w; s->h = h; s->window = window; diff --git a/src/grid.c b/src/grid.c @@ -290,6 +290,10 @@ static void ltk_grid_child_size_change(ltk_widget *self, ltk_widget *widget) { ltk_grid *grid = (ltk_grid *)self; short size_changed = 0; + /* FIXME: this is kind of hacky right now because a size_change needs to be + checked here as well so the surface (if needed) is resized */ + int orig_w = widget->rect.w; + int orig_h = widget->rect.h; widget->rect.w = widget->ideal_w; widget->rect.h = widget->ideal_h; if (grid->column_weights[widget->column] == 0 && @@ -308,6 +312,8 @@ ltk_grid_child_size_change(ltk_widget *self, ltk_widget *widget) { grid->widget.parent->vtable->child_size_change(grid->widget.parent, (ltk_widget *)grid); else ltk_recalculate_grid((ltk_widget *)grid); + if (widget->rect.w != orig_w || widget->rect.h != orig_h) + ltk_widget_resize(widget); } /* FIXME: Check if widget already exists at position */ diff --git a/src/menu.c b/src/menu.c @@ -996,7 +996,7 @@ recalc_menu_size(ltk_menu *menu) { menu->widget.ideal_w += text_w + t->text_pad * 2 + bw + t->pad; } } - if (!menu->widget.hidden && menu->widget.parent && menu->widget.parent->vtable->child_size_change) { + if (menu->widget.parent && menu->widget.parent->vtable->child_size_change) { menu->widget.parent->vtable->child_size_change(menu->widget.parent, (ltk_widget *)menu); } menu->widget.dirty = 1; diff --git a/src/surface_cache.c b/src/surface_cache.c @@ -77,7 +77,7 @@ ltk_surface_cache_create(ltk_window *window) { sc->named_keys[i].entries_alloc = 0; } sc->surfaces = NULL; - sc->surfaces_num = sc->surfaces_alloc = 0; + sc->surfaces_num = sc->surfaces_realnum = sc->surfaces_alloc = 0; sc->clock_pos = 0; sc->free_pixels = MAX_CACHE_PIXELS; return sc; diff --git a/src/widget.c b/src/widget.c @@ -85,6 +85,8 @@ ltk_fill_widget_defaults(ltk_widget *widget, const char *id, ltk_window *window, if (vtable->needs_surface) widget->surface_key = ltk_surface_cache_get_unnamed_key(window->surface_cache, w, h); + else + widget->surface_key = NULL; /* FIXME: possibly check that draw and destroy aren't NULL */ widget->vtable = vtable; diff --git a/test.gui b/test.gui diff --git a/test2.gui b/test2.gui @@ -22,4 +22,4 @@ menu submenu1 add-submenu entry5 "Submenu" submenu2 submenu submenu3 create menu submenu3 add-entry entrya3 "Submenu Entry" menu submenu2 add-submenu entrya2 "Submenu" submenu3 -grid grd1 add menu1 0 0 1 1 ew +grid grd1 add menu1 0 0 1 1 w