From ea31c11aff9d32cb402139702d974f863dcf3484 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 8 Jan 2024 17:29:18 +0000 Subject: [PATCH] LibGUI+PDFViewer: Move NumericInput into LibGUI A text box that is restricted to numbers within a range, is generally useful. Let's make it available for use! --- .../share/man/man5/GML/Widget/NumericInput.md | 19 +++++++++++++++++++ .../Applications/PDFViewer/CMakeLists.txt | 1 - .../PDFViewer/PDFViewerWidget.cpp | 2 +- .../Applications/PDFViewer/PDFViewerWidget.h | 4 ++-- Userland/Libraries/LibGUI/CMakeLists.txt | 1 + .../LibGUI}/NumericInput.cpp | 4 ++++ .../LibGUI}/NumericInput.h | 4 ++++ 7 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 Base/usr/share/man/man5/GML/Widget/NumericInput.md rename Userland/{Applications/PDFViewer => Libraries/LibGUI}/NumericInput.cpp (99%) rename Userland/{Applications/PDFViewer => Libraries/LibGUI}/NumericInput.h (97%) diff --git a/Base/usr/share/man/man5/GML/Widget/NumericInput.md b/Base/usr/share/man/man5/GML/Widget/NumericInput.md new file mode 100644 index 0000000000..dfa994d226 --- /dev/null +++ b/Base/usr/share/man/man5/GML/Widget/NumericInput.md @@ -0,0 +1,19 @@ +## Name + +GML Numeric Input Widget + +## Description + +Defines a GUI text box that only allows integers within a specified range. + +## Synopsis + +`@GUI::NumericInput` + +## Examples + +```gml +@GUI::NumericInput { + text: "23" +} +``` diff --git a/Userland/Applications/PDFViewer/CMakeLists.txt b/Userland/Applications/PDFViewer/CMakeLists.txt index e9b59a35ed..e9c235e7b4 100644 --- a/Userland/Applications/PDFViewer/CMakeLists.txt +++ b/Userland/Applications/PDFViewer/CMakeLists.txt @@ -4,7 +4,6 @@ serenity_component( ) set(SOURCES - NumericInput.cpp OutlineModel.cpp PDFViewer.cpp PDFViewerWidget.cpp diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index 3c53d0e27d..e5293153da 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -276,7 +276,7 @@ void PDFViewerWidget::initialize_toolbar(GUI::Toolbar& toolbar) toolbar.add_action(*m_go_to_prev_page_action); toolbar.add_action(*m_go_to_next_page_action); - m_page_text_box = toolbar.add(); + m_page_text_box = toolbar.add(); m_page_text_box->set_enabled(false); m_page_text_box->set_fixed_width(30); m_page_text_box->set_min_number(1); diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.h b/Userland/Applications/PDFViewer/PDFViewerWidget.h index 0cdcf32942..b19a8eb5d6 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.h +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.h @@ -6,7 +6,6 @@ #pragma once -#include "NumericInput.h" #include "PDFViewer.h" #include "SidebarWidget.h" #include @@ -14,6 +13,7 @@ #include #include #include +#include #include class PDFViewer; @@ -40,7 +40,7 @@ private: RefPtr m_sidebar; NonnullRefPtr m_paged_errors_model; RefPtr m_errors_tree_view; - RefPtr m_page_text_box; + RefPtr m_page_text_box; RefPtr m_total_page_label; RefPtr m_go_to_prev_page_action; RefPtr m_go_to_next_page_action; diff --git a/Userland/Libraries/LibGUI/CMakeLists.txt b/Userland/Libraries/LibGUI/CMakeLists.txt index 86cf325379..c1ed664f62 100644 --- a/Userland/Libraries/LibGUI/CMakeLists.txt +++ b/Userland/Libraries/LibGUI/CMakeLists.txt @@ -86,6 +86,7 @@ set(SOURCES MouseTracker.cpp MultiView.cpp Notification.cpp + NumericInput.cpp Object.cpp OpacitySlider.cpp Painter.cpp diff --git a/Userland/Applications/PDFViewer/NumericInput.cpp b/Userland/Libraries/LibGUI/NumericInput.cpp similarity index 99% rename from Userland/Applications/PDFViewer/NumericInput.cpp rename to Userland/Libraries/LibGUI/NumericInput.cpp index 1b67911b59..e08d54a2a1 100644 --- a/Userland/Applications/PDFViewer/NumericInput.cpp +++ b/Userland/Libraries/LibGUI/NumericInput.cpp @@ -7,6 +7,8 @@ #include "NumericInput.h" #include +namespace GUI { + NumericInput::NumericInput() { set_text("0"sv); @@ -87,3 +89,5 @@ void NumericInput::set_current_number(i32 number, GUI::AllowCallback allow_callb if (on_number_changed && allow_callback == GUI::AllowCallback::Yes) on_number_changed(m_current_number); } + +} diff --git a/Userland/Applications/PDFViewer/NumericInput.h b/Userland/Libraries/LibGUI/NumericInput.h similarity index 97% rename from Userland/Applications/PDFViewer/NumericInput.h rename to Userland/Libraries/LibGUI/NumericInput.h index 8be85d7754..3559681f23 100644 --- a/Userland/Applications/PDFViewer/NumericInput.h +++ b/Userland/Libraries/LibGUI/NumericInput.h @@ -9,6 +9,8 @@ #include #include +namespace GUI { + class NumericInput final : public GUI::TextBox { C_OBJECT(NumericInput) public: @@ -29,3 +31,5 @@ private: i32 m_min_number { NumericLimits::min() }; i32 m_max_number { NumericLimits::max() }; }; + +}