Skip to content

Commit 4078b58

Browse files
committed
[update] splash rect and specialized macro for unique widget
1 parent 9faaa1c commit 4078b58

File tree

8 files changed

+145
-1
lines changed

8 files changed

+145
-1
lines changed

include/ekg/core/pools.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ namespace ekg::core {
7676
ekg_core_widget_call_impl(ekg::popup_t, widget_descriptor_at, todo); \
7777
}
7878

79+
#define ekg_core_unique_widget_call(descriptor_t, widget_descriptor_type, widget_descriptor_at, todo) \
80+
switch (widget_descriptor_type) { \
81+
ekg_core_widget_call_impl(descriptor_t, widget_descriptor_at, todo); \
82+
}
83+
7984
#define ekg_registry_widget(widget_descriptor_t, register_widget_pool, register_property_pool, is_container, register_settings) \
8085
widget_descriptor_t &widget { \
8186
register_widget_pool.push_back( \

include/ekg/ui/frame/frame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace ekg {
3232
struct frame_color_scheme_t {
3333
public:
3434
ekg::pixel_thickness_t actions_margin_pixel_thickness {5};
35+
ekg::pixel_t popup_offset {2.0f};
3536
ekg::pixel_t margin {2.0f};
3637
ekg::rgba_t<uint8_t> background {};
3738
ekg::rgba_t<uint8_t> highlight {};

include/ekg/ui/popup/popup.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ namespace ekg {
4040
struct link_t {
4141
public:
4242
std::string tag {};
43-
ekg::at_t descriptor_at {};
43+
ekg::at_t popup_at {};
44+
ekg::at_t widget_at {};
4445
};
4546
public:
4647
static ekg::popup_t not_found;
4748
static constexpr ekg::type type {ekg::type::popup};
4849
public:
50+
ekg::at_t parent_popup_at {};
4951
ekg::at_t property_at {};
5052
public:
5153
std::string tag {};

include/ekg/ui/popup/widget.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
#include "ekg/ui/property.hpp"
2626

2727
namespace ekg::ui {
28+
void splash_popup_but_bounding(
29+
float &popup_offset,
30+
ekg::rect_t<float> &rect_widget,
31+
ekg::rect_t<float> &rect_parent,
32+
ekg::rect_t<float> &rect_child
33+
);
34+
2835
void reload(
2936
ekg::property_t &property,
3037
ekg::popup_t &popup

src/ekg.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ void ekg::render() {
151151
property.descriptor_at.flags,
152152
property.descriptor_at,
153153

154+
ekg::ui::get_abs_rect(property, descriptor.rect);
155+
if (!property.states.is_visible) {
156+
break;
157+
}
158+
154159
/**
155160
* @TODO: Fix this stupid glitch where scrolling is jittering because of something
156161
*

src/ui/abstract.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ ekg::rect_t<float> &ekg::ui::get_abs_rect(
3434
ekg::query<ekg::property_t>(property.parent_at)
3535
};
3636

37+
if (parent != ekg::property_t::not_found) {
38+
property.states.is_visible = parent.states.is_visible;
39+
}
40+
3741
return (
3842
property.widget.rect = (
3943
descriptor_rect + parent.widget.rect + parent.scroll.position

src/ui/button/widget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ void ekg::ui::event(
274274
)
275275
);
276276

277+
property.states.is_highlight = is_hovering_any;
278+
property.states.is_active = is_active_any;
279+
277280
break;
278281
}
279282
case ekg::io::stage::pre:

src/ui/popup/widget.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@
2323
*/
2424
#include "ekg/ui/popup/widget.hpp"
2525
#include "ekg/ui/frame/widget.hpp"
26+
#include "ekg/core/runtime.hpp"
27+
#include "ekg/core/pools.hpp"
28+
#include "ekg/core/context.hpp"
29+
30+
void ekg::ui::splash_popup_but_bounding(
31+
float &popup_offset,
32+
ekg::rect_t<float> &rect_widget,
33+
ekg::rect_t<float> &rect_parent,
34+
ekg::rect_t<float> &rect_child
35+
) {
36+
ekg::rect_t<float> preview {};
37+
38+
preview.w = rect_parent.x + rect_parent.w + popup_offset;
39+
rect_child.x = preview.w;
40+
41+
if (preview.w + rect_child.w > ekg::dpi.viewport.w) {
42+
rect_child.x = rect_parent.x - rect_parent.w - popup_offset;
43+
}
44+
45+
preview.h = rect_widget.y;
46+
rect_child.y = preview.h;
47+
48+
if (preview.h + rect_child.h > ekg::dpi.viewport.h) {
49+
preview.h += rect_child.h;
50+
rect_child.y = rect_widget.y - (preview.h - ekg::dpi.viewport.h);
51+
}
52+
}
2653

2754
void ekg::ui::reload(
2855
ekg::property_t &property,
@@ -37,6 +64,96 @@ void ekg::ui::event(
3764
const ekg::io::stage &stage
3865
) {
3966
ekg::ui::event(property, popup.widget.frame, stage);
67+
popup.rect = popup.widget.frame.rect;
68+
69+
switch (stage) {
70+
case ekg::io::stage::post: {
71+
ekg::input_info_t &input {ekg::p_core->handler_input.input};
72+
ekg::vec2_t<float> interact {static_cast<ekg::vec2_t<float>>(input.interact)};
73+
74+
if (
75+
!input.has_motion
76+
&&
77+
!input.was_pressed
78+
&&
79+
!input.was_released
80+
) {
81+
break;
82+
}
83+
84+
bool exists {};
85+
bool preview_popup {};
86+
ekg::rect_t<float> rect_position {};
87+
88+
for (ekg::popup_t::link_t &link : popup.links) {
89+
exists = false;
90+
91+
ekg_core_widget_call(
92+
link.widget_at.flags,
93+
link.widget_at,
94+
{
95+
ekg::property_t &wproperty {ekg::query<ekg::property_t>(descriptor.property_at)};
96+
if (wproperty.states.is_highlight) {
97+
preview_popup = true;
98+
rect_position = wproperty.widget.rect;
99+
}
100+
101+
exists = true;
102+
}
103+
);
104+
105+
// @TODO: ref this thanks
106+
if (!exists) {
107+
for (ekg::at_t &at : property.children) {
108+
ekg_core_widget_call(
109+
at.flags,
110+
at,
111+
{
112+
if (descriptor.tag == link.tag) {
113+
exists = true;
114+
link.widget_at = at;
115+
}
116+
}
117+
);
118+
119+
if (exists) {
120+
break;
121+
}
122+
}
123+
124+
continue;
125+
}
126+
127+
ekg_core_unique_widget_call(
128+
ekg::popup_t,
129+
link.popup_at.flags,
130+
link.popup_at,
131+
{
132+
ekg::property_t &wproperty {ekg::query<ekg::property_t>(descriptor.property_at)};
133+
134+
descriptor.parent_popup_at = popup.at;
135+
wproperty.states.is_visible = false;
136+
137+
if (preview_popup) {
138+
wproperty.states.is_visible = true;
139+
140+
splash_popup_but_bounding(
141+
popup.color_scheme.popup_offset,
142+
rect_position,
143+
popup.rect,
144+
descriptor.widget.frame.rect
145+
);
146+
}
147+
}
148+
);
149+
}
150+
151+
break;
152+
}
153+
154+
default:
155+
break;
156+
}
40157
}
41158

42159
void ekg::ui::high_frequency(

0 commit comments

Comments
 (0)