BuGUI
BUtton Grid User Interface
Loading...
Searching...
No Matches
ctrlr_deleter.hpp
1#pragma once
2#include "base_controller.hpp"
3#include <widgets/container_widget.hpp>
4
5namespace bugui
6{
10template <typename T>
11struct ctrlr_deleter : base_controller
12{
15 {
16 if (!p.get_bool()) return;
17
18 auto d{get_deepest_held()};
19 if (d.empty()) return;
20 auto it{d.begin()};
21
22 while (it != d.end())
23 {
24 if (!(*it)->handle_Delete())
25 {
26 recursive_child_Delete(*it);
27
28 auto new_d{get_deepest_held()};
29
30 if (d == new_d)
31 {
32 it++;
33 continue;
34 }
35
36 d = new_d;
37 it = d.begin();
38 }
39 else
40 it++;
41 }
42
43 repaint();
44 }
45
46 using base_controller::base_controller;
47
48private:
49 void recursive_child_Delete(base_widget* cw)
50 {
51 auto p{cw->get_parent()};
52
53 if (p->handle_child_Delete())
54 return;
55 else
56 recursive_child_Delete(p);
57 }
58};
59
62template <has_Delete T>
63struct ctrlr_deleter<T> : base_controller
64{ using base_controller::base_controller; };
65
66} // namespace bugui
67
68
std::vector< base_widget * > get_deepest_held()
Retrieves all held items that do not have child held widgets i.e. the deepest held widget in the hier...
Provides the minimum required 2D widget functionalities.
Definition base_widget.hpp:12
virtual void repaint()
Calls for this widget to be repainted.
base_container_widget * get_parent() const
Retrieves the parent widget.
Definition base_widget.hpp:24
Definition button_presser.hpp:10
Ensures that buttons labeled Delete triggers the delete funcitonlaity on the widget tree,...
Definition ctrlr_deleter.hpp:12
void on_Delete(button_presser &p)
Handles presses on buttons labeled Delete.
Definition ctrlr_deleter.hpp:14