change windows position on one line only

This commit is contained in:
Filip Sykala 2021-11-22 09:42:31 +01:00
parent 8a44a754ca
commit f4ad435ec5

View File

@ -218,27 +218,29 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
start_process = true; start_process = true;
// set window position // set window position
if (m_move_to_center && change_window_position) { if (change_window_position) {
m_move_to_center = false; ImVec2 pos;
auto parent_size = m_parent.get_canvas_size(); Size parent_size = m_parent.get_canvas_size();
ImVec2 pos(parent_size.get_width() / 2 - m_gui_cfg->window_offset_x, if (m_move_to_center) {
parent_size.get_height() / 2 - m_gui_cfg->window_offset_y); m_move_to_center = false;
ImGui::SetNextWindowPos(pos, ImGuiCond_Always); pos = ImVec2(parent_size.get_width() / 2 - m_gui_cfg->window_offset_x,
}else if (change_window_position) { parent_size.get_height() / 2 - m_gui_cfg->window_offset_y);
ImVec2 pos = ImGui::GetMousePos(); } else {
pos.x -= m_gui_cfg->window_offset_x; // keep window wisible on canvas and close to mouse click
pos.y -= m_gui_cfg->window_offset_y; pos = ImGui::GetMousePos();
// minimal top left value pos.x -= m_gui_cfg->window_offset_x;
ImVec2 tl(m_gui_cfg->window_padding, m_gui_cfg->window_padding); pos.y -= m_gui_cfg->window_offset_y;
if (pos.x < tl.x) pos.x = tl.x; // minimal top left value
if (pos.y < tl.y) pos.y = tl.y; ImVec2 tl(m_gui_cfg->window_padding,
// maximal bottom right value m_gui_cfg->window_padding);
auto parent_size = m_parent.get_canvas_size(); if (pos.x < tl.x) pos.x = tl.x;
ImVec2 br( if (pos.y < tl.y) pos.y = tl.y;
parent_size.get_width() - (2 * m_gui_cfg->window_offset_x + m_gui_cfg->window_padding), // maximal bottom right value
parent_size.get_height() - (2 * m_gui_cfg->window_offset_y + m_gui_cfg->window_padding)); ImVec2 br(parent_size.get_width() - (2 * m_gui_cfg->window_offset_x + m_gui_cfg->window_padding),
if (pos.x > br.x) pos.x = br.x; parent_size.get_height() -(2 * m_gui_cfg->window_offset_y + m_gui_cfg->window_padding));
if (pos.y > br.y) pos.y = br.y; if (pos.x > br.x) pos.x = br.x;
if (pos.y > br.y) pos.y = br.y;
}
ImGui::SetNextWindowPos(pos, ImGuiCond_Always); ImGui::SetNextWindowPos(pos, ImGuiCond_Always);
} }
} }