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

[Textbox] Add placeholder.

Fixes: #1020
This commit is contained in:
Dave Davenport 2019-12-26 14:24:10 +01:00
parent 2c56e5ca33
commit f3bb043df0
4 changed files with 44 additions and 22 deletions

View file

@ -1064,6 +1064,10 @@ color is optional, multiple highlight styles can be added like: bold underline i
.IP \(bu 2
\fBcontent\fP: Set the displayed text (String).
.IP \(bu 2
\fBplaceholder\fP: Set the displayed text (String) when nothing is entered.
.IP \(bu 2
\fBplaceholder\-color\fP: Color of the placeholder text.
.IP \(bu 2
\fBblink\fP: Enable/Disable blinking on an input textbox (Boolean).
.RE

View file

@ -650,6 +650,8 @@ The following properties are currently supported:
color is optional, multiple highlight styles can be added like: bold underline italic #000000;
* **width**: override the desired width for the textbox.
* **content**: Set the displayed text (String).
* **placeholder**: Set the displayed text (String) when nothing is entered.
* **placeholder-color**: Color of the placeholder text.
* **blink**: Enable/Disable blinking on an input textbox (Boolean).
### listview:

View file

@ -53,6 +53,8 @@ typedef struct
unsigned long flags;
short cursor;
char *text;
const char *placeholder;
int show_placeholder;
PangoLayout *layout;
int tbft;
int markup;

View file

@ -192,6 +192,10 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex
if ( !txt ){
txt = rofi_theme_get_string ( WIDGET ( tb ), "content", text );
}
const char *placeholder = rofi_theme_get_string ( WIDGET(tb), "placeholder", NULL);
if ( placeholder){
tb->placeholder = placeholder;
}
textbox_text ( tb, txt ? txt : "" );
textbox_cursor_end ( tb );
@ -264,6 +268,13 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
static void __textbox_update_pango_text ( textbox *tb )
{
pango_layout_set_attributes ( tb->layout, NULL );
if ( tb->placeholder && (tb->text == NULL || tb->text[0] == 0) )
{
tb->show_placeholder = TRUE;
pango_layout_set_text ( tb->layout, tb->placeholder, -1 );
return;
}
tb->show_placeholder = FALSE;
if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) {
size_t l = g_utf8_strlen ( tb->text, -1 );
char string [l + 1];
@ -430,6 +441,9 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
rofi_theme_get_color ( WIDGET ( tb ), "text-color", draw );
if ( tb->show_placeholder ) {
rofi_theme_get_color ( WIDGET ( tb ), "placeholder-color", draw );
}
// draw the cursor
if ( tb->flags & TB_EDITABLE && tb->blink ) {
// We want to place the cursor based on the text shown.