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)
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 {
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,
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;
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);
}
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);