wlt: toolkit: allow widgets to control new size

This changes the prepare-resize logic to allow widgets full control of the
new size. The initial size starts at 0 and each widget can increase it.
The last widget should be a catch-all that uses all size that is available
and computes a good new size based on the requirements that the previous
widgets provided.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann committed 2012-09-30 22:50:38 +02:00
1 parent 5347c62688
commit d69414297c
4 files changed
+45 -18

No files matched your search

+16 -1
View File
@@ -210,6 +210,20 @@ static void widget_resize(struct wlt_widget *widget, struct wlt_rect *alloc,
kmscon_pty_resize(term->pty, term->cols, term->rows);
}
static void widget_prepare_resize(struct wlt_widget *widget,
unsigned int width, unsigned int height,
unsigned int *new_width,
unsigned int *new_height,
void *data)
{
struct wlt_terminal *term = data;
if (*new_width < width)
*new_width = width;
if (*new_height < height)
*new_height = height;
}
static void widget_key(struct wlt_widget *widget, unsigned int mask,
uint32_t sym, uint32_t state, void *data)
{
@@ -326,7 +340,8 @@ int wlt_terminal_new(struct wlt_terminal **out, struct wlt_window *wnd)
wlt_widget_set_destroy_cb(term->widget, widget_destroy);
wlt_widget_set_redraw_cb(term->widget, widget_redraw);
wlt_widget_set_resize_cb(term->widget, NULL, widget_resize);
wlt_widget_set_resize_cb(term->widget, widget_prepare_resize,
widget_resize);
wlt_widget_set_keyboard_cb(term->widget, widget_key);
*out = term;
return 0;
+15 -13
View File
@@ -252,26 +252,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 width, unsigned int height,
unsigned int *new_width,
unsigned int *new_height,
void *data)
{
struct wlt_theme *theme = data;
unsigned int minw, minh;
unsigned int minw, minh, tw, th;
minw = theme->frame_width * 2;
minh = theme->control_height + theme->frame_width * 2;
if (*width < minw)
*width = minw;
if (*height < minh)
*height = minh;
minw = 2 * theme->button_margin + 2 * theme->button_padding +
3 * theme->button_size;
minh = theme->button_size + 2 * theme->button_padding;
if (*width < minw)
*width = minw;
if (*height < minh)
*height = minh;
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;
*new_width += minw;
*new_height += minh;
}
static void widget_resize(struct wlt_widget *widget, struct wlt_rect *alloc,
+10 -2
View File
@@ -1036,18 +1036,26 @@ 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;
unsigned int oldw, oldh, neww, newh;
if (!wnd || !width || !height)
return -EINVAL;
neww = 0;
newh = 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,
widget->prepare_resize_cb(widget, width, height,
&neww, &newh,
widget->data);
}
if (neww)
width = neww;
if (newh)
height = newh;
if (width == wnd->buffer.width &&
height == wnd->buffer.height)
return 0;
+4 -2
View File
@@ -82,8 +82,10 @@ typedef void (*wlt_widget_redraw_cb) (struct wlt_widget *widget,
typedef void (*wlt_widget_destroy_cb) (struct wlt_widget *widget,
void *data);
typedef void (*wlt_widget_prepare_resize_cb) (struct wlt_widget *widget,
unsigned int *width,
unsigned int *height,
unsigned int width,
unsigned int height,
unsigned int *new_width,
unsigned int *new_height,
void *data);
typedef void (*wlt_widget_resize_cb) (struct wlt_widget *widget,
struct wlt_rect *allocation,