Skip to content

Commit d3346db

Browse files
committed
[fix] popup self-destroy
1 parent 98d687d commit d3346db

File tree

7 files changed

+58
-36
lines changed

7 files changed

+58
-36
lines changed

include/ekg/core/pools.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ namespace ekg {
307307
true,
308308
{
309309
property.is_childnizate = true;
310+
property.is_stack_top_level = true;
310311
property.is_children_docknizable = true;
311312
property.states.is_visible = false;
313+
312314
widget.color_scheme = global_theme.popup_color_scheme;
313315
}
314316
);

include/ekg/ui/popup/popup.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace ekg {
3737
ekg::at_t popup_opened_at {ekg::at_t::not_found};
3838
bool was_visible {};
3939
bool just_opened {};
40+
bool should_self_recursive_destroy {};
4041
};
4142

4243
struct link_t {

include/ekg/ui/property.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace ekg {
8181

8282
bool is_childnizate {};
8383
bool is_children_docknizable {};
84+
bool is_stack_top_level {};
85+
8486
std::vector<ekg::at_t> children {};
8587
public:
8688
ekg::property_t::states_t states {};

src/core/runtime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ void ekg::core::swap_collector(
4242

4343
if (
4444
parent_property.at == ekg::gui.bind.swap_at
45+
||
46+
parent_property.is_stack_top_level
4547
) {
4648
was_found = true;
4749
}
@@ -88,7 +90,7 @@ void ekg::core::swap(ekg::info_t &info) {
8890
ekg::p_core->collector.clear();
8991
ekg::core::swap_collector(was_found, at);
9092

91-
if (ekg::p_core->top_level_stack.empty() && was_found) {
93+
if (was_found) {
9294
ekg::p_core->top_level_stack.insert(
9395
ekg::p_core->top_level_stack.begin(),
9496
ekg::p_core->collector.begin(),

src/ekg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ void ekg::render() {
136136
}
137137

138138
if (ekg::gui.ui.redraw) {
139+
ekg::gui.ui.redraw = false;
140+
139141
ekg::p_core->draw_allocator.invoke();
140142

141143
for (ekg::at_t &at : ekg::p_core->stack) {
@@ -185,6 +187,5 @@ void ekg::render() {
185187
ekg::p_core->draw_allocator.revoke();
186188
}
187189

188-
ekg::gui.ui.redraw = false;
189190
ekg::p_core->draw_allocator.to_gpu();
190191
}

src/ui/popup/popup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ekg::show(
4848
);
4949

5050
ekg::io::dispatch(
51-
ekg::io::operation::high_frequency,
51+
ekg::io::operation::swap,
5252
popup.property_at
5353
);
5454
}

src/ui/popup/widget.cpp

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@
3030
void ekg::ui::recursive_self_destroy_abs_popup(
3131
ekg::popup_t &popup
3232
) {
33-
if (popup.parent_popup_at == ekg::at_t::not_found) {
34-
ekg::ui::recursive_children_set_visible(
35-
popup,
36-
false
37-
);
33+
if (popup == ekg::popup_t::not_found) {
3834
return;
3935
}
4036

37+
ekg::property_t &property {ekg::query<ekg::property_t>(popup.property_at)};
38+
ekg::ui::set_visible(
39+
property,
40+
false
41+
);
42+
43+
property.widget.should_buffering = false;
44+
4145
ekg::ui::recursive_self_destroy_abs_popup(
4246
ekg::query<ekg::popup_t>(popup.parent_popup_at)
4347
);
@@ -99,10 +103,19 @@ void ekg::ui::splash_popup_just_opened(
99103
const ekg::vec2_t<float> &pos
100104
) {
101105
ekg::property_t &property {ekg::query<ekg::property_t>(popup.property_at)};
102-
if (popup == ekg::popup_t::not_found || property == ekg::property_t::not_found) {
106+
if (
107+
popup == ekg::popup_t::not_found
108+
||
109+
property == ekg::property_t::not_found
110+
) {
103111
return;
104112
}
105113

114+
ekg::ui::recursive_children_set_visible(
115+
popup,
116+
false
117+
);
118+
106119
property.states.is_visible = true;
107120
popup.widget.was_visible = true;
108121
ekg::gui.ui.redraw = true;
@@ -174,11 +187,13 @@ void ekg::ui::event(
174187
ekg::input_info_t &input {ekg::p_core->handler_input.input};
175188
ekg::vec2_t<float> interact {static_cast<ekg::vec2_t<float>>(input.interact)};
176189

190+
bool skip_this_tick_self_destruction {};
177191
if (
178192
popup.widget.just_opened
179193
&&
180194
input.was_released
181195
) {
196+
skip_this_tick_self_destruction = true;
182197
popup.widget.just_opened = false;
183198
}
184199

@@ -204,7 +219,6 @@ void ekg::ui::event(
204219
bool should_unset_visibility {};
205220
bool is_linked_hovering {};
206221
bool is_this_popup_being_hovered {};
207-
bool should_self_recursive_destroy {};
208222
bool is_hovering_any_linked_widget {};
209223

210224
ekg::rect_t<float> rect_position {};
@@ -354,34 +368,26 @@ void ekg::ui::event(
354368
);
355369
}
356370

357-
should_self_recursive_destroy = (
358-
(
359-
input.was_released
360-
&&
361-
is_this_popup_being_hovered
362-
&&
363-
popup.links.empty()
364-
)
365-
||
366-
(
367-
input.was_released
368-
&&
369-
is_this_popup_being_hovered
370-
&&
371-
!is_hovering_any_linked_widget
372-
)
373-
||
371+
if (
374372
(
375-
input.was_pressed
376-
&&
377-
!is_hovering_a_popup
373+
(
374+
input.was_released
375+
&&
376+
is_this_popup_being_hovered
377+
&&
378+
!is_hovering_any_linked_widget
379+
)
380+
||
381+
(
382+
input.was_released
383+
&&
384+
!is_hovering_a_popup
385+
)
378386
)
379-
);
380-
381-
if (should_self_recursive_destroy) {
382-
ekg::ui::recursive_self_destroy_abs_popup(
383-
popup
384-
);
387+
&&
388+
!skip_this_tick_self_destruction
389+
) {
390+
popup.widget.should_self_recursive_destroy = true;
385391
}
386392

387393
break;
@@ -403,6 +409,14 @@ void ekg::ui::pass(
403409
ekg::property_t &property,
404410
ekg::popup_t &popup
405411
) {
412+
if (popup.widget.should_self_recursive_destroy) {
413+
ekg::ui::recursive_self_destroy_abs_popup(
414+
popup
415+
);
416+
417+
popup.widget.should_self_recursive_destroy = false;
418+
}
419+
406420
ekg::ui::pass(property, popup.widget.frame);
407421
}
408422

0 commit comments

Comments
 (0)