static int listview_get_desired_height ( widget *wid ) { listview *lv = (listview *) wid; if ( lv == NULL || lv->widget.enabled == FALSE ) { return 0; } int spacing = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL ); int h = lv->menu_lines; if ( !( lv->fixed_num_lines ) ) { if ( lv->dynamic ) { h = MIN ( lv->menu_lines, lv->req_elements ); } else { h = MIN ( lv->menu_lines, lv->max_displayed_lines ); } } if ( h == 0 ) { if ( lv->dynamic && !lv->fixed_num_lines ) { // Hide widget fully. return 0; } return widget_padding_get_padding_height ( WIDGET ( lv ) ); } int height = widget_padding_get_padding_height ( WIDGET ( lv ) ); height += h * ( lv->element_height + spacing ) - spacing; return height; }
static void listview_resize ( widget *wid, short w, short h ) { listview *lv = (listview *) wid; lv->widget.w = MAX ( 0, w ); lv->widget.h = MAX ( 0, h ); int height = lv->widget.h - widget_padding_get_padding_height ( WIDGET ( lv ) ); int spacing_vert = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL ); lv->max_rows = ( spacing_vert + height ) / ( lv->element_height + spacing_vert ); lv->max_elements = lv->max_rows * lv->menu_columns; if ( lv->scrollbar->widget.index == 0 ) { widget_move ( WIDGET ( lv->scrollbar ), widget_padding_get_left ( WIDGET ( lv ) ), widget_padding_get_top ( WIDGET ( lv ) ) ); } else { widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), widget_padding_get_top ( WIDGET ( lv ) ) ); } widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height ); listview_recompute_elements ( lv ); widget_queue_redraw ( wid ); }
static int box_get_desired_height ( widget *wid ) { box *b = (box *) wid; int spacing = distance_get_pixel ( b->spacing, b->type ); int height = 0; if ( b->type == ROFI_ORIENTATION_VERTICAL ) { int active_widgets = 0; 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 ); } if ( active_widgets > 0 ) { height += ( active_widgets - 1 ) * 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; }
void box_add ( box *box, widget *child, gboolean expand ) { if ( box == NULL ) { return; } // Make sure box is width/heigh enough. if ( box->type == ROFI_ORIENTATION_VERTICAL ) { int width = box->widget.w; width = MAX ( width, child->w + widget_padding_get_padding_width ( WIDGET ( box ) ) ); box->widget.w = width; } else { int height = box->widget.h; height = MAX ( height, child->h + widget_padding_get_padding_height ( WIDGET ( box ) ) ); box->widget.h = height; } child->expand = rofi_theme_get_boolean ( child, "expand", expand ); g_assert ( child->parent == WIDGET ( box ) ); box->children = g_list_append ( box->children, (void *) child ); widget_update ( WIDGET ( box ) ); }
scrollbar *scrollbar_create ( widget *parent, const char *name ) { scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) ); widget_init ( WIDGET ( sb ), parent, WIDGET_TYPE_SCROLLBAR, name ); sb->widget.x = 0; sb->widget.y = 0; sb->width = rofi_theme_get_distance ( WIDGET ( sb ), "handle-width", DEFAULT_SCROLLBAR_WIDTH ); int width = distance_get_pixel ( sb->width, ROFI_ORIENTATION_HORIZONTAL ); sb->widget.w = widget_padding_get_padding_width ( WIDGET ( sb ) ) + width; sb->widget.h = widget_padding_get_padding_height ( WIDGET ( sb ) ); sb->widget.draw = scrollbar_draw; sb->widget.free = scrollbar_free; sb->widget.trigger_action = scrollbar_trigger_action; sb->widget.motion_notify = scrollbar_motion_notify; sb->widget.get_desired_height = scrollbar_get_desired_height; sb->length = 10; sb->pos = 0; sb->pos_length = 4; return sb; }
static void vert_calculate_size ( box *b ) { int spacing = distance_get_pixel ( b->spacing, ROFI_ORIENTATION_VERTICAL ); int expanding_widgets = 0; int active_widgets = 0; int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) ); int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) ); for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { widget * child = (widget *) iter->data; if ( child->enabled && child->expand == FALSE ) { widget_resize ( child, rem_width, widget_get_desired_height ( child ) ); } } b->max_size = 0; 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 ) { expanding_widgets++; continue; } if ( child->h > 0 ) { b->max_size += child->h; } } if ( active_widgets > 0 ) { b->max_size += ( active_widgets - 1 ) * spacing; } if ( b->max_size > rem_height ) { b->max_size = rem_height; g_debug ( "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h ); return; } if ( active_widgets > 0 ) { int top = widget_padding_get_top ( WIDGET ( b ) ); double rem = rem_height - b->max_size; int index = 0; for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { widget * child = (widget *) iter->data; if ( child->enabled == FALSE ) { continue; } if ( child->expand == TRUE ) { // Re-calculate to avoid round issues leaving one pixel left. int expanding_widgets_size = ( rem ) / ( expanding_widgets - index ); 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++; } else { widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top ); top += widget_get_height ( child ); top += spacing; } } } b->max_size += widget_padding_get_padding_height ( WIDGET ( b ) ); }
int textbox_get_estimated_height ( const textbox *tb, int eh ) { int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics ); return ( eh * height ) / PANGO_SCALE + widget_padding_get_padding_height ( WIDGET ( tb ) ); }
int textbox_get_height ( const textbox *tb ) { return textbox_get_font_height ( tb ) + widget_padding_get_padding_height ( WIDGET ( tb ) ); }