wlt: toolkit: implement proper minimal sizes
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 30 Sep 2012 22:16:57 +0000 (00:16 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 30 Sep 2012 22:16:57 +0000 (00:16 +0200)
A widget may have different constraints regarding minimal sizes and the
size it occupies. Therefore, we need to pass a hint with the minimal size
together with the prepare-resize round.

The catch-all user can then decide to resize the catch-all field until it
is big enough to hold all minimal-sizes.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/wlt_terminal.c
src/wlt_theme.c
src/wlt_toolkit.c
src/wlt_toolkit.h

index 8493ff5..8d38e81 100644 (file)
@@ -201,6 +201,8 @@ static void widget_resize(struct wlt_widget *widget, struct wlt_rect *alloc,
 
 static void widget_prepare_resize(struct wlt_widget *widget,
                                  unsigned int width, unsigned int height,
+                                 unsigned int *min_width,
+                                 unsigned int *min_height,
                                  unsigned int *new_width,
                                  unsigned int *new_height,
                                  void *data)
@@ -218,6 +220,15 @@ static void widget_prepare_resize(struct wlt_widget *widget,
                w *= term->font_normal->attr.width;
                *new_width += w;
        }
+
+       if (*new_width < *min_width) {
+               w = *min_width - *new_width;
+               w /= term->font_normal->attr.width;
+               w += 1;
+               w *= term->font_normal->attr.width;
+               *new_width += w;
+       }
+
        if (*new_height >= height) {
                *new_height += term->font_normal->attr.height;
        } else {
@@ -228,6 +239,14 @@ static void widget_prepare_resize(struct wlt_widget *widget,
                h *= term->font_normal->attr.height;
                *new_height += h;
        }
+
+       if (*new_height < *min_height) {
+               h = *min_height - *new_height;
+               h /= term->font_normal->attr.height;
+               h += 1;
+               h *= term->font_normal->attr.height;
+               *new_height += h;
+       }
 }
 
 static void widget_key(struct wlt_widget *widget, unsigned int mask,
index c7d7b64..b32624d 100644 (file)
@@ -253,24 +253,28 @@ static void widget_redraw(struct wlt_widget *widget, void *data)
 
 static void widget_prepare_resize(struct wlt_widget *widget,
                                  unsigned int width, unsigned int height,
+                                 unsigned int *min_width,
+                                 unsigned int *min_height,
                                  unsigned int *new_width,
                                  unsigned int *new_height,
                                  void *data)
 {
        struct wlt_theme *theme = data;
-       unsigned int minw, minh, tw, th;
-
-       minw = theme->frame_width * 2;
-       minh = theme->control_height + theme->frame_width * 2;
-
-       tw = 2 * theme->button_margin + 2 * theme->button_padding +
-            3 * theme->button_size;
-       th = theme->button_size + 2 * theme->button_padding;
-
-       if (minw < tw)
-               minw = tw;
-       if (minh < th)
-               minh = th;
+       unsigned int minw, minh;
+
+       /* set minimal size */
+       minw = 2 * theme->button_margin + 2 * theme->button_padding +
+              3 * theme->button_size + *new_width;
+       minh = theme->button_size + 2 * theme->button_padding +
+              2 * theme->frame_width + *new_height;
+       if (*min_width < minw)
+               *min_width = minw;
+       if (*min_height < minh)
+               *min_height = minh;
+
+       /* set margin size */
+       minw = 2 * theme->frame_width;
+       minh = theme->control_height + 2 * theme->frame_width;
 
        *new_width += minw;
        *new_height += minh;
index bbc8591..37b07b0 100644 (file)
@@ -1036,17 +1036,20 @@ static int resize_window(struct wlt_window *wnd, unsigned int width,
        struct wlt_pool *old_pool = NULL;
        size_t nsize;
        int ret;
-       unsigned int oldw, oldh, neww, newh;
+       unsigned int oldw, oldh, neww, newh, minw, minh;
 
        if (!wnd || !width || !height)
                return -EINVAL;
 
        neww = 0;
        newh = 0;
+       minw = 0;
+       minh = 0;
        shl_dlist_for_each(iter, &wnd->widget_list) {
                widget = shl_dlist_entry(iter, struct wlt_widget, list);
                if (widget->prepare_resize_cb)
                        widget->prepare_resize_cb(widget, width, height,
+                                                 &minw, &minh,
                                                  &neww, &newh,
                                                  widget->data);
        }
index fce4921..f1ea93d 100644 (file)
@@ -84,6 +84,8 @@ typedef void (*wlt_widget_destroy_cb) (struct wlt_widget *widget,
 typedef void (*wlt_widget_prepare_resize_cb) (struct wlt_widget *widget,
                                              unsigned int width,
                                              unsigned int height,
+                                             unsigned int *min_width,
+                                             unsigned int *min_height,
                                              unsigned int *new_width,
                                              unsigned int *new_height,
                                              void *data);