From 7a5407982f9183f302f1cbd98e1005d60a3e4af0 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Sun, 23 May 2021 21:05:35 +0200 Subject: [PATCH] Calculator: Show decimal point immediately when typed --- Userland/Applications/Calculator/Keypad.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/Calculator/Keypad.cpp b/Userland/Applications/Calculator/Keypad.cpp index c1c2acf8d3..8881518769 100644 --- a/Userland/Applications/Calculator/Keypad.cpp +++ b/Userland/Applications/Calculator/Keypad.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2019-2020, Sergey Bugaev + * Copyright (c) 2021, Max Wipfli * * SPDX-License-Identifier: BSD-2-Clause */ @@ -144,10 +145,14 @@ String Keypad::to_string() const builder.append("-"); builder.appendff("{}", m_int_value); + // NOTE: This is so the decimal point appears on screen as soon as you type it. + if (m_frac_length > 0 || m_state == State::TypingDecimal) + builder.append('.'); + if (m_frac_length > 0) { // FIXME: This disables the compiletime format string check since we can't parse '}}' here correctly. // remove the 'StringView { }' when that's fixed. - builder.appendff(StringView { ".{:0{}}" }, m_frac_value, m_frac_length); + builder.appendff(StringView { "{:0{}}" }, m_frac_value, m_frac_length); } return builder.to_string();