diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-01-06 16:41:23 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-01-06 16:41:23 +0100 |
commit | af8a6541a2608c387c6df95b4e0bd57a1fade6e6 (patch) | |
tree | 4ccc8392d0968eb050d0a7fce02c902bc12730ca /source/widgets/box.c | |
parent | 50780346729d2e9f4feb2725824c8df173b0df5b (diff) |
Order entries in box based on index, allow theme to override.
Diffstat (limited to 'source/widgets/box.c')
-rw-r--r-- | source/widgets/box.c | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/source/widgets/box.c b/source/widgets/box.c index 7bd48537..ba1e4eab 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -122,7 +122,6 @@ static void vert_calculate_size ( box *b ) return; } if ( active_widgets > 0 ) { - int bottom = b->widget.h - widget_padding_get_bottom ( WIDGET( b ) ); int top = widget_padding_get_top ( WIDGET ( b ) ); double rem = rem_height - b->max_size; int index = 0; @@ -134,26 +133,12 @@ static void vert_calculate_size ( box *b ) if ( child->expand == TRUE ) { // Re-calculate to avoid round issues leaving one pixel left. int expanding_widgets_size = ( rem ) / ( expanding_widgets - index ); - if ( child->end ) { - bottom -= expanding_widgets_size; - widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), bottom ); - widget_resize ( child, rem_width, expanding_widgets_size ); - bottom -= spacing; - } - else { - widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top ); - top += expanding_widgets_size; - widget_resize ( child, rem_width, expanding_widgets_size ); - top += spacing; - } + widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top ); + top += expanding_widgets_size; + widget_resize ( child, rem_width, expanding_widgets_size ); + top += spacing; rem -= expanding_widgets_size; index++; - // b->max_size += widget_padding_get_padding_height ( child); - } - else if ( child->end ) { - bottom -= widget_get_height ( child ); - widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), bottom ); - bottom -= spacing; } else { widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top ); @@ -200,7 +185,6 @@ static void hori_calculate_size ( box *b ) return; } if ( active_widgets > 0 ) { - int right = b->widget.w-widget_padding_get_right ( WIDGET (b) ); int left = widget_padding_get_left ( WIDGET (b) ); double rem = rem_width - b->max_size; int index = 0; @@ -212,26 +196,12 @@ static void hori_calculate_size ( box *b ) if ( child->expand == TRUE ) { // Re-calculate to avoid round issues leaving one pixel left. int expanding_widgets_size = ( rem ) / ( expanding_widgets - index ); - if ( child->end ) { - right -= expanding_widgets_size; - widget_move ( child, right, widget_padding_get_top ( WIDGET ( b ) )); - widget_resize ( child, expanding_widgets_size, rem_height ); - right -= spacing; - } - else { - widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) ); - left += expanding_widgets_size; - widget_resize ( child, expanding_widgets_size, rem_height ); - left += spacing; - } + widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) ); + left += expanding_widgets_size; + widget_resize ( child, expanding_widgets_size, rem_height ); + left += spacing; rem -= expanding_widgets_size; index++; - // b->max_size += widget_padding_get_padding_width ( child); - } - else if ( child->end ) { - right -= widget_get_width ( child ); - widget_move ( child, right, widget_padding_get_top ( WIDGET ( b ) ) ); - right -= spacing; } else { widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) ); @@ -264,7 +234,15 @@ static void box_free ( widget *wid ) g_free ( b ); } -void box_add ( box *box, widget *child, gboolean expand, gboolean end ) +static int box_sort_children ( gconstpointer a, gconstpointer b ) +{ + widget *child_a = (widget*)a; + widget *child_b = (widget*)b; + + return child_a->index - child_b->index; +} + +void box_add ( box *box, widget *child, gboolean expand, int index ) { if ( box == NULL ) { return; @@ -280,9 +258,10 @@ void box_add ( box *box, widget *child, gboolean expand, gboolean end ) box->widget.h = height; } child->expand = rofi_theme_get_boolean ( child, "expand", expand); - child->end = rofi_theme_get_boolean ( child, "end", end); + child->index = rofi_theme_get_integer_exact ( child, "index" , index ); child->parent = WIDGET ( box ); box->children = g_list_append ( box->children, (void *) child ); + box->children = g_list_sort ( box->children, box_sort_children ); widget_update ( WIDGET ( box ) ); } |