mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Redo some of the redrawing methods, better padding support
This commit is contained in:
parent
1c611b0eec
commit
dfc8a31126
7 changed files with 36 additions and 61 deletions
|
@ -34,14 +34,10 @@ typedef enum
|
|||
/**
|
||||
* @param name The name of the widget.
|
||||
* @param type The packing direction of the newly created box.
|
||||
* @param x The x position of the box relative to its parent.
|
||||
* @param y The y position of the box relative to its parent.
|
||||
* @param w The width of the box.
|
||||
* @param h The height of the box.
|
||||
*
|
||||
* @returns a newly created box, free with #widget_free
|
||||
*/
|
||||
box * box_create ( const char *name, boxType type, short x, short y, short w, short h );
|
||||
box * box_create ( const char *name, boxType type );
|
||||
|
||||
/**
|
||||
* @param box Handle to the box widget.
|
||||
|
|
|
@ -87,10 +87,6 @@ typedef enum
|
|||
|
||||
/**
|
||||
* @param flags #TextboxFlags indicating the type of textbox.
|
||||
* @param x horizontal positon of textbox
|
||||
* @param y vertical position of textbox
|
||||
* @param w width of textbox
|
||||
* @param h height of textbox
|
||||
* @param tbft #TextBoxFontType current state of textbox.
|
||||
* @param text intial text to display.
|
||||
*
|
||||
|
@ -100,7 +96,6 @@ typedef enum
|
|||
* @returns a new #textbox
|
||||
*/
|
||||
textbox* textbox_create ( const char *name, TextboxFlags flags,
|
||||
short x, short y, short w, short h,
|
||||
TextBoxFontType tbft,
|
||||
const char *text );
|
||||
/**
|
||||
|
|
|
@ -1449,22 +1449,18 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
// Get active monitor size.
|
||||
TICK_N ( "Get active monitor" );
|
||||
|
||||
int total_width = state->width - 2*state->border - state->pad.left - state->pad.right;
|
||||
int total_height = state->height - 2*state->border - state->pad.top- state->pad.bottom;
|
||||
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
|
||||
state->border+state->pad.left, state->border+state->pad.top,
|
||||
total_width, total_height);
|
||||
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL );
|
||||
widget_move ( WIDGET ( state->main_box ), state->border+state->pad.left, state->border+state->pad.top );
|
||||
|
||||
// we need this at this point so we can get height.
|
||||
unsigned int line_height = textbox_get_estimated_char_height ();
|
||||
rofi_view_calculate_window_and_element_width ( state );
|
||||
|
||||
state->input_bar = box_create ( "inputbar.box", BOX_HORIZONTAL, 0, 0, total_width, line_height );
|
||||
state->input_bar = box_create ( "inputbar.box", BOX_HORIZONTAL );
|
||||
state->input_bar_separator = separator_create ( "inputbar.separator", S_HORIZONTAL, 2 );
|
||||
|
||||
// Only enable widget when sidebar is enabled.
|
||||
if ( config.sidebar_mode ) {
|
||||
state->sidebar_bar = box_create ( "sidebar.box", BOX_HORIZONTAL, 0, 0, total_width, line_height );
|
||||
state->sidebar_bar = box_create ( "sidebar.box", BOX_HORIZONTAL );
|
||||
separator *sep = separator_create ( "sidebar.separator", S_HORIZONTAL, 2 );
|
||||
box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE );
|
||||
box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE );
|
||||
|
@ -1472,7 +1468,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
|
||||
for ( unsigned int j = 0; j < state->num_modi; j++ ) {
|
||||
const Mode * mode = rofi_get_mode ( j );
|
||||
state->modi[j] = textbox_create ( "sidebar.button", TB_CENTER, 0, 0, 0, 0, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
|
||||
state->modi[j] = textbox_create ( "sidebar.button", TB_CENTER|TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
|
||||
mode_get_display_name ( mode ) );
|
||||
box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE, FALSE );
|
||||
widget_set_clicked_handler ( WIDGET ( state->modi[j] ), rofi_view_modi_clicked_cb, state );
|
||||
|
@ -1482,33 +1478,32 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
int end = ( config.location == WL_EAST_SOUTH || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST );
|
||||
box_add ( state->main_box, WIDGET ( state->input_bar ), FALSE, end );
|
||||
|
||||
state->case_indicator = textbox_create ( "inputbar.case-indicator", TB_AUTOWIDTH, 0, 0, 0, line_height, NORMAL, "*" );
|
||||
state->case_indicator = textbox_create ( "inputbar.case-indicator", TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "*" );
|
||||
// Add small separator between case indicator and text box.
|
||||
box_add ( state->input_bar, WIDGET ( state->case_indicator ), FALSE, TRUE );
|
||||
|
||||
// Prompt box.
|
||||
state->prompt = textbox_create ( "inputbar.prompt",TB_AUTOWIDTH, 0, 0, 0, line_height, NORMAL, "" );
|
||||
state->prompt = textbox_create ( "inputbar.prompt",TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "" );
|
||||
rofi_view_update_prompt ( state );
|
||||
box_add ( state->input_bar, WIDGET ( state->prompt ), FALSE, FALSE );
|
||||
|
||||
// Entry box
|
||||
TextboxFlags tfl = TB_EDITABLE;
|
||||
tfl |= ( ( menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0;
|
||||
state->text = textbox_create ( "inputbar.entry", tfl, 0, 0, 0, line_height, NORMAL, input );
|
||||
state->text = textbox_create ( "inputbar.entry", tfl|TB_AUTOHEIGHT, NORMAL, input );
|
||||
|
||||
box_add ( state->input_bar, WIDGET ( state->text ), TRUE, FALSE );
|
||||
|
||||
textbox_text ( state->case_indicator, get_matching_state () );
|
||||
if ( message ) {
|
||||
textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
|
||||
total_width, -1, NORMAL, message );
|
||||
textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message );
|
||||
separator *sep = separator_create ( "message.separator", S_HORIZONTAL, 2 );
|
||||
box_add ( state->main_box, WIDGET ( sep ), FALSE, end);
|
||||
box_add ( state->main_box, WIDGET ( message_tb ), FALSE, end);
|
||||
}
|
||||
box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, end );
|
||||
|
||||
state->overlay = textbox_create ( "overlay.textbox", TB_AUTOWIDTH, 0, 0, 20, line_height, URGENT, "blaat" );
|
||||
state->overlay = textbox_create ( "overlay.textbox", TB_AUTOWIDTH|TB_AUTOHEIGHT, URGENT, "blaat" );
|
||||
widget_disable ( WIDGET ( state->overlay ) );
|
||||
|
||||
state->list_view = listview_create ( "listview", update_callback, state, config.element_height );
|
||||
|
@ -1565,16 +1560,11 @@ int rofi_view_error_dialog ( const char *msg, int markup )
|
|||
// state->border = rofi_theme_get_integer ( "@window", "window", NULL, "padding" , config.padding );
|
||||
state->border += rofi_theme_get_integer ( "@window", "window", NULL, "border-width" , config.menu_bw);
|
||||
|
||||
int total_width = state->width - 2*state->border - state->pad.left - state->pad.right;
|
||||
int total_height = state->height - 2*state->border - state->pad.top- state->pad.bottom;
|
||||
|
||||
rofi_view_calculate_window_and_element_width ( state );
|
||||
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
|
||||
state->border, state->border,
|
||||
total_width, total_height );
|
||||
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL);
|
||||
widget_move ( WIDGET ( state->main_box ), state->border+state->pad.left, state->border+state->pad.top );
|
||||
state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||
( state->border+state->pad.left ), ( state->border+state->pad.top ),
|
||||
total_width, 1, NORMAL, ( msg != NULL ) ? msg : "" );
|
||||
NORMAL, ( msg != NULL ) ? msg : "" );
|
||||
box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE );
|
||||
unsigned int line_height = textbox_get_height ( state->text );
|
||||
|
||||
|
|
|
@ -226,6 +226,16 @@ void box_add ( box *box, widget *child, gboolean expand, gboolean end )
|
|||
if ( box == NULL ) {
|
||||
return;
|
||||
}
|
||||
// Make sure box is width/heigh enough.
|
||||
if ( box->type == BOX_VERTICAL){
|
||||
int width=box->widget.w;
|
||||
width = MAX ( child->w, width+box->widget.pad.left+box->widget.pad.right );
|
||||
box->widget.w = width;
|
||||
} else {
|
||||
int height = box->widget.h;
|
||||
height = MAX (height, child->h+box->widget.pad.top+box->widget.pad.bottom);
|
||||
box->widget.h = height;
|
||||
}
|
||||
child->expand = expand;
|
||||
child->end = end;
|
||||
child->parent = WIDGET ( box );
|
||||
|
@ -278,14 +288,12 @@ static gboolean box_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
box * box_create ( const char *name, boxType type, short x, short y, short w, short h )
|
||||
box * box_create ( const char *name, boxType type )
|
||||
{
|
||||
box *b = g_malloc0 ( sizeof ( box ) );
|
||||
// Initialize widget.
|
||||
widget_init ( WIDGET(b), name, BOX_CLASS_NAME);
|
||||
b->type = type;
|
||||
b->widget.y = y;
|
||||
b->widget.w = w;
|
||||
b->widget.draw = box_draw;
|
||||
b->widget.free = box_free;
|
||||
b->widget.resize = box_resize;
|
||||
|
@ -295,9 +303,6 @@ box * box_create ( const char *name, boxType type, short x, short y, short w, sh
|
|||
b->widget.enabled = TRUE;
|
||||
|
||||
box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin ));
|
||||
// Do this dynamically
|
||||
b->widget.h = h+b->widget.pad.top+b->widget.pad.bottom;
|
||||
b->widget.x = x+b->widget.pad.left+b->widget.pad.right;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ static void listview_recompute_elements ( listview *lv )
|
|||
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
|
||||
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
|
||||
char *name = g_strjoin (".", lv->widget.name,"element", NULL);
|
||||
lv->boxes[i] = textbox_create ( name, flags, 0, 0, 0, lv->element_height, NORMAL, "" );
|
||||
lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" );
|
||||
g_free ( name );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,15 +136,16 @@ static void separator_draw ( widget *wid, cairo_t *draw )
|
|||
cairo_set_dash ( draw, dashes, 1, 0.0 );
|
||||
}
|
||||
if ( sep->type == S_HORIZONTAL ) {
|
||||
cairo_set_line_width ( draw, wid->h );
|
||||
int height= wid->h-wid->pad.top-wid->pad.bottom;
|
||||
cairo_set_line_width ( draw, height );
|
||||
double half = height / 2.0;
|
||||
cairo_move_to ( draw, wid->x+wid->pad.left, wid->y + wid->pad.top +half );
|
||||
cairo_line_to ( draw, wid->x+wid->w-wid->pad.right, wid->y +wid->pad.top + half );
|
||||
}
|
||||
else {
|
||||
cairo_set_line_width ( draw, wid->w );
|
||||
double half = wid->w / 2.0;
|
||||
int width = wid->w-wid->pad.left-wid->pad.right;
|
||||
cairo_set_line_width ( draw, width);
|
||||
double half = width / 2.0;
|
||||
cairo_move_to ( draw, wid->x + wid->pad.left + half, wid->y +wid->pad.top);
|
||||
cairo_line_to ( draw, wid->x + wid->pad.left + half, wid->y + wid->h-wid->pad.bottom );
|
||||
}
|
||||
|
|
|
@ -98,8 +98,7 @@ static void textbox_resize ( widget *wid, short w, short h )
|
|||
textbox_moveresize ( tb, tb->widget.x, tb->widget.y, w, h );
|
||||
}
|
||||
|
||||
textbox* textbox_create ( const char *name, TextboxFlags flags, short x, short y, short w, short h,
|
||||
TextBoxFontType tbft, const char *text )
|
||||
textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text )
|
||||
{
|
||||
textbox *tb = g_slice_new0 ( textbox );
|
||||
|
||||
|
@ -111,11 +110,6 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, short x, short y
|
|||
tb->widget.get_height = _textbox_get_height;
|
||||
tb->flags = flags;
|
||||
|
||||
tb->widget.x = x;
|
||||
tb->widget.y = y;
|
||||
tb->widget.w = MAX ( 1, w );
|
||||
tb->widget.h = MAX ( 1, h );
|
||||
|
||||
tb->changed = FALSE;
|
||||
|
||||
tb->main_surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, tb->widget.w, tb->widget.h );
|
||||
|
@ -789,12 +783,9 @@ void textbox_cleanup ( void )
|
|||
int textbox_get_width ( widget *wid )
|
||||
{
|
||||
textbox *tb = (textbox *) wid;
|
||||
if ( !wid->expand ) {
|
||||
if ( tb->flags & TB_AUTOWIDTH ) {
|
||||
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
|
||||
return textbox_get_font_width ( tb ) + 2 * config.line_padding + offset;
|
||||
}
|
||||
return tb->widget.w;
|
||||
if ( tb->flags & TB_AUTOWIDTH ) {
|
||||
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
|
||||
return textbox_get_font_width ( tb ) + 2 * config.line_padding + offset;
|
||||
}
|
||||
return tb->widget.w;
|
||||
}
|
||||
|
@ -802,11 +793,8 @@ int textbox_get_width ( widget *wid )
|
|||
int _textbox_get_height ( widget *wid )
|
||||
{
|
||||
textbox *tb = (textbox *) wid;
|
||||
if ( !wid->expand ) {
|
||||
if ( tb->flags & TB_AUTOHEIGHT ) {
|
||||
return textbox_get_height ( tb );
|
||||
}
|
||||
return tb->widget.h;
|
||||
if ( tb->flags & TB_AUTOHEIGHT ) {
|
||||
return textbox_get_height ( tb );
|
||||
}
|
||||
return tb->widget.h;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue