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();
|
||||
}
|
||||
|
||||
// Should only be used in selection allowing tools
|
||||
bool DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
||||
Toolbar& t = world.main.toolbar;
|
||||
// Paste objects action only works on selection allowing tools
|
||||
std::vector<std::pair<std::string, std::function<void()>>> actions;
|
||||
actions.emplace_back("Paste Objects", [&]() {
|
||||
selection.deselect_all();
|
||||
selection.paste_clipboard(popupPos);
|
||||
bool shouldClose = false;
|
||||
t.gui.list_popup_menu("Selection popup menu", popupPos, [&]() {
|
||||
t.gui.text_label_light("Selection menu");
|
||||
if(t.gui.text_button_left_transparent("Paste", "Paste")) {
|
||||
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()) {
|
||||
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);
|
||||
return !shouldClose;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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({
|
||||
.id = clayID,
|
||||
.layout = {
|
||||
|
|
@ -907,17 +905,10 @@ bool GUIManager::action_list_popup_menu(const std::string& id, Vector2f popupPos
|
|||
}) {
|
||||
obstructing_window();
|
||||
push_id(1);
|
||||
for(auto& [actionName, actionFunc] : actions) {
|
||||
if(text_button_left_transparent(actionName, actionName)) {
|
||||
actionFunc();
|
||||
toRet = true;
|
||||
}
|
||||
}
|
||||
elemUpdate();
|
||||
pop_id();
|
||||
}
|
||||
pop_id();
|
||||
|
||||
return toRet;
|
||||
}
|
||||
|
||||
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 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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue