neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
slider_box.hpp
Go to the documentation of this file.
1// slider_box.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 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>
25
26namespace neogfx
27{
28 template <typename T>
29 class basic_slider_box : public widget<>
30 {
32 public:
33 typedef T value_type;
34 public:
35 define_event(ValueChanged, value_changed)
36 define_event(ConstraintsChanged, constraints_changed)
37 public:
39 widget{},
40 iLayout{ *this },
41 iSlider{ iLayout },
42 iSpinBox{ iLayout },
43 iSettingParameter{ false }
44 {
45 init();
46 }
48 widget{ aParent },
49 iLayout{ *this },
50 iSlider{ iLayout },
51 iSpinBox{ iLayout },
52 iSettingParameter{ false }
53 {
54 init();
55 }
57 widget{ aLayout },
58 iLayout{ *this },
59 iSlider{ iLayout },
60 iSpinBox{ iLayout },
61 iSettingParameter{ false }
62 {
63 init();
64 }
65 public:
66 value_type minimum() const
67 {
68 return iSlider.minimum();
69 }
70 void set_minimum(value_type aMinimum)
71 {
72 if (iSettingParameter)
73 return;
74 neolib::scoped_flag sf{ iSettingParameter };
75 iSlider.set_minimum(aMinimum);
76 iSpinBox.set_minimum(aMinimum);
77 ConstraintsChanged.trigger();
78 }
79 value_type maximum() const
80 {
81 return iSlider.maximum();
82 }
83 void set_maximum(value_type aMaximum)
84 {
85 if (iSettingParameter)
86 return;
87 neolib::scoped_flag sf{ iSettingParameter };
88 iSlider.set_maximum(aMaximum);
89 iSpinBox.set_maximum(aMaximum);
90 ConstraintsChanged.trigger();
91 }
92 value_type step() const
93 {
94 return iSlider.step();
95 }
96 void set_step(value_type aStep)
97 {
98 if (iSettingParameter)
99 return;
100 neolib::scoped_flag sf{ iSettingParameter };
101 iSlider.set_step(aStep);
102 iSpinBox.set_step(aStep);
103 ConstraintsChanged.trigger();
104 }
105 value_type value() const
106 {
107 return iSlider.value();
108 }
109 void set_value(value_type aValue)
110 {
111 if (iSettingParameter)
112 return;
113 neolib::scoped_flag sf{ iSettingParameter };
114 iSlider.set_value(aValue);
115 iSpinBox.set_value(aValue);
116 ValueChanged.trigger();
117 }
118 public:
119 const basic_slider<value_type>& slider() const
120 {
121 return iSlider;
122 }
123 basic_slider<value_type>& slider()
124 {
125 return iSlider;
126 }
128 {
129 return iSpinBox;
130 }
132 {
133 return iSpinBox;
134 }
135 private:
136 void init()
137 {
138 iSlider.ValueChanged([&]()
139 {
140 if (iSettingParameter)
141 return;
142 neolib::scoped_flag sf{ iSettingParameter };
143 iSpinBox.set_value(iSlider.value());
144 ValueChanged.trigger();
145 });
146 iSpinBox.ValueChanged([&]()
147 {
148 if (iSettingParameter)
149 return;
150 neolib::scoped_flag sf{ iSettingParameter };
151 iSlider.set_value(iSpinBox.value());
152 ValueChanged.trigger();
153 });
154 iSlider.ConstraintsChanged([&]()
155 {
156 if (iSettingParameter)
157 return;
158 neolib::scoped_flag sf{ iSettingParameter };
159 iSpinBox.set_minimum(iSlider.minimum());
160 iSpinBox.set_maximum(iSlider.maximum());
161 iSpinBox.set_step(iSlider.step());
162 ConstraintsChanged.trigger();
163 });
164 iSpinBox.ConstraintsChanged([&]()
165 {
166 if (iSettingParameter)
167 return;
168 neolib::scoped_flag sf{ iSettingParameter };
169 iSlider.set_minimum(iSpinBox.minimum());
170 iSlider.set_maximum(iSpinBox.maximum());
171 iSlider.set_step(iSpinBox.step());
172 ConstraintsChanged.trigger();
173 });
174 }
175 private:
176 horizontal_layout iLayout;
177 basic_slider<value_type> iSlider;
178 basic_spin_box<value_type> iSpinBox;
179 bool iSettingParameter;
180 };
181
184}
basic_slider< value_type > & slider()
void set_minimum(value_type aMinimum)
value_type step() const
basic_slider_box(i_layout &aLayout)
define_event(ValueChanged, value_changed) define_event(ConstraintsChanged
basic_slider_box(i_widget &aParent)
const basic_slider< value_type > & slider() const
void set_step(value_type aStep)
void set_value(value_type aValue)
value_type minimum() const
const basic_spin_box< value_type > & spin_box() const
basic_spin_box< value_type > & spin_box()
value_type value() const
value_type maximum() const
void set_maximum(value_type aMaximum)
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
void set_value(value_type aValue, bool aNotify=true)
Definition spin_box.ipp:469
void set_minimum(value_type aMinimum)
Definition spin_box.ipp:419
value_type step() const
Definition spin_box.ipp:449
value_type minimum() const
Definition spin_box.ipp:413
value_type value() const
Definition spin_box.ipp:463
basic_slider_box< double > double_slider_box
basic_slider_box< int32_t > slider_box
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200