From 35afd32a51c56e3c425f1f27f2cff5f45df7912d Mon Sep 17 00:00:00 2001 From: RasmusNylander <43042651+rasmusnylander@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:07:53 +0100 Subject: [PATCH] KeyboardMapper: Fix displaying null characters Fixes a bug where KeyButtons would display null characters. A single null character should be handled as an empty string. --- .../Applications/KeyboardMapper/KeyButton.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Userland/Applications/KeyboardMapper/KeyButton.cpp b/Userland/Applications/KeyboardMapper/KeyButton.cpp index 8632929953..712849897b 100644 --- a/Userland/Applications/KeyboardMapper/KeyButton.cpp +++ b/Userland/Applications/KeyboardMapper/KeyButton.cpp @@ -40,14 +40,15 @@ void KeyButton::paint_event(GUI::PaintEvent& event) painter.draw_rect(key_cap_face_border_rect, Color::from_rgb(0x8C7272), false); painter.fill_rect(key_cap_face_rect, face_color); - if (!text().is_empty()) { - Gfx::IntRect text_rect { 0, 0, font.width(text()), font.glyph_height() }; - text_rect.align_within(key_cap_face_rect, Gfx::TextAlignment::Center); + if (text().is_empty() || text().starts_with('\0')) + return; - painter.draw_text(text_rect, text(), font, Gfx::TextAlignment::Center, Color::Black, Gfx::TextElision::Right); - if (is_focused()) - painter.draw_rect(text_rect.inflated(6, 4), palette().focus_outline()); - } + Gfx::IntRect text_rect { 0, 0, font.width(text()), font.glyph_height() }; + text_rect.align_within(key_cap_face_rect, Gfx::TextAlignment::Center); + + painter.draw_text(text_rect, text(), font, Gfx::TextAlignment::Center, Color::Black, Gfx::TextElision::Right); + if (is_focused()) + painter.draw_rect(text_rect.inflated(6, 4), palette().focus_outline()); } void KeyButton::click(unsigned)