1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-07-31 21:59:25 -04:00

Make separator work in both directions ( hori/vert ).

This commit is contained in:
Dave Davenport 2016-10-09 10:07:32 +02:00
parent ad02f8f0b7
commit f10bc5004f
6 changed files with 73 additions and 43 deletions

View file

@ -14,13 +14,24 @@
typedef struct _separator separator;
/**
* @param h The height of the separator.
* Direction of the separator.
*/
typedef enum
{
S_HORIZONTAL = 0,
S_VERTICAL = 1
} separator_type;
/**
* @param type The type of separator.
* @param sw The thickness of the separator.
*
* Create a horizontal separator with height h.
*
* @returns a new separator, free with ::widget_free
*/
separator *separator_create ( short h );
separator *separator_create ( separator_type type, short sw );
/*@}*/
#endif // ROFI_SEPARATOR_H

View file

@ -1388,7 +1388,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->input_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height );
box_set_padding ( state->input_bar, config.line_margin );
state->input_bar_separator = separator_create ( 2 );
state->input_bar_separator = separator_create ( S_HORIZONTAL, 2 );
if ( ( config.location == WL_EAST_SOUTH || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST ) ) {
box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, TRUE );
@ -1400,6 +1400,8 @@ RofiViewState *rofi_view_create ( Mode *sw,
}
state->case_indicator = textbox_create ( TB_AUTOWIDTH, 0, 0, 0, line_height, NORMAL, "*" );
// Add small separator between case indicator and text box.
/* box_add ( state->input_bar, WIDGET( separator_create ( S_VERTICAL, 2 ) ), FALSE, TRUE );*/
box_add ( state->input_bar, WIDGET ( state->case_indicator ), FALSE, TRUE );
// Prompt box.
@ -1419,7 +1421,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
textbox *message_tb = textbox_create ( TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
state->width - ( 2 * ( state->border ) ), -1, NORMAL, message );
box_add ( state->main_box, WIDGET ( message_tb ), FALSE, FALSE );
box_add ( state->main_box, WIDGET ( separator_create ( 2 ) ), FALSE, FALSE );
box_add ( state->main_box, WIDGET ( separator_create ( S_HORIZONTAL, 2 ) ), FALSE, FALSE );
}
state->overlay = textbox_create ( TB_AUTOWIDTH, 0, 0, 20, line_height, URGENT, "blaat" );
@ -1444,7 +1446,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
if ( config.sidebar_mode ) {
state->sidebar_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height );
box_set_padding ( state->sidebar_bar, config.line_margin );
box_add ( state->main_box, WIDGET ( separator_create ( 2 ) ), FALSE, TRUE );
box_add ( state->main_box, WIDGET ( separator_create ( S_HORIZONTAL, 2 ) ), FALSE, TRUE );
box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE );
state->num_modi = rofi_get_num_enabled_modi ();
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );

View file

@ -36,6 +36,7 @@
struct _separator
{
widget widget;
separator_type type;
};
const char *const _separator_style_none = "none";
@ -43,14 +44,21 @@ const char *const _separator_style_dash = "dash";
static void separator_draw ( widget *, cairo_t * );
static void separator_free ( widget * );
separator *separator_create ( short h )
separator *separator_create ( separator_type type, short sw )
{
separator *sb = g_malloc0 ( sizeof ( separator ) );
sb->type = type;
sb->widget.x = 0;
sb->widget.y = 0;
if ( sb->type == S_HORIZONTAL ) {
sb->widget.w = 1;
sb->widget.h = MAX ( 1, h );
sb->widget.h = MAX ( 1, sw );
}
else {
sb->widget.h = 1;
sb->widget.w = MAX ( 1, sw );
}
sb->widget.draw = separator_draw;
sb->widget.free = separator_free;
@ -68,16 +76,25 @@ static void separator_free ( widget *wid )
static void separator_draw ( widget *wid, cairo_t *draw )
{
separator *sep = (separator *) wid;
if ( strcmp ( config.separator_style, _separator_style_none ) ) {
cairo_set_line_width ( draw, wid->h );
color_separator ( draw );
if ( strcmp ( config.separator_style, _separator_style_dash ) == 0 ) {
const double dashes[1] = { 4 };
cairo_set_dash ( draw, dashes, 1, 0.0 );
}
if ( sep->type == S_HORIZONTAL ) {
cairo_set_line_width ( draw, wid->h );
double half = wid->h / 2.0;
cairo_move_to ( draw, wid->x, wid->y + half );
cairo_line_to ( draw, wid->x + wid->w, wid->y + half );
}
else {
cairo_set_line_width ( draw, wid->w );
double half = wid->w / 2.0;
cairo_move_to ( draw, wid->x + half, wid->y );
cairo_line_to ( draw, wid->x + half, wid->y + wid->h );
}
cairo_stroke ( draw );
}
}