summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-12-30 19:59:45 +0100
committerDave Davenport <qball@gmpclient.org>2016-12-30 19:59:45 +0100
commit2bfbb464e60736664de427c974a294ca42dd82ad (patch)
treeeaeff00b799d033f09f1bc60ee5825c7f3d1034a
parenteafd4697a28b54422a86a2fba686456b78e9486b (diff)
Fix more sizing issues
-rw-r--r--source/widgets/box.c37
-rw-r--r--source/widgets/scrollbar.c8
-rw-r--r--source/widgets/separator.c11
-rw-r--r--source/widgets/textbox.c10
-rw-r--r--source/widgets/widget.c4
-rw-r--r--source/widgets/window.c1
6 files changed, 57 insertions, 14 deletions
diff --git a/source/widgets/box.c b/source/widgets/box.c
index 13282fd4..a6d5187a 100644
--- a/source/widgets/box.c
+++ b/source/widgets/box.c
@@ -60,22 +60,33 @@ static int box_get_desired_height ( widget *wid )
{
box *b = (box *)wid;
int active_widgets = 0;
- int height = widget_padding_get_padding_height ( wid );
- for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
- widget * child = (widget *) iter->data;
- if ( !child->enabled ) {
- continue;
- }
- active_widgets++;
- if ( child->expand == TRUE ) {
+ int height = 0;
+ if ( b->type == BOX_VERTICAL ){
+ for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
+ widget * child = (widget *) iter->data;
+ if ( !child->enabled ) {
+ continue;
+ }
+ active_widgets++;
+ if ( child->expand == TRUE ) {
+ height += widget_get_desired_height ( child );
+ continue;
+ }
height += widget_get_desired_height ( child );
- continue;
}
- height += child->h;
- }
- if ( active_widgets > 0 ){
- height += (active_widgets - 1)*b->spacing;
+ if ( active_widgets > 0 ){
+ height += (active_widgets - 1)*b->spacing;
+ }
+ } else {
+ for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
+ widget * child = (widget *) iter->data;
+ if ( !child->enabled ) {
+ continue;
+ }
+ height = MAX ( widget_get_desired_height ( child ), height );
+ }
}
+ height += widget_padding_get_padding_height ( wid );
return height;
}
diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c
index d7cb0cf4..a4b859dc 100644
--- a/source/widgets/scrollbar.c
+++ b/source/widgets/scrollbar.c
@@ -35,6 +35,13 @@ static void scrollbar_draw ( widget *, cairo_t * );
static void scrollbar_free ( widget * );
static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
+
+static int scrollbar_get_desired_height ( widget *wid )
+{
+ // Want height we are.
+ return wid->h;
+}
+
scrollbar *scrollbar_create ( const char *name, int width )
{
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
@@ -47,6 +54,7 @@ scrollbar *scrollbar_create ( const char *name, int width )
sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free;
sb->widget.motion_notify = scrollbar_motion_notify;
+ sb->widget.get_desired_height = scrollbar_get_desired_height;
sb->length = 10;
sb->pos = 0;
diff --git a/source/widgets/separator.c b/source/widgets/separator.c
index d5307edd..b2324cf6 100644
--- a/source/widgets/separator.c
+++ b/source/widgets/separator.c
@@ -58,6 +58,7 @@ struct _separator
widget widget;
separator_type type;
separator_line_style line_style;
+ int separator_width;
};
/** Configuration value for separator style indicating no line */
@@ -67,11 +68,20 @@ const char *const _separator_style_dash = "dash";
static void separator_draw ( widget *, cairo_t * );
static void separator_free ( widget * );
+static int separator_get_desired_height ( widget *wid )
+{
+ separator *sb = (separator *)wid;
+ int height = sb->separator_width;
+ height += widget_padding_get_padding_height ( WIDGET (sb) );
+ return height;
+}
+
separator *separator_create ( const char *name, separator_type type, short sw )
{
separator *sb = g_malloc0 ( sizeof ( separator ) );
widget_init ( WIDGET (sb), name, SEPARATOR_CLASS_NAME );
sb->type = type;
+ sb->separator_width = sw;
sb->widget.x = 0;
sb->widget.y = 0;
if ( sb->type == S_HORIZONTAL ) {
@@ -85,6 +95,7 @@ separator *separator_create ( const char *name, separator_type type, short sw )
sb->widget.draw = separator_draw;
sb->widget.free = separator_free;
+ sb->widget.get_desired_height = separator_get_desired_height;
// Enabled by default
sb->widget.enabled = TRUE;
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 29b08cb4..87d90767 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -77,6 +77,15 @@ static void textbox_resize ( widget *wid, short w, short h )
textbox *tb = (textbox *) wid;
textbox_moveresize ( tb, tb->widget.x, tb->widget.y, w, h );
}
+static int textbox_get_desired_height ( widget *wid )
+{
+ textbox *tb = (textbox *)wid;
+ if ( tb->flags & TB_AUTOHEIGHT )
+ {
+ return tb->widget.h;
+ }
+ return textbox_get_height (tb);
+}
textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text )
{
@@ -89,6 +98,7 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
tb->widget.resize = textbox_resize;
tb->widget.get_width = textbox_get_width;
tb->widget.get_height = _textbox_get_height;
+ tb->widget.get_desired_height = textbox_get_desired_height;
tb->flags = flags;
tb->changed = FALSE;
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index 0fc03c09..f8adafc0 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -66,6 +66,7 @@ void widget_enable ( widget *widget )
if ( widget && !widget->enabled ) {
widget->enabled = TRUE;
widget_update ( widget );
+ widget_update ( widget->parent );
}
}
void widget_disable ( widget *widget )
@@ -73,6 +74,7 @@ void widget_disable ( widget *widget )
if ( widget && widget->enabled ) {
widget->enabled = FALSE;
widget_update ( widget );
+ widget_update ( widget->parent );
}
}
void widget_draw ( widget *widget, cairo_t *d )
@@ -269,7 +271,7 @@ int widget_padding_get_padding_width ( const widget *wid )
int widget_get_desired_height ( widget *wid )
{
- if ( wid->get_desired_height )
+ if ( wid && wid->get_desired_height )
{
return wid->get_desired_height ( wid );
}
diff --git a/source/widgets/window.c b/source/widgets/window.c
index 43683112..d73d23ea 100644
--- a/source/widgets/window.c
+++ b/source/widgets/window.c
@@ -60,6 +60,7 @@ static int window_get_desired_height ( widget *widget )
if ( b->child ) {
height += widget_get_desired_height ( b->child );
}
+ height += widget_padding_get_padding_height ( widget );
return height;
}