Generalize list popup function
This commit is contained in:
parent
303dac19a4
commit
f227e074f8
3 changed files with 28 additions and 30 deletions
|
|
@ -226,27 +226,34 @@ void DrawingProgram::toolbar_gui() {
|
||||||
t.gui.pop_id();
|
t.gui.pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should only be used in selection allowing tools
|
||||||
bool DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
bool DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
||||||
Toolbar& t = world.main.toolbar;
|
Toolbar& t = world.main.toolbar;
|
||||||
// Paste objects action only works on selection allowing tools
|
bool shouldClose = false;
|
||||||
std::vector<std::pair<std::string, std::function<void()>>> actions;
|
t.gui.list_popup_menu("Selection popup menu", popupPos, [&]() {
|
||||||
actions.emplace_back("Paste Objects", [&]() {
|
t.gui.text_label_light("Selection menu");
|
||||||
selection.deselect_all();
|
if(t.gui.text_button_left_transparent("Paste", "Paste")) {
|
||||||
selection.paste_clipboard(popupPos);
|
selection.deselect_all();
|
||||||
|
selection.paste_clipboard(popupPos);
|
||||||
|
shouldClose = true;
|
||||||
|
}
|
||||||
|
if(selection.is_something_selected()) {
|
||||||
|
if(t.gui.text_button_left_transparent("Copy", "Copy")) {
|
||||||
|
selection.selection_to_clipboard();
|
||||||
|
shouldClose = true;
|
||||||
|
}
|
||||||
|
if(t.gui.text_button_left_transparent("Cut", "Cut")) {
|
||||||
|
selection.selection_to_clipboard();
|
||||||
|
selection.delete_all();
|
||||||
|
shouldClose = true;
|
||||||
|
}
|
||||||
|
if(t.gui.text_button_left_transparent("Delete", "Delete")) {
|
||||||
|
selection.delete_all();
|
||||||
|
shouldClose = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if(selection.is_something_selected()) {
|
return !shouldClose;
|
||||||
actions.emplace_back("Copy Selection", [&]() {
|
|
||||||
selection.selection_to_clipboard();
|
|
||||||
});
|
|
||||||
actions.emplace_back("Cut Selection", [&]() {
|
|
||||||
selection.selection_to_clipboard();
|
|
||||||
selection.delete_all();
|
|
||||||
});
|
|
||||||
actions.emplace_back("Delete Selection", [&]() {
|
|
||||||
selection.delete_all();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return !t.gui.action_list_popup_menu("General popup menu", popupPos, actions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrawingProgram::right_click_popup_gui(Vector2f popupPos) {
|
bool DrawingProgram::right_click_popup_gui(Vector2f popupPos) {
|
||||||
|
|
|
||||||
|
|
@ -870,7 +870,7 @@ void GUIManager::paint_circle_popup_menu(const std::string& id, const Vector2f&
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GUIManager::action_list_popup_menu(const std::string& id, Vector2f popupPos, const std::vector<std::pair<std::string, std::function<void()>>>& actions) {
|
void GUIManager::list_popup_menu(const std::string& id, Vector2f popupPos, const std::function<void()>& elemUpdate) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
|
|
||||||
std::string& uniqueID = insert_any_with_id_with_function<std::string>(0, [&]() {
|
std::string& uniqueID = insert_any_with_id_with_function<std::string>(0, [&]() {
|
||||||
|
|
@ -886,8 +886,6 @@ bool GUIManager::action_list_popup_menu(const std::string& id, Vector2f popupPos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool toRet = false;
|
|
||||||
|
|
||||||
CLAY({
|
CLAY({
|
||||||
.id = clayID,
|
.id = clayID,
|
||||||
.layout = {
|
.layout = {
|
||||||
|
|
@ -907,17 +905,10 @@ bool GUIManager::action_list_popup_menu(const std::string& id, Vector2f popupPos
|
||||||
}) {
|
}) {
|
||||||
obstructing_window();
|
obstructing_window();
|
||||||
push_id(1);
|
push_id(1);
|
||||||
for(auto& [actionName, actionFunc] : actions) {
|
elemUpdate();
|
||||||
if(text_button_left_transparent(actionName, actionName)) {
|
|
||||||
actionFunc();
|
|
||||||
toRet = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
pop_id();
|
pop_id();
|
||||||
|
|
||||||
return toRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::obstructing_window() {
|
void GUIManager::obstructing_window() {
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class GUIManager {
|
||||||
void dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width = 200.0f, const std::function<void()>& hoverboxElemUpdate = nullptr);
|
void dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width = 200.0f, const std::function<void()>& hoverboxElemUpdate = nullptr);
|
||||||
|
|
||||||
void paint_circle_popup_menu(const std::string& id, const Vector2f& centerPos, const PaintCircleMenu::Data& val, const std::function<void()>& elemUpdate = nullptr);
|
void paint_circle_popup_menu(const std::string& id, const Vector2f& centerPos, const PaintCircleMenu::Data& val, const std::function<void()>& elemUpdate = nullptr);
|
||||||
bool action_list_popup_menu(const std::string& id, Vector2f popupPos, const std::vector<std::pair<std::string, std::function<void()>>>& actions);
|
void list_popup_menu(const std::string& id, Vector2f popupPos, const std::function<void()>& elemUpdate);
|
||||||
|
|
||||||
void obstructing_window();
|
void obstructing_window();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue