listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse ) { listview *lv = g_malloc0 ( sizeof ( listview ) ); gchar *box = g_strjoin ( ".", name, "box", NULL ); widget_init ( WIDGET ( lv ), box ); g_free ( box ); lv->listview_name = g_strdup ( name ); lv->widget.free = listview_free; lv->widget.resize = listview_resize; lv->widget.draw = listview_draw; lv->widget.clicked = listview_clicked; lv->widget.motion_notify = listview_motion_notify; lv->widget.get_desired_height = listview_get_desired_height; lv->widget.enabled = TRUE; lv->eh = eh; char *n = g_strjoin ( ".", lv->listview_name, "scrollbar", NULL ); lv->scrollbar = scrollbar_create ( n ); // Default position on right. lv->scrollbar->widget.index = rofi_theme_get_integer_exact ( WIDGET ( lv->scrollbar ), "index", 1 ); g_free ( n ); widget_set_clicked_handler ( WIDGET ( lv->scrollbar ), listview_scrollbar_clicked, lv ); lv->scrollbar->widget.parent = WIDGET ( lv ); // Calculate height of an element. // char *tb_name = g_strjoin ( ".", lv->listview_name, "element", NULL ); textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" ); lv->element_height = textbox_get_estimated_height ( tb, lv->eh ); g_free ( tb_name ); widget_free ( WIDGET ( tb ) ); lv->callback = cb; lv->udata = udata; // Some settings. lv->spacing = rofi_theme_get_distance ( WIDGET ( lv ), "spacing", DEFAULT_SPACING ); lv->menu_columns = rofi_theme_get_integer ( WIDGET ( lv ), "columns", config.menu_columns ); lv->fixed_num_lines = rofi_theme_get_boolean ( WIDGET ( lv ), "fixed-height", config.fixed_num_lines ); lv->dynamic = rofi_theme_get_boolean ( WIDGET ( lv ), "dynamic", TRUE ); lv->reverse = rofi_theme_get_boolean ( WIDGET ( lv ), "reverse", reverse ); listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( WIDGET ( lv ), "scrollbar", !config.hide_scrollbar ) ); lv->cycle = rofi_theme_get_boolean ( WIDGET ( lv ), "cycle", config.cycle ); return lv; }
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 ) ); }