Skip to content

Commit b26a0de

Browse files
authored
[feature] scrollbar widget (#45)
-- Fixed a critic issue where no ending buffers occurs if any gpu-data is out of scissor. -- Widgets states are apart from property. -- Added scrolling widget.
1 parent bc2f479 commit b26a0de

File tree

25 files changed

+1327
-100
lines changed

25 files changed

+1327
-100
lines changed

cmake/properties.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(EKG_VERSION 2.2.0)
1+
set(EKG_VERSION 2.3.0)
22
set(EKG_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
33

44
if(CMAKE_TOOLCHAIN_FILE)

include/ekg/core/pools.hpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include "ekg/ui/label/label.hpp"
4242
#include "ekg/ui/label/widget.hpp"
4343

44+
#include "ekg/ui/scrollbar/scrollbar.hpp"
45+
#include "ekg/ui/scrollbar/widget.hpp"
46+
4447
namespace ekg::core {
4548
void registry(ekg::property_t &property);
4649
}
@@ -62,6 +65,7 @@ namespace ekg::core {
6265
ekg_core_declare_widget_case_todo(ekg::frame_t, widget_descriptor_at, ekg_core_widget_todo); \
6366
ekg_core_declare_widget_case_todo(ekg::button_t, widget_descriptor_at, ekg_core_widget_todo); \
6467
ekg_core_declare_widget_case_todo(ekg::label_t, widget_descriptor_at, ekg_core_widget_todo); \
68+
ekg_core_declare_widget_case_todo(ekg::scrollbar_t, widget_descriptor_at, ekg_core_widget_todo); \
6569
}
6670

6771
#define ekg_registry_widget(widget_descriptor_t, register_widget_pool, register_property_pool, is_container, register_settings) \
@@ -123,6 +127,9 @@ namespace ekg {
123127

124128
ekg::pool<ekg::property_t> label_property {};
125129
ekg::pool<ekg::label_t> label {};
130+
131+
ekg::pool<ekg::property_t> scrollbar_property {};
132+
ekg::pool<ekg::scrollbar_t> scrollbar {};
126133
} pools;
127134

128135
template<typename t>
@@ -156,6 +163,10 @@ namespace ekg {
156163
return ekg::io::any_static_cast<t>(
157164
&ekg::pools.label_property.query(at)
158165
);
166+
case ekg::type::scrollbar:
167+
return ekg::io::any_static_cast<t>(
168+
&ekg::pools.scrollbar_property.query(at)
169+
);
159170
}
160171
case ekg::type::button:
161172
return ekg::io::any_static_cast<t>(
@@ -169,6 +180,10 @@ namespace ekg {
169180
return ekg::io::any_static_cast<t>(
170181
&ekg::pools.label.query(at)
171182
);
183+
case ekg::type::scrollbar:
184+
return ekg::io::any_static_cast<t>(
185+
&ekg::pools.scrollbar.query(at)
186+
);
172187
}
173188

174189
return t::not_found;
@@ -186,8 +201,8 @@ namespace ekg {
186201
ekg::pools.frame_property,
187202
true,
188203
{
189-
property.widget.is_childnizate = true;
190-
property.widget.is_children_docknizable = true;
204+
property.is_childnizate = true;
205+
property.is_children_docknizable = true;
191206
widget.color_scheme = global_theme.frame_color_scheme;
192207
}
193208
);
@@ -200,8 +215,8 @@ namespace ekg {
200215
ekg::pools.button_property,
201216
false,
202217
{
203-
property.widget.is_childnizate = false;
204-
property.widget.is_children_docknizable = false;
218+
property.is_childnizate = false;
219+
property.is_children_docknizable = false;
205220
widget.color_scheme = global_theme.button_color_scheme;
206221
}
207222
);
@@ -212,14 +227,29 @@ namespace ekg {
212227
ekg::label_t,
213228
ekg::pools.label,
214229
ekg::pools.label_property,
215-
true,
230+
false,
216231
{
217-
property.widget.is_childnizate = false;
218-
property.widget.is_children_docknizable = false;
232+
property.is_childnizate = false;
233+
property.is_children_docknizable = false;
219234
widget.color_scheme = global_theme.label_color_scheme;
220235
}
221236
);
222237
}
238+
239+
case ekg::type::scrollbar: {
240+
ekg_registry_widget(
241+
ekg::scrollbar_t,
242+
ekg::pools.scrollbar,
243+
ekg::pools.scrollbar_property,
244+
false,
245+
{
246+
property.is_childnizate = false;
247+
property.is_children_docknizable = false;
248+
widget.color_scheme = global_theme.scrollbar_color_scheme;
249+
}
250+
);
251+
}
252+
223253
case ekg::type::stack: {
224254
ekg::stack_t &stack {
225255
ekg::pools.stack.push_back(
@@ -240,7 +270,7 @@ namespace ekg {
240270
)
241271
);
242272
case ekg::type::sampler:
243-
return ekg::io::any_static_cast<t>(
273+
return ekg::io::any_static_cast<t>(
244274
&ekg::pools.sampler.push_back(
245275
ekg::io::any_static_cast<ekg::sampler_t>(&descriptor)
246276
)

include/ekg/draw/allocator.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,28 @@
3131
#include "ekg/gpu/sampler.hpp"
3232

3333
/**
34-
* This macro prevent from dispatching any GPU-data under a render section
35-
* if the content is not visible to the parent rect_scissor.
34+
* Each rendering section must begin with this, so we can do smart-caching
35+
* for CPU-side.
3636
**/
37-
#define ekg_draw_allocator_assert_scissor(rect_scissor, rect_child, rect_parent, is_parented) \
38-
if (!ekg::p_core->draw_allocator.sync_scissor(rect_scissor, rect_child, rect_parent, is_parented)) return;
39-
4037
#define ekg_draw_allocator_bind_local(p_geometry_buffer, p_gpu_data_buffer) \
4138
ekg::p_core->draw_allocator.bind_local(p_geometry_buffer, p_gpu_data_buffer);
4239

40+
/**
41+
* Each rendering section must end with this, for send buffers to GPU.
42+
**/
4343
#define ekg_draw_allocator_pass() \
4444
ekg::p_core->draw_allocator.pass(); \
4545
return;
4646

47+
/**
48+
* This macro prevent from dispatching any GPU-data under a render section
49+
* if the content is not visible to the parent rect_scissor.
50+
**/
51+
#define ekg_draw_allocator_assert_scissor(rect_scissor, rect_child, rect_parent, is_parented) \
52+
if (!ekg::p_core->draw_allocator.sync_scissor(rect_scissor, rect_child, rect_parent, is_parented)) { \
53+
ekg_draw_allocator_pass(); \
54+
};
55+
4756
namespace ekg::draw {
4857
class allocator {
4958
public:

include/ekg/handler/input.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ekg {
6060

6161
struct input_info_t {
6262
public:
63-
float scroll_speed {0.4f};
63+
float scroll_speed {1.0f};
6464
ekg::timing_t ui_timeout_timing {};
6565
ekg::timing_t ui_scrolling_timing {};
6666
ekg::timing_t timing_last_interact {};

include/ekg/handler/theme.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "ekg/ui/button/button.hpp"
2828
#include "ekg/ui/frame/frame.hpp"
2929
#include "ekg/ui/label/label.hpp"
30+
#include "ekg/ui/scrollbar/scrollbar.hpp"
3031

3132
namespace ekg {
3233
struct theme_t {
@@ -40,10 +41,11 @@ namespace ekg {
4041
ekg::button_color_scheme_t button_color_scheme {};
4142
ekg::frame_color_scheme_t frame_color_scheme {};
4243
ekg::label_color_scheme_t label_color_scheme {};
44+
ekg::scrollbar_color_scheme_t scrollbar_color_scheme {};
4345
};
4446

45-
ekg::theme_t &theme(std::string_view tag = "");
46-
ekg::theme_t &set_current_theme(std::string_view tag);
47+
ekg::theme_t &theme(std::string tag = "");
48+
ekg::theme_t &set_current_theme(const std::string &tag);
4749
}
4850

4951
#endif

include/ekg/handler/theme/handler.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
namespace ekg::handler {
3333
class theme {
3434
protected:
35-
std::string_view current_theme_tag {"dark-theme"};
36-
std::map<std::string_view, ekg::theme_t> themes {};
35+
std::string current_theme_tag {"dark-theme"};
36+
std::map<std::string, ekg::theme_t> themes {};
3737
public:
3838
void init();
3939
void quit();
4040

41-
ekg::theme_t &registry(const std::string_view &tag);
41+
ekg::theme_t &registry(const std::string &tag);
4242
ekg::theme_t &get_current_theme();
43-
ekg::theme_t &set_current_theme(const std::string_view &tag);
43+
ekg::theme_t &set_current_theme(const std::string &tag);
4444
};
4545
}
4646

include/ekg/io/event.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ namespace ekg {
5151
hover,
5252
active,
5353
press,
54-
release
54+
release,
55+
drag,
56+
resize
5557
};
56-
constexpr size_t enum_action_size {static_cast<size_t>(ekg::action::release)+1};
58+
constexpr size_t enum_action_size {static_cast<size_t>(ekg::action::resize)+1};
5759

5860
template<typename t, size_t s>
5961
struct at_array_t {

include/ekg/math/geometry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ namespace ekg {
284284
}
285285

286286
template<typename s>
287-
ekg::rect_t<t> operator + (ekg::vec4_t<s> vec) {
287+
ekg::rect_t<t> operator + (const ekg::vec4_t<s> &vec) {
288288
return ekg::rect_t<t> {
289289
this->x + static_cast<t>(vec.x),
290290
this->y + static_cast<t>(vec.y),

include/ekg/ui/button/button.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ekg/io/font.hpp"
2929
#include "ekg/math/geometry.hpp"
3030
#include "ekg/io/event.hpp"
31+
#include "ekg/ui/property.hpp"
3132

3233
namespace ekg {
3334
struct button_color_scheme_t {
@@ -51,8 +52,6 @@ namespace ekg {
5152
public:
5253
struct widget_t {
5354
public:
54-
bool is_highlight {};
55-
bool is_active {};
5655
ekg::rect_t<float> rect_text {};
5756
ekg::rect_t<float> rect_box {};
5857
};
@@ -63,6 +62,7 @@ namespace ekg {
6362
ekg::flags_t box {ekg::dock::none};
6463
ekg::flags_t dock {ekg::dock::left};
6564
ekg::button_t::check_t::widget_t widget {};
65+
ekg::property_t::states_t states {};
6666
ekg::at_array_t<ekg::layer, ekg::enum_layer_size> layers {};
6767
ekg::at_array_t<ekg::action, ekg::enum_action_size> actions {};
6868
};

include/ekg/ui/label/label.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace ekg {
5050
ekg::at_t property_at {};
5151
public:
5252
std::string tag {};
53-
ekg::rect_t<float> rect {};
53+
ekg::rect_t<float> rect {0.0f, 0.0f, 75.0f, 0.0f};
5454
ekg::value<std::string> text {};
5555
ekg::flags_t dock {};
5656
ekg::flags_t dock_text {};

0 commit comments

Comments
 (0)