1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Remove index from box_add.

This commit is contained in:
Dave Davenport 2017-06-02 16:53:39 +02:00
parent 1d622aa59c
commit 4bd9828aa7
6 changed files with 31 additions and 44 deletions

View file

@ -59,10 +59,9 @@ box * box_create ( const char *name, RofiOrientation type );
* @param box Handle to the box widget. * @param box Handle to the box widget.
* @param child Handle to the child widget to pack. * @param child Handle to the child widget to pack.
* @param expand If the child widget should expand and use all available space. * @param expand If the child widget should expand and use all available space.
* @param index The position index.
* *
* Add a widget to the box. * Add a widget to the box.
*/ */
void box_add ( box *box, widget *child, gboolean expand, int index ); void box_add ( box *box, widget *child, gboolean expand );
/*@}*/ /*@}*/
#endif // ROFI_HBOX_H #endif // ROFI_HBOX_H

View file

@ -58,8 +58,6 @@ struct _widget
gboolean enabled; gboolean enabled;
/** Expand the widget when packed */ /** Expand the widget when packed */
gboolean expand; gboolean expand;
/*** The packing index */
int index;
/** Place widget at end of parent */ /** Place widget at end of parent */
gboolean end; gboolean end;
/** Parent widget */ /** Parent widget */

View file

@ -1498,7 +1498,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
*/ */
if ( strcmp ( name, "mainbox") == 0 ){ if ( strcmp ( name, "mainbox") == 0 ){
wid = (widget *)box_create ( strbox, ROFI_ORIENTATION_VERTICAL ); wid = (widget *)box_create ( strbox, ROFI_ORIENTATION_VERTICAL );
box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE, 0 ); box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE );
defaults = "inputbar,message,listview"; defaults = "inputbar,message,listview";
} }
/** /**
@ -1508,7 +1508,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
wid = (widget *)box_create ( strbox, ROFI_ORIENTATION_HORIZONTAL ); wid = (widget *)box_create ( strbox, ROFI_ORIENTATION_HORIZONTAL );
defaults = "prompt,entry,case-indicator"; defaults = "prompt,entry,case-indicator";
box_add ( (box *)parent_widget, WIDGET ( wid ), FALSE, 0 ); box_add ( (box *)parent_widget, WIDGET ( wid ), FALSE );
} }
/** /**
* PROMPT * PROMPT
@ -1517,7 +1517,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
// Prompt box. // Prompt box.
state->prompt = textbox_create ( str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "" ); state->prompt = textbox_create ( str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "" );
rofi_view_update_prompt ( state ); rofi_view_update_prompt ( state );
box_add ( (box *)parent_widget, WIDGET ( state->prompt ), FALSE, 1 ); box_add ( (box *)parent_widget, WIDGET ( state->prompt ), FALSE );
defaults = NULL; defaults = NULL;
} }
/** /**
@ -1526,7 +1526,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
else if ( strcmp ( name, "case-indicator") == 0 ){ else if ( strcmp ( name, "case-indicator") == 0 ){
state->case_indicator = textbox_create ( str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*" ); state->case_indicator = textbox_create ( str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*" );
// Add small separator between case indicator and text box. // Add small separator between case indicator and text box.
box_add ( (box *)parent_widget, WIDGET ( state->case_indicator ), FALSE, 3 ); box_add ( (box *)parent_widget, WIDGET ( state->case_indicator ), FALSE );
textbox_text ( state->case_indicator, get_matching_state () ); textbox_text ( state->case_indicator, get_matching_state () );
} }
/** /**
@ -1537,7 +1537,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
TextboxFlags tfl = TB_EDITABLE; TextboxFlags tfl = TB_EDITABLE;
tfl |= ( ( state->menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0; tfl |= ( ( state->menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0;
state->text = textbox_create ( str, tfl | TB_AUTOHEIGHT, NORMAL, NULL); state->text = textbox_create ( str, tfl | TB_AUTOHEIGHT, NORMAL, NULL);
box_add ( (box*)parent_widget, WIDGET ( state->text ), TRUE, 2 ); box_add ( (box*)parent_widget, WIDGET ( state->text ), TRUE );
} }
/** /**
* MESSAGE * MESSAGE
@ -1548,7 +1548,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
state->mesg_tb = textbox_create ( strmsg, TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL ); state->mesg_tb = textbox_create ( strmsg, TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL );
container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) ); container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) );
rofi_view_reload_message_bar ( state ); rofi_view_reload_message_bar ( state );
box_add ( (box*)parent_widget, WIDGET ( state->mesg_box ), FALSE, 2 ); box_add ( (box*)parent_widget, WIDGET ( state->mesg_box ), FALSE );
g_free(strmsg); g_free(strmsg);
} }
/** /**
@ -1556,7 +1556,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
*/ */
else if ( strcmp ( name, "listview" ) == 0 ) { else if ( strcmp ( name, "listview" ) == 0 ) {
state->list_view = listview_create ( str, update_callback, state, config.element_height, 0); state->list_view = listview_create ( str, update_callback, state, config.element_height, 0);
box_add ( (box*)parent_widget, WIDGET ( state->list_view ), TRUE, 3 ); box_add ( (box*)parent_widget, WIDGET ( state->list_view ), TRUE );
// Set configuration // Set configuration
listview_set_multi_select ( state->list_view, ( state->menu_flags & MENU_INDICATOR ) == MENU_INDICATOR ); listview_set_multi_select ( state->list_view, ( state->menu_flags & MENU_INDICATOR ) == MENU_INDICATOR );
listview_set_scroll_type ( state->list_view, config.scroll_method ); listview_set_scroll_type ( state->list_view, config.scroll_method );
@ -1572,7 +1572,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
else if ( strcmp( name, "sidebar" ) == 0 ) { else if ( strcmp( name, "sidebar" ) == 0 ) {
if ( config.sidebar_mode ){ if ( config.sidebar_mode ){
state->sidebar_bar = box_create ( strbox, ROFI_ORIENTATION_HORIZONTAL ); state->sidebar_bar = box_create ( strbox, ROFI_ORIENTATION_HORIZONTAL );
box_add ( (box*)parent_widget, WIDGET ( state->sidebar_bar ), FALSE, 10 ); box_add ( (box*)parent_widget, WIDGET ( state->sidebar_bar ), FALSE );
state->num_modi = rofi_get_num_enabled_modi (); state->num_modi = rofi_get_num_enabled_modi ();
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) ); state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
char *strbutton= g_strjoin ( "." , str, "button",NULL ); char *strbutton= g_strjoin ( "." , str, "button",NULL );
@ -1580,17 +1580,17 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
const Mode * mode = rofi_get_mode ( j ); const Mode * mode = rofi_get_mode ( j );
state->modi[j] = textbox_create ( strbutton, TB_CENTER | TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL, state->modi[j] = textbox_create ( strbutton, TB_CENTER | TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
mode_get_display_name ( mode ) ); mode_get_display_name ( mode ) );
box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE, j ); box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE );
//widget_set_clicked_handler ( WIDGET ( state->modi[j] ), rofi_view_modi_clicked_cb, state ); //widget_set_clicked_handler ( WIDGET ( state->modi[j] ), rofi_view_modi_clicked_cb, state );
} }
g_free(strbutton); g_free(strbutton);
} }
} else if ( g_ascii_strncasecmp ( name, "textbox", 7) == 0 ){ } else if ( g_ascii_strncasecmp ( name, "textbox", 7) == 0 ){
textbox *t = textbox_create ( str, TB_WRAP, NORMAL, ""); textbox *t = textbox_create ( str, TB_WRAP, NORMAL, "");
box_add ( (box *)parent_widget, WIDGET(t), TRUE, 0); box_add ( (box *)parent_widget, WIDGET(t), TRUE);
} else { } else {
wid = box_create ( strbox, ROFI_ORIENTATION_VERTICAL ); wid = box_create ( strbox, ROFI_ORIENTATION_VERTICAL );
box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE, 0 ); box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE );
//g_error("The widget %s does not exists. Invalid layout.", name); //g_error("The widget %s does not exists. Invalid layout.", name);
} }
if ( wid ) { if ( wid ) {
@ -1685,10 +1685,10 @@ int rofi_view_error_dialog ( const char *msg, int markup )
state->main_window = box_create ( "window.box", ROFI_ORIENTATION_VERTICAL ); state->main_window = box_create ( "window.box", ROFI_ORIENTATION_VERTICAL );
box *box = box_create ( "window.mainbox.message.box", ROFI_ORIENTATION_VERTICAL ); box *box = box_create ( "window.mainbox.message.box", ROFI_ORIENTATION_VERTICAL );
box_add ( state->main_window, WIDGET ( box ), TRUE, 0 ); box_add ( state->main_window, WIDGET ( box ), TRUE );
state->text = textbox_create ( "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), state->text = textbox_create ( "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
NORMAL, ( msg != NULL ) ? msg : "" ); NORMAL, ( msg != NULL ) ? msg : "" );
box_add ( box, WIDGET ( state->text ), TRUE, 1 ); box_add ( box, WIDGET ( state->text ), TRUE );
// Make sure we enable fixed num lines when in normal window mode. // Make sure we enable fixed num lines when in normal window mode.
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) { if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {

View file

@ -273,15 +273,7 @@ static void box_free ( widget *wid )
g_free ( b ); g_free ( b );
} }
static int box_sort_children ( gconstpointer a, gconstpointer b ) void box_add ( box *box, widget *child, gboolean expand )
{
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 ) { if ( box == NULL ) {
return; return;
@ -298,10 +290,8 @@ void box_add ( box *box, widget *child, gboolean expand, int index )
box->widget.h = height; box->widget.h = height;
} }
child->expand = rofi_theme_get_boolean ( child, "expand", expand ); child->expand = rofi_theme_get_boolean ( child, "expand", expand );
child->index = rofi_theme_get_integer_exact ( child, "index", index );
child->parent = WIDGET ( box ); child->parent = WIDGET ( box );
box->children = g_list_append ( box->children, (void *) child ); box->children = g_list_append ( box->children, (void *) child );
//box->children = g_list_sort ( box->children, box_sort_children );
widget_update ( WIDGET ( box ) ); widget_update ( WIDGET ( box ) );
} }

View file

@ -294,9 +294,11 @@ static void listview_draw ( widget *wid, cairo_t *draw )
int left_offset = widget_padding_get_left ( wid ); int left_offset = widget_padding_get_left ( wid );
int top_offset = widget_padding_get_top ( wid ); int top_offset = widget_padding_get_top ( wid );
/*
if ( lv->scrollbar->widget.index == 0 ) { if ( lv->scrollbar->widget.index == 0 ) {
left_offset += spacing_hori + lv->scrollbar->widget.w; left_offset += spacing_hori + lv->scrollbar->widget.w;
} }
*/
if ( lv->cur_elements > 0 && lv->max_rows > 0 ) { if ( lv->cur_elements > 0 && lv->max_rows > 0 ) {
// Set new x/y possition. // Set new x/y possition.
unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset ); unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset );
@ -415,7 +417,7 @@ static void listview_resize ( widget *wid, short w, short h )
lv->max_rows = ( spacing_vert + height ) / ( lv->element_height + spacing_vert ); lv->max_rows = ( spacing_vert + height ) / ( lv->element_height + spacing_vert );
lv->max_elements = lv->max_rows * lv->menu_columns; lv->max_elements = lv->max_rows * lv->menu_columns;
if ( lv->scrollbar->widget.index == 0 ) { if ( /*lv->scrollbar->widget.index ==*/ 0 ) {
widget_move ( WIDGET ( lv->scrollbar ), widget_move ( WIDGET ( lv->scrollbar ),
widget_padding_get_left ( WIDGET ( lv ) ), widget_padding_get_left ( WIDGET ( lv ) ),
widget_padding_get_top ( WIDGET ( lv ) ) ); widget_padding_get_top ( WIDGET ( lv ) ) );
@ -526,8 +528,6 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
char *n = g_strjoin ( ".", lv->listview_name, "scrollbar", NULL ); char *n = g_strjoin ( ".", lv->listview_name, "scrollbar", NULL );
lv->scrollbar = scrollbar_create ( n ); 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 ); g_free ( n );
lv->scrollbar->widget.parent = WIDGET ( lv ); lv->scrollbar->widget.parent = WIDGET ( lv );
// Calculate height of an element. // Calculate height of an element.

View file

@ -97,7 +97,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget_resize ( WIDGET (b), 100, 20); widget_resize ( WIDGET (b), 100, 20);
widget *wid1 = g_malloc0(sizeof(widget)); widget *wid1 = g_malloc0(sizeof(widget));
box_add ( b , WIDGET( wid1 ), TRUE, 0 ); box_add ( b , WIDGET( wid1 ), TRUE );
// Widget not enabled. no width allocated. // Widget not enabled. no width allocated.
TASSERTE ( wid1->h, 0); TASSERTE ( wid1->h, 0);
TASSERTE ( wid1->w, 0 ); TASSERTE ( wid1->w, 0 );
@ -108,7 +108,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
TASSERTE ( wid1->w, 100 ); TASSERTE ( wid1->w, 100 );
widget *wid2 = g_malloc0(sizeof(widget)); widget *wid2 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid2 ) ); widget_enable ( WIDGET ( wid2 ) );
box_add ( b , WIDGET( wid2 ), TRUE, 1 ); box_add ( b , WIDGET( wid2 ), TRUE );
TASSERTE ( wid1->h, 20); TASSERTE ( wid1->h, 20);
TASSERTE ( wid1->w, 49); TASSERTE ( wid1->w, 49);
TASSERTE ( wid2->h, 20); TASSERTE ( wid2->h, 20);
@ -116,7 +116,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget *wid3 = g_malloc0(sizeof(widget)); widget *wid3 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid3 ) ); widget_enable ( WIDGET ( wid3 ) );
box_add ( b , WIDGET( wid3 ), FALSE, 2 ); box_add ( b , WIDGET( wid3 ), FALSE );
TASSERTE ( wid1->h, 20); TASSERTE ( wid1->h, 20);
TASSERTE ( wid1->w, 48); TASSERTE ( wid1->w, 48);
TASSERTE ( wid2->h, 20); TASSERTE ( wid2->h, 20);
@ -144,12 +144,12 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget *wid4 = g_malloc0(sizeof(widget)); widget *wid4 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid4 ) ); widget_enable ( WIDGET ( wid4 ) );
widget_resize ( WIDGET ( wid4 ), 20, 20 ); widget_resize ( WIDGET ( wid4 ), 20, 20 );
box_add ( b , WIDGET( wid4 ), FALSE, 5 ); box_add ( b , WIDGET( wid4 ), FALSE );
TASSERTE ( wid4->x, 200-20); TASSERTE ( wid4->x, 200-20);
widget *wid5 = g_malloc0(sizeof(widget)); widget *wid5 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid5 ) ); widget_enable ( WIDGET ( wid5 ) );
widget_resize ( WIDGET ( wid5 ), 20, 20 ); widget_resize ( WIDGET ( wid5 ), 20, 20 );
box_add ( b , WIDGET( wid5 ), TRUE, 6 ); box_add ( b , WIDGET( wid5 ), TRUE );
TASSERTE ( wid5->x, 149); TASSERTE ( wid5->x, 149);
widget_free ( WIDGET ( b ) ); widget_free ( WIDGET ( b ) );
} }
@ -159,7 +159,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
//box_set_padding ( b, 5 ); //box_set_padding ( b, 5 );
widget *wid1 = g_malloc0(sizeof(widget)); widget *wid1 = g_malloc0(sizeof(widget));
box_add ( b , WIDGET( wid1 ), TRUE, 0 ); box_add ( b , WIDGET( wid1 ), TRUE );
// Widget not enabled. no width allocated. // Widget not enabled. no width allocated.
TASSERTE ( wid1->h, 0); TASSERTE ( wid1->h, 0);
TASSERTE ( wid1->w, 0 ); TASSERTE ( wid1->w, 0 );
@ -170,7 +170,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
TASSERTE ( wid1->w, 20 ); TASSERTE ( wid1->w, 20 );
widget *wid2 = g_malloc0(sizeof(widget)); widget *wid2 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid2 ) ); widget_enable ( WIDGET ( wid2 ) );
box_add ( b , WIDGET( wid2 ), TRUE, 1 ); box_add ( b , WIDGET( wid2 ), TRUE );
TASSERTE ( wid1->w, 20); TASSERTE ( wid1->w, 20);
TASSERTE ( wid1->h, 49); TASSERTE ( wid1->h, 49);
TASSERTE ( wid2->w, 20); TASSERTE ( wid2->w, 20);
@ -178,7 +178,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget *wid3 = g_malloc0(sizeof(widget)); widget *wid3 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid3 ) ); widget_enable ( WIDGET ( wid3 ) );
box_add ( b , WIDGET( wid3 ), FALSE, 2 ); box_add ( b , WIDGET( wid3 ), FALSE );
TASSERTE ( wid1->w, 20); TASSERTE ( wid1->w, 20);
TASSERTE ( wid1->h, 48); TASSERTE ( wid1->h, 48);
TASSERTE ( wid2->w, 20); TASSERTE ( wid2->w, 20);
@ -205,12 +205,12 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget *wid4 = g_malloc0(sizeof(widget)); widget *wid4 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid4 ) ); widget_enable ( WIDGET ( wid4 ) );
widget_resize ( WIDGET ( wid4 ), 20, 20 ); widget_resize ( WIDGET ( wid4 ), 20, 20 );
box_add ( b , WIDGET( wid4 ), FALSE, 5 ); box_add ( b , WIDGET( wid4 ), FALSE );
TASSERTE ( wid4->y, 180); TASSERTE ( wid4->y, 180);
widget *wid5 = g_malloc0(sizeof(widget)); widget *wid5 = g_malloc0(sizeof(widget));
widget_enable ( WIDGET ( wid5 ) ); widget_enable ( WIDGET ( wid5 ) );
widget_resize ( WIDGET ( wid5 ), 20, 20 ); widget_resize ( WIDGET ( wid5 ), 20, 20 );
box_add ( b , WIDGET( wid5 ), TRUE, 6 ); box_add ( b , WIDGET( wid5 ), TRUE );
TASSERTE ( wid5->y, 149); TASSERTE ( wid5->y, 149);
widget_free ( WIDGET ( b ) ); widget_free ( WIDGET ( b ) );
} }
@ -221,15 +221,15 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget *wid1 = g_malloc0(sizeof(widget)); widget *wid1 = g_malloc0(sizeof(widget));
wid1->type = 1; wid1->type = 1;
widget_enable(wid1); widget_enable(wid1);
box_add ( b , WIDGET( wid1 ), TRUE, 0 ); box_add ( b , WIDGET( wid1 ), TRUE );
widget *wid2 = g_malloc0(sizeof(widget)); widget *wid2 = g_malloc0(sizeof(widget));
wid2->type = 1; wid2->type = 1;
widget_enable(wid2); widget_enable(wid2);
box_add ( b , WIDGET( wid2 ), TRUE, 1 ); box_add ( b , WIDGET( wid2 ), TRUE );
widget *wid3 = g_malloc0(sizeof(widget)); widget *wid3 = g_malloc0(sizeof(widget));
wid3->type = 2; wid3->type = 2;
widget_enable(wid3); widget_enable(wid3);
box_add ( b , WIDGET( wid3 ), TRUE, 2 ); box_add ( b , WIDGET( wid3 ), TRUE );
gint x = 10; gint x = 10;
gint y = 50; gint y = 50;