Skip to content

Commit 7455ddb

Browse files
committed
[fix] scrollbar on new model implementation
1 parent 2e7585f commit 7455ddb

File tree

20 files changed

+553
-104
lines changed

20 files changed

+553
-104
lines changed

include/ekg/io/input.hpp

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

4242
struct input_t {
4343
public:
44-
float scroll_speed {0.8f};
44+
float scroll_speed {0.2f};
4545
ekg::timing_t ui_timeout_timing {};
4646
ekg::timing_t ui_scrolling_timing {};
4747
ekg::timing_t timing_last_interact {};

include/ekg/io/log.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace ekg {
1717
public:
1818
static void flush() {
1919
if (ekg::log::buffered) {
20-
#ifdef __ANDROID__
21-
__android_log_print(ANDROID_LOG_VERBOSE, "EKG", "%s", ekg::log::buffer.str().c_str());
20+
#if defined(__ANDROID__)
21+
__android_log_print(ANDROID_LOG_VERBOSE, "EKG", "%s", ekg::log::buffer.str().c_str());
2222
#else
23-
std::cout << ekg::log::buffer.str();
23+
std::cout << ekg::log::buffer.str();
2424
#endif
2525

2626
ekg::log::buffer = std::ostringstream {};
@@ -56,9 +56,10 @@ namespace ekg {
5656

5757
~log() {
5858
ekg::log::buffer << '\n';
59-
#ifdef EKG_LOG_DEBUG
60-
ekg::log::flush();
61-
std::cout << std::endl;
59+
60+
#if defined(EKG_LOG_DEBUG)
61+
ekg::log::flush();
62+
std::cout << std::endl;
6263
#endif
6364
}
6465

include/ekg/io/safety.hpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "ekg/ui/frame/frame_widget.hpp"
3333
#include "ekg/ui/label/label_widget.hpp"
3434
#include "ekg/ui/checkbox/checkbox_widget.hpp"
35+
#include "ekg/ui/scrollbar/scrollbar_widget.hpp"
3536

3637
namespace ekg::io {
3738
template<typename t>
@@ -60,6 +61,10 @@ namespace ekg {
6061
.is_visible = true
6162
};
6263

64+
ekg::properties_t *p_current_parent_properties {
65+
ekg::p_core->get_current_parent_properties()
66+
};
67+
6368
ekg::theme_t &current_global_theme {ekg::p_core->service_theme.get_current_theme()};
6469

6570
switch (descriptor.type) {
@@ -168,16 +173,43 @@ namespace ekg {
168173
break;
169174
}
170175

176+
case ekg::type::scrollbar: {
177+
ekg::scrollbar_t &scrollbar {
178+
ekg::io::any_static_cast<ekg::scrollbar_t>(
179+
&descriptor
180+
)
181+
};
182+
183+
ekg::ui::scrollbar *p_scrollbar {
184+
ekg::io::new_widget_instance<ekg::ui::scrollbar>()
185+
};
186+
187+
p_scrollbar->descriptor = scrollbar;
188+
p_scrollbar->descriptor.theme = current_global_theme.scrollbar;
189+
190+
properties.p_descriptor = &p_scrollbar->descriptor;
191+
properties.p_widget = p_scrollbar;
192+
properties.is_docknizable = false;
193+
properties.is_parentable = true;
194+
195+
p_created_widget = dynamic_cast<ekg::ui::abstract*>(p_scrollbar);
196+
197+
if (p_current_parent_properties) {
198+
p_scrollbar->descriptor.p_binded_children = &p_current_parent_properties->children;
199+
p_scrollbar->descriptor.p_binded_rect = (
200+
static_cast<ekg::ui::abstract*>(p_current_parent_properties->p_widget)->p_descriptor_rect
201+
);
202+
}
203+
204+
break;
205+
}
206+
171207
default:
172208
break;
173209
}
174210

175211
p_created_widget->properties = properties;
176212

177-
ekg::properties_t *p_current_parent_properties {
178-
ekg::p_core->get_current_parent_properties()
179-
};
180-
181213
if (
182214
p_created_widget->properties.is_parentable
183215
&&

include/ekg/layout/docknize.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace ekg::layout {
7272
float container_dimension,
7373
float offset
7474
) {
75-
return ekg::min_clamp(
75+
return ekg::clamp_min(
7676
(
7777
(side_a + (container_dimension - side_a) + offset)
7878
-

include/ekg/math/geometry.hpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,18 @@ namespace ekg {
342342
}
343343

344344
template<typename t>
345-
constexpr t min_clamp(t a, t b) {
345+
constexpr t clamp_min(t a, t b) {
346346
return a < b ? b : a;
347347
}
348348

349349
template<typename t>
350-
constexpr t max_clamp(t a, t b) {
350+
constexpr t clamp_max(t a, t b) {
351351
return a > b ? b : a;
352352
}
353353

354354
template<typename t>
355355
constexpr t clamp(t a, t b, t c) {
356-
return ekg::min_clamp(ekg::max_clamp(a, c), b);
356+
return ekg::clamp_min(ekg::clamp_max(a, c), b);
357357
}
358358

359359
template<typename t>
@@ -363,13 +363,18 @@ namespace ekg {
363363
) {
364364
const t zero {};
365365
return ekg::rect_t<t> {
366-
ekg::min_clamp<t>(rect.x, zero),
367-
ekg::min_clamp<t>(rect.y, zero),
368-
ekg::max_clamp<t>(rect.w, square),
369-
ekg::max_clamp<t>(rect.h, square)
366+
ekg::clamp_min<t>(rect.x, zero),
367+
ekg::clamp_min<t>(rect.y, zero),
368+
ekg::clamp_max<t>(rect.w, square),
369+
ekg::clamp_max<t>(rect.h, square)
370370
};
371371
}
372372

373+
template<typename t>
374+
constexpr t lerp(t x, t y, t delta) {
375+
return x + (y - x) * delta;
376+
}
377+
373378
struct rect_descriptor_t {
374379
public:
375380
ekg::rect_t<float> *p_rect {};
@@ -406,8 +411,8 @@ namespace ekg {
406411
)
407412
);
408413

409-
aligned.w = ekg::min_clamp<float>(rect.w + aligned.offset * 2, minimum_size);
410-
aligned.h = ekg::min_clamp<float>(rect.h + dimension_offset, minimum_size);
414+
aligned.w = ekg::clamp_min<float>(rect.w + aligned.offset * 2, minimum_size);
415+
aligned.h = ekg::clamp_min<float>(rect.h + dimension_offset, minimum_size);
411416
break;
412417
case ekg::axis::vertical:
413418
dimension_offset = (
@@ -424,8 +429,8 @@ namespace ekg {
424429
)
425430
);
426431

427-
aligned.h = ekg::min_clamp<float>(rect.h + aligned.offset * 2, minimum_size);
428-
aligned.w = ekg::min_clamp<float>(rect.w + dimension_offset, minimum_size);
432+
aligned.h = ekg::clamp_min<float>(rect.h + aligned.offset * 2, minimum_size);
433+
aligned.w = ekg::clamp_min<float>(rect.w + dimension_offset, minimum_size);
429434
break;
430435
}
431436
}

include/ekg/ui/checkbox/checkbox.hpp

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

2929
struct checkbox_t {
3030
public:
31-
const static ekg::flags_t box {1};
31+
constexpr static ekg::flags_t box {1};
3232
public:
3333
std::string tag {};
3434
ekg::flags_t dock {};

include/ekg/ui/scrollbar/scrollbar.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@
33

44
#include "ekg/math/geometry.hpp"
55
#include "ekg/ui/properties.hpp"
6+
#include "ekg/io/gpu.hpp"
67

78
namespace ekg {
89
struct scrollbar_theme_t {
910
public:
1011
ekg::vec4_t<float> background {};
1112
ekg::vec4_t<float> outline {};
12-
ekg::vec4_t<float> bar {};
1313
ekg::vec4_t<float> highlight {};
14+
ekg::vec4_t<float> active {};
1415
int32_t pixel_thickness {};
1516
float min_bar_size {};
17+
18+
/**
19+
* [0] ekg::scrollbar_t::horizontal
20+
* [1] ekg::scrollbar_t::vertical
21+
**/
22+
ekg::layer_t<2> layers {};
1623
};
1724

1825
struct scrollbar_t {
26+
public:
27+
constexpr static ekg::flags_t horizontal {0};
28+
constexpr static ekg::flags_t vertical {1};
1929
public:
2030
std::string tag {};
2131
ekg::vec2_t<bool> axis {true, true};
2232
std::vector<ekg::properties_t*> *p_binded_children {};
2333
ekg::rect_t<float> *p_binded_rect {};
2434
ekg::type type {ekg::type::scrollbar};
35+
ekg::scrollbar_theme_t theme {};
2536
};
2637
}
2738

include/ekg/ui/scrollbar/scrollbar_widget.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace ekg::ui {
1616
ekg::vec4_t<float> scroll {};
1717
ekg::vec2_t<float> delta {};
1818
ekg::vec2_t<float> acceleration {};
19+
20+
ekg::ui::states_t bar_horizontal_states {};
21+
ekg::ui::states_t bar_vertical_states {};
1922
public:
2023
void clamp_scroll();
2124
void reset_scroll();

src/core/runtime.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,21 @@ void ekg::runtime::init() {
155155

156156
if (this->draw_fr_normal.font_size != font_size) {
157157
this->draw_fr_small.set_size(
158-
ekg::min_clamp(
158+
ekg::clamp_min(
159159
font_size - ekg::dpi.font_offset.x,
160160
ekg::minimum_small_font_height
161161
)
162162
);
163163

164164
this->draw_fr_normal.set_size(
165-
ekg::min_clamp(
165+
ekg::clamp_min(
166166
font_size,
167167
ekg::minimum_font_height
168168
)
169169
);
170170

171171
this->draw_fr_big.set_size(
172-
ekg::min_clamp(
172+
ekg::clamp_min(
173173
font_size + ekg::dpi.font_offset.y,
174174
ekg::minimum_big_font_height
175175
)
@@ -229,11 +229,12 @@ void ekg::runtime::poll_events() {
229229
this->service_input.input
230230
};
231231

232-
bool is_on_scrolling_timeout {!ekg::reach(&input.ui_scrolling_timing, 250)};
232+
bool is_on_scrolling_timeout {!ekg::reach(&input.ui_scrolling_timing, 100)};
233233
ekg::current.unique_id *= !(input.was_pressed || input.was_released || input.has_motion);
234234

235235
if (
236-
this->p_abs_activity_widget != nullptr &&
236+
this->p_abs_activity_widget != nullptr
237+
&&
237238
(this->p_abs_activity_widget->states.is_absolute || is_on_scrolling_timeout)
238239
) {
239240

src/draw/font_renderer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ float ekg::draw::font_renderer::get_text_width(std::string_view text, int32_t &l
6868
break_text = char8 == '\n';
6969
if (break_text || (r_n_break_text = (char8 == '\r' && it < text_size && text.at(it + 1) == '\n'))) {
7070
it += static_cast<uint64_t>(r_n_break_text);
71-
largest_text_width = ekg::min_clamp(largest_text_width, text_width);
71+
largest_text_width = ekg::clamp_min(largest_text_width, text_width);
7272
text_width = 0.0f;
7373
lines_count++;
7474
continue;
@@ -115,8 +115,8 @@ float ekg::draw::font_renderer::get_text_width(std::string_view text, int32_t &l
115115
text_width += this->mapped_glyph_char_data[char32].wsize;
116116
}
117117

118-
lines = ekg::min_clamp(lines, lines_count);
119-
largest_text_width = ekg::min_clamp(largest_text_width, text_width);
118+
lines = ekg::clamp_min(lines, lines_count);
119+
largest_text_width = ekg::clamp_min(largest_text_width, text_width);
120120

121121
return largest_text_width;
122122
}
@@ -157,7 +157,7 @@ float ekg::draw::font_renderer::get_text_width(std::string_view text) {
157157
break_text = char8 == '\n';
158158
if (break_text || (r_n_break_text = (char8 == '\r' && it < text_size && text.at(it + 1) == '\n'))) {
159159
it += static_cast<uint64_t>(r_n_break_text);
160-
largest_text_width = ekg::min_clamp(largest_text_width, text_width);
160+
largest_text_width = ekg::clamp_min(largest_text_width, text_width);
161161
text_width = 0.0f;
162162
continue;
163163
}
@@ -203,7 +203,7 @@ float ekg::draw::font_renderer::get_text_width(std::string_view text) {
203203
text_width += char_data.wsize;
204204
}
205205

206-
largest_text_width = ekg::min_clamp(largest_text_width, text_width);
206+
largest_text_width = ekg::clamp_min(largest_text_width, text_width);
207207
return largest_text_width;
208208
}
209209

@@ -339,14 +339,14 @@ void ekg::draw::font_renderer::reload() {
339339
char_data.wsize = static_cast<float>(static_cast<int32_t>(ft_glyph_slot->advance.x >> 6));
340340

341341
this->atlas_rect.w += static_cast<int32_t>(char_data.w);
342-
this->atlas_rect.h = ekg::min_clamp<int32_t>(this->atlas_rect.h, static_cast<int32_t>(char_data.h));
342+
this->atlas_rect.h = ekg::clamp_min<int32_t>(this->atlas_rect.h, static_cast<int32_t>(char_data.h));
343343

344-
p_font_face_picked->highest_glyph_size.x = ekg::min_clamp(
344+
p_font_face_picked->highest_glyph_size.x = ekg::clamp_min(
345345
static_cast<int32_t>(p_font_face_picked->highest_glyph_size.x),
346346
static_cast<int32_t>(char_data.w)
347347
);
348348

349-
p_font_face_picked->highest_glyph_size.y = ekg::min_clamp(
349+
p_font_face_picked->highest_glyph_size.y = ekg::clamp_min(
350350
static_cast<int32_t>(p_font_face_picked->highest_glyph_size.y),
351351
static_cast<int32_t>(char_data.h)
352352
);

0 commit comments

Comments
 (0)