neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
spin_box.hpp
Go to the documentation of this file.
1// spin_box.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
27
28namespace neogfx
29{
30 template <typename T>
32 {
34 public:
35 define_event(ValueChanged, value_changed)
36 define_event(ConstraintsChanged, constraints_changed)
37 public:
38 typedef T value_type;
39 private:
40 enum class step_direction
41 {
42 Up,
43 Down
44 };
45 public:
46 static constexpr size INTERNAL_SPACING = { 2.0, 0.0 };
47 static constexpr size SPIN_BUTTON_MINIMUM_SIZE = { 13.0, 9.0 };
48 public:
50 basic_spin_box(i_widget& aParent);
51 basic_spin_box(i_layout& aLayout);
52 public:
53 i_string const& text();
54 const line_edit& text_box() const;
56 void show_arrows();
57 void hide_arrows();
58 public:
59 value_type minimum() const;
60 void set_minimum(value_type aMinimum);
61 value_type maximum() const;
62 void set_maximum(value_type aMaximum);
63 value_type step() const;
64 void set_step(value_type aStep);
65 value_type value() const;
66 void set_value(value_type aValue, bool aNotify = true);
67 std::string const& format() const;
68 void set_format(std::string const& aFormat);
69 const std::optional<size_hint>& text_box_size_hint() const;
70 void set_text_box_size_hint(const std::optional<size_hint>& aSizeHint);
71 public:
72 std::string const& valid_text_characters() const;
73 std::string value_to_string() const;
74 protected:
75 neogfx::size_policy size_policy() const override;
76 protected:
77 color palette_color(color_role aColorRole) const override;
78 protected:
79 color frame_color() const override;
80 protected:
81 bool mouse_wheel_scrolled(mouse_wheel aWheel, const point& aPosition, delta aDelta, key_modifiers_e aKeyModifiers) override;
82 protected:
83 bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override;
84 private:
85 void do_step(step_direction aDirection, uint32_t aAmount = 1);
86 std::optional<value_type> string_to_value(std::string const& aString) const;
87 void init();
88 void update_size_hint();
89 void update_arrows();
90 private:
91 sink iSink;
92 string iText;
93 cursor::position_type iTextCursorPos;
94 horizontal_layout iPrimaryLayout;
95 line_edit iTextBox;
96 vertical_layout iSecondaryLayout;
97 push_button iStepUpButton;
98 push_button iStepDownButton;
99 std::optional<widget_timer> iStepper;
100 mutable std::optional<std::pair<color, texture>> iUpArrow;
101 mutable std::optional<std::pair<color, texture>> iDownArrow;
102 value_type iMinimum;
103 value_type iMaximum;
104 value_type iStep;
105 value_type iValue;
106 std::string iFormat;
107 std::optional<size_hint> iTextBoxSizeHint;
108 bool iDontSetText = false;
109 };
110
111 extern template class basic_spin_box<int8_t>;
112 extern template class basic_spin_box<uint8_t>;
113 extern template class basic_spin_box<int16_t>;
114 extern template class basic_spin_box<uint16_t>;
115 extern template class basic_spin_box<int32_t>;
116 extern template class basic_spin_box<uint32_t>;
117 extern template class basic_spin_box<int64_t>;
118 extern template class basic_spin_box<uint64_t>;
119 extern template class basic_spin_box<float>;
120 extern template class basic_spin_box<double>;
121
132
134}
color frame_color() const override
Definition spin_box.ipp:104
i_string const & text()
Definition spin_box.ipp:139
void set_step(value_type aStep)
Definition spin_box.ipp:455
value_type maximum() const
Definition spin_box.ipp:433
void set_maximum(value_type aMaximum)
Definition spin_box.ipp:439
static constexpr size INTERNAL_SPACING
Definition spin_box.hpp:46
void set_value(value_type aValue, bool aNotify=true)
Definition spin_box.ipp:469
void set_text_box_size_hint(const std::optional< size_hint > &aSizeHint)
Definition spin_box.ipp:505
color palette_color(color_role aColorRole) const override
Definition spin_box.ipp:94
static constexpr size SPIN_BUTTON_MINIMUM_SIZE
Definition spin_box.hpp:47
void set_minimum(value_type aMinimum)
Definition spin_box.ipp:419
void set_format(std::string const &aFormat)
Definition spin_box.ipp:491
value_type step() const
Definition spin_box.ipp:449
value_type minimum() const
Definition spin_box.ipp:413
neogfx::size_policy size_policy() const override
Definition spin_box.ipp:84
const line_edit & text_box() const
Definition spin_box.ipp:145
std::string const & valid_text_characters() const
Definition spin_box.ipp:512
value_type value() const
Definition spin_box.ipp:463
const std::optional< size_hint > & text_box_size_hint() const
Definition spin_box.ipp:499
bool mouse_wheel_scrolled(mouse_wheel aWheel, const point &aPosition, delta aDelta, key_modifiers_e aKeyModifiers) override
Definition spin_box.ipp:110
std::string const & format() const
Definition spin_box.ipp:485
std::string value_to_string() const
Definition spin_box.ipp:540
bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override
Definition spin_box.ipp:122
anchor_changed define_event(AppearanceChanged, appearance_changed) public typedef std::size_t position_type
Definition cursor.hpp:43
basic_spin_box< float > float_spin_box
Definition spin_box.hpp:130
basic_spin_box< uint16_t > uint16_spin_box
Definition spin_box.hpp:125
int32_spin_box spin_box
Definition spin_box.hpp:133
basic_spin_box< int32_t > int32_spin_box
Definition spin_box.hpp:126
basic_spin_box< uint64_t > uint64_spin_box
Definition spin_box.hpp:129
mouse_wheel
Definition i_mouse.hpp:42
basic_spin_box< uint32_t > uint32_spin_box
Definition spin_box.hpp:127
basic_spin_box< double > double_spin_box
Definition spin_box.hpp:131
basic_spin_box< int16_t > int16_spin_box
Definition spin_box.hpp:124
basic_spin_box< uint8_t > uint8_spin_box
Definition spin_box.hpp:123
basic_spin_box< int64_t > int64_spin_box
Definition spin_box.hpp:128
basic_spin_box< int8_t > int8_spin_box
Definition spin_box.hpp:122
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200