tFix bug with resizing widget surfaces - ltk - Socket-based GUI for X11 (WIP)
HTML git clone git://lumidify.org/ltk.git (fast, but not encrypted)
HTML git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 185426535af1a1f3ba649607d5346f59fa687803
DIR parent e5bdbd74dfdd1a238bde307a3613b995021ffeda
HTML Author: lumidify <nobody@lumidify.org>
Date: Tue, 24 May 2022 17:49:11 +0200
Fix bug with resizing widget surfaces
Diffstat:
M src/box.c | 5 +++++
M src/graphics_xlib.c | 4 ++++
M src/grid.c | 6 ++++++
M src/menu.c | 2 +-
M src/surface_cache.c | 2 +-
M src/widget.c | 2 ++
M test.gui | 0
M test2.gui | 2 +-
8 files changed, 20 insertions(+), 3 deletions(-)
---
DIR diff --git a/src/box.c b/src/box.c
t@@ -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;
t@@ -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
DIR diff --git a/src/graphics_xlib.c b/src/graphics_xlib.c
t@@ -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;
DIR diff --git a/src/grid.c b/src/grid.c
t@@ -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 &&
t@@ -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 */
DIR diff --git a/src/menu.c b/src/menu.c
t@@ -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;
DIR diff --git a/src/surface_cache.c b/src/surface_cache.c
t@@ -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;
DIR diff --git a/src/widget.c b/src/widget.c
t@@ -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;
DIR diff --git a/test.gui b/test.gui
DIR diff --git a/test2.gui b/test2.gui
t@@ -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