Imgui dialogs for undo/redo centered on their toolbar item icon

This commit is contained in:
Enrico Turri 2019-07-10 13:45:25 +02:00
parent 40a1f31e84
commit 14dad5039a
3 changed files with 6 additions and 7 deletions

View file

@ -3477,8 +3477,7 @@ void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x)
ImGuiWrapper* imgui = wxGetApp().imgui(); ImGuiWrapper* imgui = wxGetApp().imgui();
const float x = pos_x * (float)get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width(); const float x = pos_x * (float)get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width();
imgui->set_next_window_pos(x, m_toolbar.get_height(), ImGuiCond_Always); imgui->set_next_window_pos(x, m_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f);
imgui->set_next_window_bg_alpha(0.5f); imgui->set_next_window_bg_alpha(0.5f);
imgui->begin(wxString::Format(_(L("%s Stack")), stack_name), imgui->begin(wxString::Format(_(L("%s Stack")), stack_name),
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
@ -3688,7 +3687,7 @@ bool GLCanvas3D::_init_toolbar()
item.action_callback = [this]() { if (m_canvas != nullptr) m_toolbar.set_imgui_hovered_pos(-1); }; item.action_callback = [this]() { if (m_canvas != nullptr) m_toolbar.set_imgui_hovered_pos(-1); };
item.visibility_callback = []()->bool { return true; }; item.visibility_callback = []()->bool { return true; };
item.enabled_state_callback = [this]()->bool { return wxGetApp().plater()->can_undo(); } ; item.enabled_state_callback = [this]()->bool { return wxGetApp().plater()->can_undo(); } ;
item.render_callback = [this](float pos_x, float, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(true, pos_x); }; item.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(true, 0.5f * (left + right)); };
if (!m_toolbar.add_item(item)) if (!m_toolbar.add_item(item))
return false; return false;
@ -3699,7 +3698,7 @@ bool GLCanvas3D::_init_toolbar()
item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]"; item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]";
item.sprite_id = 12; item.sprite_id = 12;
item.enabled_state_callback = [this]()->bool { return wxGetApp().plater()->can_redo(); }; item.enabled_state_callback = [this]()->bool { return wxGetApp().plater()->can_redo(); };
item.render_callback = [this](float pos_x, float, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(false, pos_x); }; item.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(false, 0.5f * (left + right)); };
if (!m_toolbar.add_item(item)) if (!m_toolbar.add_item(item))
return false; return false;

View file

@ -233,9 +233,9 @@ ImVec2 ImGuiWrapper::calc_text_size(const wxString &text)
return size; return size;
} }
void ImGuiWrapper::set_next_window_pos(float x, float y, int flag) void ImGuiWrapper::set_next_window_pos(float x, float y, int flag, float pivot_x, float pivot_y)
{ {
ImGui::SetNextWindowPos(ImVec2(x, y), (ImGuiCond)flag); ImGui::SetNextWindowPos(ImVec2(x, y), (ImGuiCond)flag, ImVec2(pivot_x, pivot_y));
ImGui::SetNextWindowSize(ImVec2(0.0, 0.0)); ImGui::SetNextWindowSize(ImVec2(0.0, 0.0));
} }

View file

@ -51,7 +51,7 @@ public:
ImVec2 scaled(float x, float y) const { return ImVec2(x * m_font_size, y * m_font_size); } ImVec2 scaled(float x, float y) const { return ImVec2(x * m_font_size, y * m_font_size); }
ImVec2 calc_text_size(const wxString &text); ImVec2 calc_text_size(const wxString &text);
void set_next_window_pos(float x, float y, int flag); void set_next_window_pos(float x, float y, int flag, float pivot_x = 0.0f, float pivot_y = 0.0f);
void set_next_window_bg_alpha(float alpha); void set_next_window_bg_alpha(float alpha);
bool begin(const std::string &name, int flags = 0); bool begin(const std::string &name, int flags = 0);