1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05: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

@ -1043,28 +1043,32 @@ The offset of the window to the anchor point, allowing you to push the window le
.SS textbox:
.RS
.IP \(bu 2
\fBbackground\-color\fP: color
\fBbackground\-color\fP: color
.IP \(bu 2
\fBborder\-color\fP: the color used for the border around the widget.
\fBborder\-color\fP: the color used for the border around the widget.
.IP \(bu 2
\fBfont\fP: the font used by this textbox (string).
\fBfont\fP: the font used by this textbox (string).
.IP \(bu 2
\fBstr\fP: the string to display by this textbox (string).
\fBstr\fP: the string to display by this textbox (string).
.IP \(bu 2
\fBvertical\-align\fP: vertical alignment of the text (\fB\fC0\fR top, \fB\fC1\fR bottom).
\fBvertical\-align\fP: vertical alignment of the text (\fB\fC0\fR top, \fB\fC1\fR bottom).
.IP \(bu 2
\fBhorizontal\-align\fP: horizontal alignment of the text (\fB\fC0\fR left, \fB\fC1\fR right).
\fBhorizontal\-align\fP: horizontal alignment of the text (\fB\fC0\fR left, \fB\fC1\fR right).
.IP \(bu 2
\fBtext\-color\fP: the text color to use.
\fBtext\-color\fP: the text color to use.
.IP \(bu 2
\fBhighlight\fP: text style {color}.
\fBhighlight\fP: text style {color}.
color is optional, multiple highlight styles can be added like: bold underline italic #000000;
.IP \(bu 2
\fBwidth\fP: override the desired width for the textbox.
\fBwidth\fP: override the desired width for the textbox.
.IP \(bu 2
\fBcontent\fP: Set the displayed text (String).
\fBcontent\fP: Set the displayed text (String).
.IP \(bu 2
\fBblink\fP: Enable/Disable blinking on an input textbox (Boolean).
\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

@ -639,18 +639,20 @@ The following properties are currently supported:
### textbox:
* **background-color**: color
* **border-color**: the color used for the border around the widget.
* **font**: the font used by this textbox (string).
* **str**: the string to display by this textbox (string).
* **vertical-align**: vertical alignment of the text (`0` top, `1` bottom).
* **horizontal-align**: horizontal alignment of the text (`0` left, `1` right).
* **text-color**: the text color to use.
* **highlight**: text style {color}.
* **background-color**: color
* **border-color**: the color used for the border around the widget.
* **font**: the font used by this textbox (string).
* **str**: the string to display by this textbox (string).
* **vertical-align**: vertical alignment of the text (`0` top, `1` bottom).
* **horizontal-align**: horizontal alignment of the text (`0` left, `1` right).
* **text-color**: the text color to use.
* **highlight**: text style {color}.
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).
* **blink**: Enable/Disable blinking on an input textbox (Boolean).
* **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:
* **columns**: integer

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.