Skip to content

Commit 11299d9

Browse files
committed
[update] generic-tape-based slider
1 parent 4e5194d commit 11299d9

File tree

9 files changed

+328
-11
lines changed

9 files changed

+328
-11
lines changed

include/ekg/core/pools.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
#include "ekg/ui/scrollbar/scrollbar.hpp"
4545
#include "ekg/ui/scrollbar/widget.hpp"
4646

47+
#include "ekg/ui/slider/slider.hpp"
48+
#include "ekg/ui/slider/widget.hpp"
49+
4750
namespace ekg::core {
4851
void registry(ekg::property_t &property);
4952
}
@@ -66,6 +69,7 @@ namespace ekg::core {
6669
ekg_core_declare_widget_case_todo(ekg::button_t, widget_descriptor_at, ekg_core_widget_todo); \
6770
ekg_core_declare_widget_case_todo(ekg::label_t, widget_descriptor_at, ekg_core_widget_todo); \
6871
ekg_core_declare_widget_case_todo(ekg::scrollbar_t, widget_descriptor_at, ekg_core_widget_todo); \
72+
ekg_core_declare_widget_case_todo(ekg::slider_t, widget_descriptor_at, ekg_core_widget_todo); \
6973
}
7074

7175
#define ekg_registry_widget(widget_descriptor_t, register_widget_pool, register_property_pool, is_container, register_settings) \
@@ -130,6 +134,9 @@ namespace ekg {
130134

131135
ekg::pool<ekg::property_t> scrollbar_property {};
132136
ekg::pool<ekg::scrollbar_t> scrollbar {};
137+
138+
ekg::pool<ekg::property_t> slider_property {};
139+
ekg::pool<ekg::slider_t> slider {};
133140
} pools;
134141

135142
template<typename t>
@@ -167,6 +174,10 @@ namespace ekg {
167174
return ekg::io::any_static_cast<t>(
168175
&ekg::pools.scrollbar_property.query(at)
169176
);
177+
case ekg::type::slider:
178+
return ekg::io::any_static_cast<t>(
179+
&ekg::pools.slider_property.query(at)
180+
);
170181
}
171182
case ekg::type::button:
172183
return ekg::io::any_static_cast<t>(
@@ -184,6 +195,10 @@ namespace ekg {
184195
return ekg::io::any_static_cast<t>(
185196
&ekg::pools.scrollbar.query(at)
186197
);
198+
case ekg::type::slider:
199+
return ekg::io::any_static_cast<t>(
200+
&ekg::pools.slider.query(at)
201+
);
187202
}
188203

189204
return t::not_found;
@@ -250,6 +265,20 @@ namespace ekg {
250265
);
251266
}
252267

268+
case ekg::type::slider: {
269+
ekg_registry_widget(
270+
ekg::slider_t,
271+
ekg::pools.slider,
272+
ekg::pools.slider_property,
273+
false,
274+
{
275+
property.is_childnizate = false;
276+
property.is_children_docknizable = false;
277+
widget.color_scheme = global_theme.slider_color_scheme;
278+
}
279+
);
280+
}
281+
253282
case ekg::type::stack: {
254283
ekg::stack_t &stack {
255284
ekg::pools.stack.push_back(

include/ekg/handler/theme.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ekg/ui/frame/frame.hpp"
2929
#include "ekg/ui/label/label.hpp"
3030
#include "ekg/ui/scrollbar/scrollbar.hpp"
31+
#include "ekg/ui/slider/slider.hpp"
3132

3233
namespace ekg {
3334
struct theme_t {
@@ -42,6 +43,7 @@ namespace ekg {
4243
ekg::frame_color_scheme_t frame_color_scheme {};
4344
ekg::label_color_scheme_t label_color_scheme {};
4445
ekg::scrollbar_color_scheme_t scrollbar_color_scheme {};
46+
ekg::slider_color_scheme_t slider_color_scheme {};
4547
};
4648

4749
ekg::theme_t &theme(std::string tag = "");

include/ekg/io/descriptor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace ekg {
3636
button = 5,
3737
scrollbar = 6,
3838
frame = 7,
39-
label = 8
39+
slider = 8,
40+
label = 9,
4041
};
4142
}
4243

include/ekg/io/memory.hpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ namespace ekg {
158158
};
159159
}
160160

161+
namespace ekg::io {
162+
/**
163+
* @TODO: add a complete docs here please.
164+
**/
165+
template<typename t>
166+
constexpr t &any_static_cast(void *p_any) {
167+
return *static_cast<t*>(p_any);
168+
}
169+
170+
template<typename t>
171+
constexpr t *any_static_cast_as_ptr(void *p_any) {
172+
return static_cast<t*>(p_any);
173+
}
174+
}
175+
161176
/**
162177
* Value system.
163178
**/
@@ -199,6 +214,11 @@ namespace ekg {
199214
return this->p ? *this->p : this->val;
200215
}
201216

217+
template<typename s>
218+
void ownership(s *p_address) {
219+
ownership(ekg::io::any_static_cast_as_ptr<t>(p_address));
220+
}
221+
202222
void ownership(t *p_address) {
203223
if (p_address == nullptr) {
204224
return;
@@ -246,14 +266,4 @@ namespace ekg {
246266
void unmap(void *pv_address);
247267
}
248268

249-
namespace ekg::io {
250-
/**
251-
* @TODO: add a complete docs here please.
252-
**/
253-
template<typename t>
254-
constexpr t &any_static_cast(void *p_any) {
255-
return *static_cast<t*>(p_any);
256-
}
257-
}
258-
259269
#endif

include/ekg/ui/slider/slider.hpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2022-2025 Rina Wilk / vokegpu@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
#ifndef EKG_UI_SLIDER_HPP
25+
#define EKG_UI_SLIDER_HPP
26+
27+
#include "ekg/io/descriptor.hpp"
28+
#include "ekg/math/geometry.hpp"
29+
30+
namespace ekg {
31+
struct slider_color_scheme_t {
32+
public:
33+
ekg::rgba_t<uint8_t> background {};
34+
ekg::rgba_t<uint8_t> outline {};
35+
ekg::rgba_t<uint8_t> bar_background {};
36+
ekg::rgba_t<uint8_t> bar_highlight {};
37+
ekg::rgba_t<uint8_t> bar_active {};
38+
ekg::rgba_t<uint8_t> bar_outline {};
39+
ekg::rgba_t<uint8_t> text_foreground {};
40+
ekg::pixel_thickness_t bar_thickness {25};
41+
ekg::pixel_thickness_t bar_target_thickness {25};
42+
};
43+
44+
struct slider_t {
45+
public:
46+
struct range {
47+
protected:
48+
ekg::value<char[1]> memory_tape_value {};
49+
ekg::value<char[8]> memory_tape_minimum_value {};
50+
ekg::value<char[8]> memory_tape_maximum_value {};
51+
public:
52+
template<typename t>
53+
t &value() {
54+
return ekg::io::any_static_cast<t>(
55+
this->memory_tape_value.get()
56+
);
57+
}
58+
59+
template<typename t>
60+
t &value(t *p_ownership_address) {
61+
this->memory_tape_value.ownership<t>(p_ownership_address);
62+
return this->value<t>();
63+
}
64+
65+
template<typename t>
66+
t &min() {
67+
return ekg::io::any_static_cast<t>(
68+
this->memory_tape_minimum_value.get()
69+
);
70+
}
71+
72+
template<typename t>
73+
t &min(t *p_ownership_address) {
74+
this->memory_tape_minimum_value.ownership<t>(p_ownership_address);
75+
return this->min<t>();
76+
}
77+
78+
template<typename t>
79+
t &max() {
80+
return ekg::io::any_static_cast<t>(
81+
this->memory_tape_maximum_value.get()
82+
);
83+
}
84+
85+
template<typename t>
86+
t &max(t *p_ownership_address) {
87+
this->memory_tape_maximum_value.ownership<t>(p_ownership_address);
88+
return this->max<t>();
89+
}
90+
};
91+
public:
92+
static constexpr ekg::type type {ekg::type::slider};
93+
static ekg::slider_t not_found;
94+
public:
95+
ekg::at_t property_at {};
96+
public:
97+
std::string tag {};
98+
ekg::rect_t<float> rect {};
99+
ekg::flags_t dock {};
100+
std::vector<ekg::slider_t::range> ranges {};
101+
ekg::slider_color_scheme_t color_scheme {};
102+
public:
103+
ekg_descriptor(ekg::slider_t);
104+
};
105+
}
106+
107+
#endif

include/ekg/ui/slider/widget.hpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2022-2025 Rina Wilk / vokegpu@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
#ifndef EKG_UI_SLIDER_WIDGET_HPP
25+
#define EKG_UI_SLIDER_WIDGET_HPP
26+
27+
#include "slider.hpp"
28+
#include "ekg/ui/property.hpp"
29+
#include "ekg/io/event.hpp"
30+
31+
namespace ekg::ui {
32+
void reload(
33+
ekg::property_t &property,
34+
ekg::slider_t &slider
35+
);
36+
37+
void event(
38+
ekg::property_t &property,
39+
ekg::slider_t &slider,
40+
const ekg::io::stage &stage
41+
);
42+
43+
void high_frequency(
44+
ekg::property_t &property,
45+
ekg::slider_t &slider
46+
);
47+
48+
void pass(
49+
ekg::property_t &property,
50+
ekg::slider_t &slider
51+
);
52+
53+
void buffering(
54+
ekg::property_t &property,
55+
ekg::slider_t &slider
56+
);
57+
58+
void unmap(
59+
ekg::slider_t &slider
60+
);
61+
}
62+
63+
#endif

src/handler/theme/handler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ void ekg::handler::theme::init() {
6565
light_pinky_theme.scrollbar_color_scheme.bar_highlight = {245, 169, 184, 50};
6666
light_pinky_theme.scrollbar_color_scheme.bar_active = {245, 169, 184, 100};
6767

68+
light_pinky_theme.slider_color_scheme.outline = {204, 204, 204, 0};
69+
light_pinky_theme.slider_color_scheme.bar_background = {245, 169, 184, 100};
70+
light_pinky_theme.slider_color_scheme.bar_highlight = {245, 169, 184, 50};
71+
light_pinky_theme.slider_color_scheme.bar_active = {245, 169, 184, 100};
72+
6873
this->registry(light_pinky_theme.tag) = light_pinky_theme;
6974
this->set_current_theme(light_pinky_theme.tag);
7075

@@ -106,6 +111,12 @@ void ekg::handler::theme::init() {
106111
black_light_pinky_theme.scrollbar_color_scheme.bar_highlight = {245, 169, 184, 50};
107112
black_light_pinky_theme.scrollbar_color_scheme.bar_active = {245, 169, 184, 100};
108113

114+
black_light_pinky_theme.slider_color_scheme.background = {204, 204, 204, 30};
115+
black_light_pinky_theme.slider_color_scheme.outline = {204, 204, 204, 0};
116+
black_light_pinky_theme.slider_color_scheme.bar_background = {245, 169, 184, 100};
117+
black_light_pinky_theme.slider_color_scheme.bar_highlight = {245, 169, 184, 50};
118+
black_light_pinky_theme.slider_color_scheme.bar_active = {245, 169, 184, 100};
119+
109120
this->registry(black_light_pinky_theme.tag) = black_light_pinky_theme;
110121
//this->set_current_theme(black_light_pinky_theme.tag);
111122
}

src/ui/slider/slider.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2022-2025 Rina Wilk / vokegpu@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
#include "ekg/ui/slider/slider.hpp"
25+
26+
ekg::slider_t ekg::slider_t::not_found {
27+
.at = ekg::at_t::not_found
28+
};

0 commit comments

Comments
 (0)