Next improvements of an undo/redo from a toolbar

This commit is contained in:
YuSanka 2019-07-09 15:27:28 +02:00
parent fbf14b42e9
commit 1347e655c2
8 changed files with 113 additions and 53 deletions

View file

@ -3442,6 +3442,41 @@ bool GLCanvas3D::_is_shown_on_screen() const
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
}
// Getter for the const char*[]
static bool string_getter(const bool is_undo, int idx, const char** out_text)
{
return wxGetApp().plater()->undo_redo_string_getter(is_undo, idx, out_text);
}
void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x)
{
if (m_canvas != nullptr && m_toolbar.get_imgui_visible(is_undo))
{
const wxString& stack_name = _(is_undo ? L("Undo") : L("Redo"));
ImGuiWrapper* imgui = wxGetApp().imgui();
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_bg_alpha(0.5f);
imgui->begin(wxString::Format(_(L("%s Stack")), stack_name),
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
int hovered = m_toolbar.get_imgui_hovered_pos();
int selected = -1;
const float em = static_cast<float>(wxGetApp().em_unit());
if (imgui->undo_redo_list(ImVec2(12 * em, 20 * em), is_undo, &string_getter, hovered, selected))
m_toolbar.set_imgui_hovered_pos(hovered);
if (selected >= 0)
m_toolbar.hide_imgui(is_undo);
imgui->text(wxString::Format(_(L("%s %d Action")), stack_name, hovered + 1));
imgui->end();
}
}
bool GLCanvas3D::_init_toolbar()
{
if (!m_toolbar.is_enabled())
@ -3627,37 +3662,19 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]";
item.sprite_id = 11;
item.action_callback = [this]()
{
item.is_toggable = false;
item.action_callback = [this]() {
if (m_canvas != nullptr) {
wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_UNDO));
m_toolbar.set_imgui_visible();
m_toolbar.activate_imgui(true);
}
};
item.visibility_callback = []()->bool { return true; };
item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_undo(); };
item.render_callback = [this]()
{
if (m_canvas != nullptr && m_toolbar.get_imgui_visible()) {
ImGuiWrapper* imgui = wxGetApp().imgui();
const float approx_height = m_toolbar.get_height();
imgui->set_next_window_pos(600, approx_height, ImGuiCond_Always);
imgui->set_next_window_bg_alpha(0.5f);
imgui->begin(_(L("Undo Stack")), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
std::vector <std::string> undo_stack = {"A", "B", "C", "D","A", "B", "C", "D","A", "B", "C", "D",};
int sel = 4;
imgui->multi_sel_list("", undo_stack, sel);
const bool undo_clicked = imgui->button(_(L("Undo N Action")));
imgui->end();
if (undo_clicked)
m_toolbar.set_imgui_visible(false);
}
item.enabled_state_callback = [this]()->bool {
if (!wxGetApp().plater()->can_undo()) { m_toolbar.hide_imgui(true); return false; }
return true;
};
item.render_callback = [this](float pos_x, float, float, float) { _render_undo_redo_stack(true, pos_x); };
if (!m_toolbar.add_item(item))
return false;
@ -3667,15 +3684,20 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]";
item.sprite_id = 12;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_REDO)); };
item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_redo(); };
item.render_callback = []() {};
item.action_callback = [this]() {
if (m_canvas != nullptr) {
wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_REDO));
m_toolbar.activate_imgui(false);
}
};
item.enabled_state_callback = [this]()->bool {
if (!wxGetApp().plater()->can_redo()) { m_toolbar.hide_imgui(false); return false; }
return true;
};
item.render_callback = [this](float pos_x, float, float, float) { _render_undo_redo_stack(false, pos_x); };
if (!m_toolbar.add_item(item))
return false;
if (!m_toolbar.add_separator())
return false;
return true;
}