Fix more sizing issues

This commit is contained in:
Dave Davenport 2016-12-30 19:59:45 +01:00
parent eafd4697a2
commit 2bfbb464e6
6 changed files with 57 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 );
}

View File

@ -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;
}