1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Textbox uses new theme engine..

This commit is contained in:
Dave Davenport 2016-12-11 17:06:31 +01:00
parent 5e371eedeb
commit 78abbeb710
7 changed files with 65 additions and 93 deletions

View file

@ -48,7 +48,7 @@ typedef void ( *listview_mouse_activated_cb )( listview *, xcb_button_press_even
*
* @returns a new listview
*/
listview *listview_create ( listview_update_callback cb, void *udata, unsigned int eh );
listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh );
/**
* @param lv The listview handle
@ -131,37 +131,6 @@ void listview_nav_page_next ( listview *lv );
*/
void listview_nav_page_prev ( listview *lv );
/**
* @param lv Handler to the listview object
* @param padding The padding
*
* Padding on between the widgets.
*/
void listview_set_padding ( listview *lv, unsigned int padding );
/**
* @param lv Handler to the listview object
* @param lines The maximum number of lines
*
* Set the maximum number of lines to show.
*/
void listview_set_max_lines ( listview *lv, unsigned int lines );
/**
* @param lv Handler to the listview object
* @param columns The maximum number of columns
*
* Set the maximum number of columns to show.
*/
void listview_set_max_columns ( listview *lv, unsigned int columns );
/**
* @param lv Handler to the listview object
* @param enabled enable
*
* Set fixed num lines mode.
*/
void listview_set_fixed_num_lines ( listview *lv, gboolean enabled );
/**
* @param lv Handler to the listview object
* @param enabled enable

View file

@ -22,6 +22,7 @@ typedef struct _scrollbar
} scrollbar;
/**
* @param name The name of the widget.
* @param x The x coordinate (relative to parent) to position the new scrollbar
* @param y The y coordinate (relative to parent) to position the new scrollbar
* @param w The width of the scrollbar
@ -31,7 +32,7 @@ typedef struct _scrollbar
*
* @returns the scrollbar object.
*/
scrollbar *scrollbar_create ( short x, short y, short w, short h );
scrollbar *scrollbar_create ( const char *name, short x, short y, short w, short h );
/**
* @param sb scrollbar object

View file

@ -39,6 +39,8 @@ typedef struct
int update;
int blink;
guint blink_timeout;
//
char *theme_name ;
} textbox;
/**
@ -97,7 +99,7 @@ typedef enum
* free with #widget_free
* @returns a new #textbox
*/
textbox* textbox_create ( TextboxFlags flags,
textbox* textbox_create ( const char *name, TextboxFlags flags,
short x, short y, short w, short h,
TextBoxFontType tbft,
const char *text );

View file

@ -586,8 +586,9 @@ void __create_window ( MenuFlags menu_flags )
pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi );
}
// Setup font.
if ( config.menu_font ) {
PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font );
char *font = rofi_theme_get_string ("window", "font" , config.menu_font );
if ( font ) {
PangoFontDescription *pfd = pango_font_description_from_string ( font );
pango_context_set_font_description ( p, pfd );
pango_font_description_free ( pfd );
}
@ -1452,7 +1453,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 ( TB_CENTER, 0, 0, 0, 0, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
state->modi[j] = textbox_create ( "sidebar.button", TB_CENTER, 0, 0, 0, 0, ( 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 );
@ -1462,25 +1463,25 @@ 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 ( TB_AUTOWIDTH, 0, 0, 0, line_height, NORMAL, "*" );
state->case_indicator = textbox_create ( "inputbar.case-indicator", TB_AUTOWIDTH, 0, 0, 0, line_height, 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 ( TB_AUTOWIDTH, 0, 0, 0, line_height, NORMAL, "" );
state->prompt = textbox_create ( "inputbar.prompt",TB_AUTOWIDTH, 0, 0, 0, line_height, 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 ( tfl, 0, 0, 0, line_height, NORMAL, input );
state->text = textbox_create ( "inputbar.entry", tfl, 0, 0, 0, line_height, 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 ( TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
state->width - ( 2 * ( state->border ) ), -1, NORMAL, message );
separator *sep = separator_create ( "message.separator", S_HORIZONTAL, 2 );
box_add ( state->main_box, WIDGET ( sep ), FALSE, end);
@ -1488,19 +1489,12 @@ RofiViewState *rofi_view_create ( Mode *sw,
}
box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, end );
state->overlay = textbox_create ( TB_AUTOWIDTH, 0, 0, 20, line_height, URGENT, "blaat" );
state->overlay = textbox_create ( "overlay.textbox", TB_AUTOWIDTH, 0, 0, 20, line_height, URGENT, "blaat" );
widget_disable ( WIDGET ( state->overlay ) );
state->list_view = listview_create ( update_callback, state, config.element_height );
state->list_view = listview_create ( "listview", update_callback, state, config.element_height );
// Set configuration
listview_set_multi_select ( state->list_view, ( state->menu_flags & MENU_INDICATOR ) == MENU_INDICATOR );
listview_set_padding ( state->list_view, rofi_theme_get_integer ( "listview", "padding", config.line_margin ));
listview_set_max_lines ( state->list_view, rofi_theme_get_integer ( "listview", "lines", config.menu_lines ));
listview_set_max_columns ( state->list_view, rofi_theme_get_integer ( "listview", "columns", config.menu_columns));
listview_set_fixed_num_lines ( state->list_view, rofi_theme_get_boolean ( "listview", "fixed-height", config.fixed_num_lines ));
listview_set_show_scrollbar ( state->list_view, rofi_theme_get_boolean ( "listview", "scrollbar", !config.hide_scrollbar ));
listview_set_scrollbar_width ( state->list_view, rofi_theme_get_integer ( "listview", "scrollbar-width", config.scrollbar_width ));
listview_set_cycle ( state->list_view, rofi_theme_get_boolean ( "listview" , "cycle", config.cycle ));
listview_set_scroll_type ( state->list_view, config.scroll_method );
listview_set_mouse_activated_cb ( state->list_view, rofi_view_listview_mouse_activated_cb, state );
@ -1553,7 +1547,7 @@ int rofi_view_error_dialog ( const char *msg, int markup )
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
state->border, state->border,
state->width - 2 * state->border, state->height - 2 * state->border );
state->text = textbox_create ( ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
( state->border ), ( state->border ),
( state->width - ( 2 * ( state->border ) ) ), 1, NORMAL, ( msg != NULL ) ? msg : "" );
box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE );

View file

@ -29,6 +29,9 @@
#include <widgets/listview.h>
#include <widgets/scrollbar.h>
#include "settings.h"
#include "theme.h"
struct _listview
{
widget widget;
@ -205,7 +208,9 @@ static void listview_recompute_elements ( listview *lv )
if ( newne > 0 ) {
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
lv->boxes[i] = textbox_create ( flags, 0, 0, 0, lv->element_height, NORMAL, "" );
char *name = g_strjoin (".", lv->widget.name,"element", NULL);
lv->boxes[i] = textbox_create ( name, flags, 0, 0, 0, lv->element_height, NORMAL, "" );
g_free ( name );
}
}
lv->rchanged = TRUE;
@ -309,9 +314,10 @@ static gboolean listview_motion_notify ( widget *wid, xcb_motion_notify_event_t
return FALSE;
}
listview *listview_create ( listview_update_callback cb, void *udata, unsigned int eh )
listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh )
{
listview *lv = g_malloc0 ( sizeof ( listview ) );
lv->widget.name = g_strdup(name);
lv->widget.free = listview_free;
lv->widget.resize = listview_resize;
lv->widget.draw = listview_draw;
@ -319,7 +325,9 @@ listview *listview_create ( listview_update_callback cb, void *udata, unsigned i
lv->widget.motion_notify = listview_motion_notify;
lv->widget.enabled = TRUE;
lv->scrollbar = scrollbar_create ( 0, 0, 4, 0 );
char *n = g_strjoin(".", lv->widget.name,"scrollbar", NULL);
lv->scrollbar = scrollbar_create ( n,0, 0, 4, 0 );
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.
@ -327,6 +335,17 @@ listview *listview_create ( listview_update_callback cb, void *udata, unsigned i
lv->callback = cb;
lv->udata = udata;
// Some settings.
lv->padding = rofi_theme_get_integer ( lv->widget.name, "padding", config.line_margin );
lv->menu_lines = rofi_theme_get_integer ( lv->widget.name, "lines", config.menu_lines );
lv->menu_columns = rofi_theme_get_integer ( lv->widget.name, "columns", config.menu_columns);
lv->fixed_num_lines = rofi_theme_get_boolean ( lv->widget.name, "fixed-height", config.fixed_num_lines );
listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( lv->widget.name, "scrollbar", !config.hide_scrollbar ));
listview_set_scrollbar_width ( lv, rofi_theme_get_integer ( lv->widget.name, "scrollbar-width", config.scrollbar_width ));
lv->cycle = rofi_theme_get_boolean ( lv->widget.name, "cycle", config.cycle );
return lv;
}
@ -438,34 +457,6 @@ unsigned int listview_get_desired_height ( listview *lv )
return h * lv->element_height + ( h - 1 ) * lv->padding;
}
/**
* Configure the widget!
*/
void listview_set_padding ( listview *lv, unsigned int padding )
{
if ( lv ) {
lv->padding = padding;
}
}
void listview_set_max_lines ( listview *lv, unsigned int lines )
{
if ( lv ) {
lv->menu_lines = lines;
}
}
void listview_set_max_columns ( listview *lv, unsigned int columns )
{
if ( lv ) {
lv->menu_columns = columns;
}
}
void listview_set_fixed_num_lines ( listview *lv, gboolean enabled )
{
if ( lv ) {
lv->fixed_num_lines = enabled;
}
}
void listview_set_show_scrollbar ( listview *lv, gboolean enabled )
{
if ( lv ) {
@ -485,12 +476,6 @@ void listview_set_scrollbar_width ( listview *lv, unsigned int width )
}
}
void listview_set_cycle ( listview *lv, gboolean cycle )
{
if ( lv ) {
lv->cycle = cycle;
}
}
void listview_set_scroll_type ( listview *lv, ScrollType type )
{
if ( lv ) {

View file

@ -33,10 +33,10 @@ static void scrollbar_draw ( widget *, cairo_t * );
static void scrollbar_free ( widget * );
static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
scrollbar *scrollbar_create ( short x, short y, short w, short h )
scrollbar *scrollbar_create ( const char *name, short x, short y, short w, short h )
{
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
sb->widget.name = g_strdup(name);
sb->widget.x = x;
sb->widget.y = y;
sb->widget.w = MAX ( 1, w );
@ -109,6 +109,7 @@ static void scrollbar_draw ( widget *wid, cairo_t *draw )
height = MAX ( 2, height );
// Cap length;
color_separator ( draw );
rofi_theme_get_color ( sb->widget.name, "foreground", draw );
cairo_rectangle ( draw, sb->widget.x, sb->widget.y + y, sb->widget.w, height );
cairo_fill ( draw );

View file

@ -36,6 +36,8 @@
#include "mode.h"
#include "view.h"
#include "theme.h"
#define DOT_OFFSET 15
static void textbox_draw ( widget *, cairo_t * );
@ -96,11 +98,13 @@ static void textbox_resize ( widget *wid, short w, short h )
textbox_moveresize ( tb, tb->widget.x, tb->widget.y, w, h );
}
textbox* textbox_create ( TextboxFlags flags, short x, short y, short w, short h,
textbox* textbox_create ( const char *name, TextboxFlags flags, short x, short y, short w, short h,
TextBoxFontType tbft, const char *text )
{
textbox *tb = g_slice_new0 ( textbox );
tb->widget.name = g_strdup ( name );
tb->theme_name = g_strdup(name);
tb->widget.draw = textbox_draw;
tb->widget.free = textbox_free;
tb->widget.resize = textbox_resize;
@ -146,20 +150,30 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
if ( tb == NULL ) {
return;
}
char *state = "normal";
// ACTIVE has priority over URGENT if both set.
if ( t == ( URGENT | ACTIVE ) ) {
t = ACTIVE;
}
if ( t == URGENT ) {
state = "urgent";
} else if ( t == ACTIVE ){
state = "active";
}
char *mode = "normal";
RowColor *color = &( colors[t] );
switch ( ( tbft & FMOD_MASK ) )
{
case HIGHLIGHT:
tb->color_bg = color->hlbg;
tb->color_fg = color->hlfg;
mode = "selected";
break;
case ALT:
tb->color_bg = color->bgalt;
tb->color_fg = color->fg;
mode = "alternate";
break;
default:
tb->color_bg = color->bg;
@ -168,6 +182,8 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
}
if ( tb->tbft != tbft ) {
tb->update = TRUE;
g_free ( tb->theme_name);
tb->theme_name = g_strjoin ("." , tb->widget.name, mode, state, NULL );
widget_queue_redraw ( WIDGET ( tb ) );
}
tb->tbft = tbft;
@ -286,7 +302,7 @@ static void textbox_free ( widget *wid )
g_source_remove ( tb->blink_timeout );
tb->blink_timeout = 0;
}
g_free(tb->theme_name );
g_free ( tb->text );
if ( tb->layout != NULL ) {
@ -359,10 +375,12 @@ static void texbox_update ( textbox *tb )
// Set ARGB
Color col = tb->color_bg;
cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha );
rofi_theme_get_color ( tb->theme_name, "background", tb->main_draw);
cairo_paint ( tb->main_draw );
col = tb->color_fg;
cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha );
rofi_theme_get_color ( tb->theme_name, "foreground", tb->main_draw);
// draw the cursor
if ( tb->flags & TB_EDITABLE && tb->blink ) {
cairo_rectangle ( tb->main_draw, x + cursor_x, y, cursor_width, font_height );
@ -375,13 +393,15 @@ static void texbox_update ( textbox *tb )
cairo_move_to ( tb->main_draw, x, y );
pango_cairo_show_layout ( tb->main_draw, tb->layout );
if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED | HIGHLIGHT ) ) ) {
if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) {
/*
if ( ( tb->tbft & SELECTED ) == SELECTED ) {
cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha );
}
else if ( ( tb->tbft & HIGHLIGHT ) == HIGHLIGHT ) {
cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha * 0.2 );
}
*/
cairo_arc ( tb->main_draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI );
cairo_fill ( tb->main_draw );