mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:28:12 +00:00
LibGUI: Add optional placeholder to TextEditor
This lets you show some disabled text when no text is entered, and the editor is not focused.
This commit is contained in:
parent
5b6ccbb918
commit
fa96e57c15
4 changed files with 19 additions and 1 deletions
|
@ -461,7 +461,12 @@ void TextEditor::paint_event(PaintEvent& event)
|
|||
#ifdef DEBUG_TEXTEDITOR
|
||||
painter.draw_rect(visual_line_rect, Color::Cyan);
|
||||
#endif
|
||||
if (!document().has_spans()) {
|
||||
|
||||
if (!placeholder().is_empty() && document().is_empty() && !is_focused() && line_index == 0) {
|
||||
auto line_rect = visual_line_rect;
|
||||
line_rect.set_width(font().width(placeholder()));
|
||||
painter.draw_text(line_rect, placeholder(), m_text_alignment, palette().color(Gfx::ColorRole::DisabledText));
|
||||
} else if (!document().has_spans()) {
|
||||
// Fast-path for plain text
|
||||
auto color = palette().color(is_enabled() ? foreground_role() : Gfx::ColorRole::DisabledText);
|
||||
if (is_displayonly() && (is_focused() || has_visible_list()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue