Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
Arquivo: box.c Projeto: yusiwen/rofi
box * box_create ( widget *parent, const char *name, RofiOrientation type )
{
    box *b = g_malloc0 ( sizeof ( box ) );
    // Initialize widget.
    widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
    b->type                      = type;
    b->widget.draw               = box_draw;
    b->widget.free               = box_free;
    b->widget.resize             = box_resize;
    b->widget.update             = box_update;
    b->widget.find_mouse_target  = box_find_mouse_target;
    b->widget.get_desired_height = box_get_desired_height;
    b->widget.get_desired_width  = box_get_desired_width;

    b->type = rofi_theme_get_orientation ( WIDGET ( b ), "orientation", b->type );

    b->spacing = rofi_theme_get_distance ( WIDGET ( b ), "spacing", DEFAULT_SPACING );
    return b;
}
Exemplo n.º 3
0
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;
}