17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-29 15:07:29 +01:00

feat(ui): imgui 1.91.9b-docking in place of 1.73: local changes of the backends carried over (glad as the gl loader, srgb and gamma of the ui, gles glsl string), BufferingBar/Spinner kept, imgui_tables in cmake; cursor position, cursor enter and focus of the main window passed to the glfw backend, which works with events now; code adapted to the api: ImGuiListClipper::Begin, BeginListBox, ImTextureID as an integer, ImageButton with an id, ImGuiKey without GetKeyIndex, logarithmic sliders in place of the removed power argument; ImGuizmo with the math operators defined before imgui.h and SetNextFrameWantCaptureMouse

This commit is contained in:
2026-10-08 20:38:13 +02:00
parent e661b9f1c7
commit 344034ec70
40 changed files with 48540 additions and 14321 deletions

View File

@@ -74,9 +74,15 @@ extern WNDPROC BaseWindowProc;
void focus_callback(GLFWwindow *window, int focus)
{
ui_layer::focus_callback(focus);
Application.on_focus_change(focus != 0);
}
void cursor_enter_callback(GLFWwindow *window, int entered)
{
ui_layer::cursor_enter_callback(entered);
}
void framebuffer_resize_callback(GLFWwindow *, int w, int h)
{
Global.fb_size = glm::ivec2(w, h);
@@ -90,6 +96,7 @@ void window_resize_callback(GLFWwindow *, int w, int h)
void cursor_pos_callback(GLFWwindow *window, double x, double y)
{
ui_layer::cursor_pos_callback(x, y);
Global.cursor_pos = glm::ivec2(x, y);
Application.on_cursor_pos(x, y);
}
@@ -1351,6 +1358,7 @@ void eu07_application::init_callbacks()
glfwSetScrollCallback(window, scroll_callback);
glfwSetCharCallback(window, char_callback);
glfwSetWindowFocusCallback(window, focus_callback);
glfwSetCursorEnterCallback(window, cursor_enter_callback);
}
int eu07_application::init_ogl()

View File

@@ -252,7 +252,7 @@ void driver_ui::render_()
ImGui::SetNextWindowSize(ImVec2(-1, -1));
if (ImGui::BeginPopupModal(popupheader, nullptr, 0))
{
if (ImGui::Button(STR_C("Resume"), ImVec2(150, 0)) || ImGui::IsKeyReleased(ImGui::GetKeyIndex(ImGuiKey_Escape)))
if (ImGui::Button(STR_C("Resume"), ImVec2(150, 0)) || ImGui::IsKeyReleased(ImGuiKey_Escape))
{
m_relay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_RELEASE, 0);
}

View File

@@ -3631,7 +3631,7 @@ void editor_mode::render_gizmo_options()
{
ImGui::SameLine();
ImGui::SetNextItemWidth(120.0f);
ImGui::SliderFloat(STR_C("Extent (m), wheel"), &Global.EditorOrthoExtent, 5.0f, 5000.0f, "%.0f", 3.0f);
ImGui::SliderFloat(STR_C("Extent (m), wheel"), &Global.EditorOrthoExtent, 5.0f, 5000.0f, "%.0f", ImGuiSliderFlags_Logarithmic);
}
ImGui::Checkbox(STR_C("Enabled"), &m_gizmo_enabled);
if (!m_gizmo_enabled)

View File

@@ -778,7 +778,8 @@ void editor_mode::render_gauge_hits()
ImGui::SameLine();
ImGui::Text("%d / %zu", m_gauge.current + 1, hits.size());
ImGui::BeginChild("gaugehits", ImVec2(0.0f, std::min(160.0f, ImGui::GetTextLineHeightWithSpacing() * hits.size() + 8.0f)), true);
ImGuiListClipper clipper(static_cast<int>(hits.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(hits.size()));
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
{

View File

@@ -1526,7 +1526,8 @@ void editor_mode::render_infra_candidates()
choose(group, false);
if (false == open)
continue;
ImGuiListClipper clipper(static_cast<int>(rows.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(rows.size()));
while (clipper.Step())
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row)
{
@@ -1602,7 +1603,8 @@ void editor_mode::render_infra_bound()
}
std::optional<std::size_t> unbind;
ImGui::BeginChild("##infrabound", ImVec2(0.f, 160.f), true);
ImGuiListClipper clipper(static_cast<int>(along.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(along.size()));
while (clipper.Step())
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row)
{

View File

@@ -467,7 +467,8 @@ void editor_mode::render_joints_body()
ImGui::SetColumnWidth(0, 90.0f);
ImGui::SetColumnWidth(1, 80.0f);
ImGui::SetColumnWidth(2, namewidth);
ImGuiListClipper clipper(static_cast<int>(listed.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(listed.size()));
while (clipper.Step())
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row)
{

View File

@@ -1433,7 +1433,7 @@ void editor_mode::render_profile_toolbar()
toggle(kPlan, STR_C("Plan curvature"), state.show_plan);
legend(kSwitchLabel, "Switches");
ImGui::SetNextItemWidth(130.0f);
ImGui::SliderFloat("##exaggeration", &state.exaggeration, 1.0f, 500.0f, STR_C("heights x%.0f"), 2.0f);
ImGui::SliderFloat("##exaggeration", &state.exaggeration, 1.0f, 500.0f, STR_C("heights x%.0f"), ImGuiSliderFlags_Logarithmic);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("Exaggeration of the heights against the lengths, also Ctrl+wheel over the plot"));
ImGui::SameLine();
@@ -1677,7 +1677,7 @@ bool editor_mode::profile_canvas_edit(profile_view const &View, bool const Hover
}
else
state.curve_grip = -1;
if ((Hovered || ImGui::IsWindowFocused()) && state.selected > 0 && state.selected + 1 < static_cast<int>(points.size()) && false == points[state.selected].joint && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Delete)))
if ((Hovered || ImGui::IsWindowFocused()) && state.selected > 0 && state.selected + 1 < static_cast<int>(points.size()) && false == points[state.selected].joint && ImGui::IsKeyPressed(ImGuiKey_Delete))
{
points.erase(points.begin() + state.selected);
state.selected = -1;

View File

@@ -1919,7 +1919,8 @@ bool editor_mode::render_road_material(char const *Label, char *Buffer, std::siz
if (filter.empty() || name.find(filter) != std::string::npos)
listed.emplace_back(&name);
ImGui::BeginChild("list", ImVec2(340.0f, 280.0f), true);
ImGuiListClipper clipper(static_cast<int>(listed.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(listed.size()));
while (clipper.Step())
{
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)

View File

@@ -290,7 +290,8 @@ void editor_mode::render_speed_body()
ImGui::BeginChild("speedresults", ImVec2(0.0f, -details), true);
ImGui::Columns(6, STR_C("speedrows"), false);
ImGui::SetColumnWidth(0, namewidth);
ImGuiListClipper clipper(static_cast<int>(listed.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(listed.size()));
while (clipper.Step())
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row)
{

View File

@@ -650,7 +650,7 @@ void nodebank_panel::render()
ImGui::InputTextWithHint(STR_C("Search"), STR_C("Search node bank"), m_nodesearch, IM_ARRAYSIZE(m_nodesearch));
// the list takes the rest of the window, but keeps a usable height when the sections above are expanded (the window scrolls then)
auto const listheight{std::max(ImGui::GetContentRegionAvail().y, ImGui::GetTextLineHeightWithSpacing() * 10.0f)};
if (ImGui::ListBoxHeader("##nodebank", ImVec2(-1, listheight)))
if (ImGui::BeginListBox("##nodebank", ImVec2(-1, listheight)))
{
auto idx{0};
auto isvisible{false};
@@ -710,7 +710,7 @@ void nodebank_panel::render()
ImGui::TextDisabled(EditorIncludes.ready().empty() ? " (none yet, describe the templates in the Include database window)" : " (no match)");
}
}
ImGui::ListBoxFooter();
ImGui::EndListBox();
}
ImGui::PopItemWidth();
}
@@ -772,7 +772,7 @@ bool nodebank_panel::set_combo(char const *Label, model_set_ref &Ref, char const
void nodebank_panel::manual_list(char const *Id, std::vector<std::string> &List, int &Selected)
{
ImGui::PushID(Id);
if (ImGui::ListBoxHeader("##list", ImVec2(-1, ImGui::GetTextLineHeightWithSpacing() * 6.5f)))
if (ImGui::BeginListBox("##list", ImVec2(-1, ImGui::GetTextLineHeightWithSpacing() * 6.5f)))
{
for (int idx = 0; idx < static_cast<int>(List.size()); ++idx)
{
@@ -784,7 +784,7 @@ void nodebank_panel::manual_list(char const *Id, std::vector<std::string> &List,
{
ImGui::TextDisabled(STR_C("(empty)"));
}
ImGui::ListBoxFooter();
ImGui::EndListBox();
}
if (ImGui::Button(STR_C("Add selected")))
{
@@ -1787,7 +1787,8 @@ void includes_panel::render_list()
static_cast<int>(EditorIncludes.ready().size()));
ImGui::BeginChild("##templates", ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 9.0f), true);
ImGuiListClipper clipper(static_cast<int>(m_listed.size()));
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(m_listed.size()));
while (clipper.Step())
{
for (auto row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row)

View File

@@ -130,6 +130,28 @@ bool ui_layer::mouse_button_callback(int button, int action, int mods)
return m_imguiio->WantCaptureMouse;
}
// the glfw backend of imgui works with events since 1.87: position, hover and focus of the window are passed to it as they come
void ui_layer::cursor_pos_callback(double x, double y)
{
if (ImGui::GetCurrentContext() == nullptr)
return;
ImGui_ImplGlfw_CursorPosCallback(m_window, x, y);
}
void ui_layer::cursor_enter_callback(int entered)
{
if (ImGui::GetCurrentContext() == nullptr)
return;
ImGui_ImplGlfw_CursorEnterCallback(m_window, entered);
}
void ui_layer::focus_callback(int focused)
{
if (ImGui::GetCurrentContext() == nullptr)
return;
ImGui_ImplGlfw_WindowFocusCallback(m_window, focused);
}
void ui_layer::imgui_style()
{
// palette shared with the MaSzyna starter: flat dark panels, thin borders, green accents
@@ -186,6 +208,9 @@ void ui_layer::imgui_style()
colors[ImGuiCol_TabActive] = rgb(accent); // also the line under the tab bar
colors[ImGuiCol_TabUnfocused] = rgb(header);
colors[ImGuiCol_TabUnfocusedActive] = rgb(accentdim);
// imgui 1.90+ marks the selected tab with a line over it as well, in the same colours
colors[ImGuiCol_TabSelectedOverline] = rgb(accent);
colors[ImGuiCol_TabDimmedSelectedOverline] = rgb(accentdim);
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
@@ -645,5 +670,5 @@ void ui_layer::render_background()
ImVec2 end_position(start_position.x + image_size.x, start_position.y + image_size.y);
// obrazek jest odwrócony w pionie – odwracamy UV
ImGui::GetBackgroundDrawList()->AddImage(reinterpret_cast<ImTextureID>(tex.get_id()), start_position, end_position, ImVec2(0, 1), ImVec2(1, 0));
ImGui::GetBackgroundDrawList()->AddImage((ImTextureID)(intptr_t)(tex.get_id()), start_position, end_position, ImVec2(0, 1), ImVec2(1, 0));
}

View File

@@ -118,6 +118,10 @@ public:
static bool char_callback(unsigned int c);
static bool scroll_callback(double xoffset, double yoffset);
static bool mouse_button_callback(int button, int action, int mods);
// state updates only, nothing to consume
static void cursor_pos_callback(double x, double y);
static void cursor_enter_callback(int entered);
static void focus_callback(int focused);
static ImFont *font_default;
static ImFont *font_mono;