mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
[TextBox] Remove TB_LEFT/CENTER/RIGHT replace with xalign/yalign.
This commit is contained in:
parent
8c27289d95
commit
9fe67c1822
5 changed files with 23 additions and 25 deletions
|
@ -65,6 +65,7 @@ typedef struct
|
|||
guint blink_timeout;
|
||||
|
||||
double yalign;
|
||||
double xalign;
|
||||
|
||||
PangoFontMetrics *metrics;
|
||||
int left_offset;
|
||||
|
@ -79,9 +80,6 @@ typedef enum
|
|||
{
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
|
@ -121,6 +119,8 @@ typedef enum
|
|||
* @param flags #TextboxFlags indicating the type of textbox.
|
||||
* @param tbft #TextBoxFontType current state of textbox.
|
||||
* @param text intial text to display.
|
||||
* @param xalign Set the Xalign value.
|
||||
* @param yalign set the yalign value.
|
||||
*
|
||||
* Create a new textbox widget.
|
||||
*
|
||||
|
@ -128,7 +128,7 @@ typedef enum
|
|||
* @returns a new #textbox
|
||||
*/
|
||||
textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags,
|
||||
TextBoxFontType tbft, const char *text );
|
||||
TextBoxFontType tbft, const char *text, double xalign, double yalign );
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
* @param tbft The style of font to render.
|
||||
|
|
|
@ -1513,7 +1513,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
|
|||
*/
|
||||
else if ( strcmp ( name, "prompt" ) == 0 ) {
|
||||
// Prompt box.
|
||||
state->prompt = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "" );
|
||||
state->prompt = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
|
||||
rofi_view_update_prompt ( state );
|
||||
box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE );
|
||||
defaults = NULL;
|
||||
|
@ -1522,7 +1522,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
|
|||
* CASE INDICATOR
|
||||
*/
|
||||
else if ( strcmp ( name, "case-indicator" ) == 0 ) {
|
||||
state->case_indicator = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*" );
|
||||
state->case_indicator = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, str, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*", 0, 0 );
|
||||
// Add small separator between case indicator and text box.
|
||||
box_add ( (box *) parent_widget, WIDGET ( state->case_indicator ), FALSE );
|
||||
textbox_text ( state->case_indicator, get_matching_state () );
|
||||
|
@ -1534,7 +1534,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
|
|||
// Entry box
|
||||
TextboxFlags tfl = TB_EDITABLE;
|
||||
tfl |= ( ( state->menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0;
|
||||
state->text = textbox_create ( WIDGET_TYPE_EDITBOX, str, tfl | TB_AUTOHEIGHT, NORMAL, NULL );
|
||||
state->text = textbox_create ( WIDGET_TYPE_EDITBOX, str, tfl | TB_AUTOHEIGHT, NORMAL, NULL, 0, 0 );
|
||||
box_add ( (box *) parent_widget, WIDGET ( state->text ), TRUE );
|
||||
}
|
||||
/**
|
||||
|
@ -1543,7 +1543,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
|
|||
else if ( strcmp ( name, "message" ) == 0 ) {
|
||||
char *strmsg = g_strjoin ( ".", str, "textbox", NULL );
|
||||
state->mesg_box = container_create ( strbox );
|
||||
state->mesg_tb = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, strmsg, TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL );
|
||||
state->mesg_tb = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, strmsg, TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL, 0, 0 );
|
||||
container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) );
|
||||
rofi_view_reload_message_bar ( state );
|
||||
box_add ( (box *) parent_widget, WIDGET ( state->mesg_box ), FALSE );
|
||||
|
@ -1576,8 +1576,8 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
|
|||
char *strbutton = g_strjoin ( ".", str, "button", NULL );
|
||||
for ( unsigned int j = 0; j < state->num_modi; j++ ) {
|
||||
const Mode * mode = rofi_get_mode ( j );
|
||||
state->modi[j] = textbox_create ( WIDGET_TYPE_SIDEBAR_MODI, strbutton, TB_CENTER | TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
|
||||
mode_get_display_name ( mode ) );
|
||||
state->modi[j] = textbox_create ( WIDGET_TYPE_SIDEBAR_MODI, strbutton, TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
|
||||
mode_get_display_name ( mode ), 0.5, 0 );
|
||||
box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE );
|
||||
widget_set_trigger_action_handler ( WIDGET ( state->modi[j] ), textbox_sidebar_modi_trigger_action, state );
|
||||
}
|
||||
|
@ -1585,7 +1585,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
|
|||
}
|
||||
}
|
||||
else if ( g_ascii_strncasecmp ( name, "textbox", 7 ) == 0 ) {
|
||||
textbox *t = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, str, TB_WRAP, NORMAL, "" );
|
||||
textbox *t = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, str, TB_WRAP, NORMAL, "", 0, 0 );
|
||||
box_add ( (box *) parent_widget, WIDGET ( t ), TRUE );
|
||||
}
|
||||
else {
|
||||
|
@ -1643,7 +1643,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
textbox_text ( state->text, input );
|
||||
}
|
||||
|
||||
state->overlay = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat" );
|
||||
state->overlay = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat", 0.5, 0 );
|
||||
state->overlay->widget.parent = WIDGET ( state->main_window );
|
||||
widget_disable ( WIDGET ( state->overlay ) );
|
||||
|
||||
|
@ -1685,7 +1685,7 @@ int rofi_view_error_dialog ( const char *msg, int markup )
|
|||
box *box = box_create ( "window.mainbox.message.box", ROFI_ORIENTATION_VERTICAL );
|
||||
box_add ( state->main_window, WIDGET ( box ), TRUE );
|
||||
state->text = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||
NORMAL, ( msg != NULL ) ? msg : "" );
|
||||
NORMAL, ( msg != NULL ) ? msg : "", 0, 0 );
|
||||
box_add ( box, WIDGET ( state->text ), TRUE );
|
||||
|
||||
// Make sure we enable fixed num lines when in normal window mode.
|
||||
|
|
|
@ -372,7 +372,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;
|
||||
flags |= ( ( config.show_icons ) ? TB_ICON : 0 );
|
||||
lv->boxes[i] = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, name, flags, NORMAL, "" );
|
||||
lv->boxes[i] = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, name, flags, NORMAL, "", 0, 0 );
|
||||
widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i] ), listview_element_trigger_action, lv );
|
||||
}
|
||||
g_free ( name );
|
||||
|
@ -535,7 +535,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
|
|||
// Calculate height of an element.
|
||||
//
|
||||
char *tb_name = g_strjoin ( ".", lv->listview_name, "element", NULL );
|
||||
textbox *tb = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, tb_name, 0, NORMAL, "" );
|
||||
textbox *tb = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, tb_name, 0, NORMAL, "", 0, 0 );
|
||||
lv->element_height = textbox_get_estimated_height ( tb, lv->eh );
|
||||
g_free ( tb_name );
|
||||
widget_free ( WIDGET ( tb ) );
|
||||
|
|
|
@ -137,7 +137,7 @@ static WidgetTriggerActionResult textbox_editable_trigger_action ( widget *wid,
|
|||
return WIDGET_TRIGGER_ACTION_RESULT_IGNORED;
|
||||
}
|
||||
|
||||
textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text )
|
||||
textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign )
|
||||
{
|
||||
textbox *tb = g_slice_new0 ( textbox );
|
||||
|
||||
|
@ -207,8 +207,10 @@ textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags,
|
|||
tb->widget.trigger_action = textbox_editable_trigger_action;
|
||||
}
|
||||
|
||||
tb->yalign = rofi_theme_get_double ( WIDGET ( tb ), "vertical-align", 0.0 );
|
||||
tb->yalign = rofi_theme_get_double ( WIDGET ( tb ), "vertical-align", xalign );
|
||||
tb->yalign = MAX ( 0, MIN ( 1.0, tb->yalign ) );
|
||||
tb->xalign = rofi_theme_get_double ( WIDGET ( tb ), "horizontal-align", yalign );
|
||||
tb->xalign = MAX ( 0, MIN ( 1.0, tb->xalign ) );
|
||||
// Enabled by default
|
||||
tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE );
|
||||
|
||||
|
@ -439,16 +441,12 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
|
|||
}
|
||||
x += offset;
|
||||
|
||||
if ( tb->flags & TB_RIGHT ) {
|
||||
if ( tb->xalign > 0.001 ) {
|
||||
int line_width = 0;
|
||||
// Get actual width.
|
||||
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL );
|
||||
x = ( tb->widget.w - line_width - widget_padding_get_right ( WIDGET ( tb ) ) - offset );
|
||||
}
|
||||
else if ( tb->flags & TB_CENTER ) {
|
||||
int tw = textbox_get_font_width ( tb );
|
||||
x = ( ( tb->widget.w - tw - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) ) / 2;
|
||||
x += widget_padding_get_left ( WIDGET ( tb ) );
|
||||
int rem = MAX ( 0, tb->widget.w - widget_padding_get_padding_width ( WIDGET ( tb ) ) - line_width );
|
||||
x = tb->xalign * rem + widget_padding_get_left ( WIDGET ( tb ) );
|
||||
}
|
||||
// TODO check if this is still needed after flatning.
|
||||
cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
|
||||
|
|
|
@ -92,7 +92,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
textbox_set_pango_context ( "default", p );
|
||||
|
||||
|
||||
textbox *box = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "test" );
|
||||
textbox *box = textbox_create ( WIDGET_TYPE_TEXTBOX_TEXT, "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "test",0,0 );
|
||||
TASSERT ( box != NULL );
|
||||
|
||||
textbox_keybinding ( box, MOVE_END );
|
||||
|
|
Loading…
Reference in a new issue