diff --git a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp index dbf8ff14..9d5014e4 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp @@ -18,6 +18,7 @@ #include "lidar_odometry.h" #include "lidar_odometry_utils.h" #include "render_cache.h" +#include "trajectory_follow.h" #include #include @@ -54,90 +55,40 @@ std::vector infoLines = { "", "It results trajectory and point clouds as single session for 'multi_view_tls_registration_step_2' program.", "", + "The camera follows the processing head smoothly by default.", + "Orbit, zoom and pan keep the current pivot attached.", + "Double left click explores around the nearest trajectory point on screen.", + "Double right click returns smoothly to the processing head.", + "During SLAM, exploration ends after the inactivity delay set in Progress.", + "After SLAM, there is no automatic return; use double right click.", + "F1 shows or hides this help. Controls / Help opens it during a run.", + "", "Next step will be to load session.json file with 'multi_view_tls_registration_step_2' program." }; -// App specific shortcuts (Type and Shortcut are just for easy reference) -static const std::vector appShortcuts = { { "Normal keys", "A", "" }, - { "", "Ctrl+A", "" }, - { "", "B", "" }, - { "", "Ctrl+B", "" }, - { "", "C", "" }, - { "", "Ctrl+C", "" }, - { "", "D", "" }, - { "", "Ctrl+D", "" }, - { "", "E", "" }, - { "", "Ctrl+E", "" }, - { "", "F", "" }, - { "", "Ctrl+F", "" }, - { "", "G", "" }, - { "", "Ctrl+G", "" }, - { "", "H", "" }, - { "", "Ctrl+H", "" }, - { "", "I", "" }, - { "", "Ctrl+I", "" }, - { "", "J", "" }, - { "", "Ctrl+K", "" }, - { "", "K", "" }, - { "", "Ctrl+K", "" }, - { "", "L", "" }, - { "", "Ctrl+L", "" }, - { "", "M", "" }, - { "", "Ctrl+M", "" }, - { "", "N", "" }, - { "", "Ctrl+N", "" }, - { "", "O", "" }, - { "", "Ctrl+O", "Open data" }, - { "", "P", "" }, - { "", "Ctrl+P", "" }, - { "", "Q", "" }, - { "", "Ctrl+Q", "" }, - { "", "R", "" }, - { "", "Ctrl+R", "" }, - { "", "Shift+R", "" }, - { "", "S", "" }, - { "", "Ctrl+S", "" }, - { "", "Ctrl+Shift+S", "" }, - { "", "T", "" }, - { "", "Ctrl+T", "" }, - { "", "U", "" }, - { "", "Ctrl+U", "" }, - { "", "V", "" }, - { "", "Ctrl+V", "" }, - { "", "W", "" }, - { "", "Ctrl+W", "" }, - { "", "X", "" }, - { "", "Ctrl+X", "" }, - { "", "Y", "" }, - { "", "Ctrl+Y", "" }, - { "", "Z", "" }, - { "", "Ctrl+Z", "" }, - { "", "Shift+Z", "" }, - { "", "1-9", "" }, - { "Special keys", "Up arrow", "" }, - { "", "Shift + up arrow", "" }, - { "", "Ctrl + up arrow", "" }, - { "", "Down arrow", "" }, - { "", "Shift + down arrow", "" }, - { "", "Ctrl + down arrow", "" }, - { "", "Left arrow", "" }, - { "", "Shift + left arrow", "" }, - { "", "Ctrl + left arrow", "" }, - { "", "Right arrow", "" }, - { "", "Shift + right arrow", "" }, - { "", "Ctrl + right arrow", "" }, - { "", "Pg down", "" }, - { "", "Pg up", "" }, - { "", "- key", "" }, - { "", "+ key", "" }, - { "Mouse related", "Left click + drag", "" }, - { "", "Right click + drag", "n" }, - { "", "Scroll", "" }, - { "", "Shift + scroll", "" }, - { "", "Shift + drag", "" }, - { "", "Ctrl + left click", "" }, - { "", "Ctrl + right click", "" }, - { "", "Ctrl + middle click", "" } }; +// List only implemented controls; the same help is available during loading and processing. +static const std::vector appShortcuts = { { "Help", "F1", "Show / hide controls and help" }, + { "Mouse", "Left drag", "Orbit around current pivot" }, + { "", "Right drag", "Pan; keep pivot attached" }, + { "", "Scroll", "Zoom; keep pivot attached" }, + { "", "Shift + scroll", "Faster zoom in perspective view" }, + { "", "Double left click", "Explore nearest trajectory point" }, + { "", "Double right click", "Return to processing head" }, + { "Camera", "Ctrl + arrows", "Rotate camera" }, + { "", "Shift + arrows", "Pan camera" }, + { "", "F / B", "Front / back view" }, + { "", "L / R", "Left / right view" }, + { "", "T / U", "Top / bottom view" }, + { "", "I", "Isometric view" }, + { "", "Z", "Reset camera" }, + { "", "Shift + Z", "Toggle Z lock in perspective view" }, + { "Display", "O", "Toggle orthographic / perspective view" }, + { "", "C", "Show / hide compass and ruler" }, + { "", "X", "Show / hide axes" }, + { "", "1-9", "Set point size" }, + { "Data", "Ctrl + O", "Load and process data when idle" }, + { "Free exploration", "Shift + R", "Open rotation-center coordinates" }, + { "", "Ctrl + right/middle click", "Choose rotation center on Z=0" } }; namespace fs = std::filesystem; @@ -179,6 +130,17 @@ bool trajectory_points_dirty = true; // GUI-thread edits; worker changes are ide // Only display fields are copied; raw IMU, timestamps and point-cache paths stay with the worker. std::mutex trajectory_preview_mutex; std::shared_ptr> trajectory_preview; +std::optional processing_head; // protected by trajectory_preview_mutex +step1_render::TrajectoryFollow trajectory_follow; + +void publish_processing_head(const Eigen::Vector3d& position) +{ + const auto p = position.cast().eval(); + if (!p.allFinite()) + return; + std::scoped_lock lock(trajectory_preview_mutex); + processing_head = Vector3{ p.x(), p.y(), p.z() }; +} void publish_trajectory_preview(const std::vector& source, bool force) { @@ -223,6 +185,7 @@ std::vector> pointsPerFile; Imu imu_data; Trajectory trajectory; std::atomic loRunning{ false }; +std::atomic loComputing{ false }; // excludes loading and export std::atomic loProgress{ 0.0 }; std::atomic loPause{ false }; std::atomic loParked{ false }; //!< step 2 is waiting on loPause and touches no file (see compute_step_2) @@ -1783,6 +1746,9 @@ void progress_window() { ImGui::Begin("Progress", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + if (ImGui::SmallButton("Controls / Help (F1)")) + info_gui = true; + ImGui::Text(("Working directory:\n'" + working_directory + "'").c_str()); recording_span_gui(); @@ -1832,6 +1798,13 @@ void progress_window() ImGui::Text("%s", timeInfo); resources_gui(); + ImGui::SliderFloat("Resume after inactivity", &trajectory_follow.idleSeconds, 1.f, 30.f, "%.0f s"); + if (!loComputing) + ImGui::TextDisabled("Camera: automatic following off (double right click to return)"); + else + ImGui::TextUnformatted( + trajectory_follow.exploring() ? "Camera: exploring (double right click to return)" : "Camera: smooth following"); + #ifdef _WIN32 // Update Windows taskbar progress if (progress > 0.01f && progress < 1.0f) @@ -1918,6 +1891,12 @@ static void launchPipeline(const std::string& folder, bool compute, bool save) loPause = false; loParked = false; loProgress = 0; + loComputing = false; + trajectory_follow.reset(GetTime()); + { + std::scoped_lock lock(trajectory_preview_mutex); + processing_head.reset(); + } loQuitting = false; if (!folder.empty()) { @@ -1953,7 +1932,9 @@ static void launchPipeline(const std::string& folder, bool compute, bool save) { if (compute) { + loComputing = true; step2(loPause); + loComputing = false; if (!step_2_done) throw std::runtime_error("Odometry failed"); } @@ -1997,6 +1978,7 @@ static void launchPipeline(const std::string& folder, bool compute, bool save) completionMessage += "\nCould not save failure report."; } } + loComputing = false; loLoading = false; loRunning = false; }); @@ -2104,11 +2086,20 @@ void display() { ClearBackground(LIGHTGRAY); rlImGuiBegin(); + if (ImGui::IsKeyPressed(ImGuiKey_F1, false)) + info_gui = !info_gui; ImGui::Begin("Loading data", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + if (ImGui::SmallButton("Controls / Help (F1)")) + info_gui = true; ImGui::Text("Loading and preparing: %s", pendingLoadFolder.c_str()); recording_span_gui(); resources_gui(); ImGui::End(); + if (info_gui) + { + infoLines[infoLines.size() - 2] = "Preparing data: " + pendingLoadFolder; + info_window(infoLines, appShortcuts); + } rlImGuiEnd(); return; // initial_points, m_g and buckets are being initialized; never read them concurrently } @@ -2128,10 +2119,10 @@ void display() } } const bool trajectory_running = loRunning.load(); - const auto preview = [] // retain an immutable snapshot for this whole frame + const auto [preview, head] = [] // retain an immutable snapshot for this whole frame { std::scoped_lock lock(trajectory_preview_mutex); - return trajectory_preview; + return std::make_pair(trajectory_preview, processing_head); }(); static const std::vector empty_preview; const auto& display_workers = !trajectory_running ? worker_data : preview ? *preview : empty_preview; @@ -2145,7 +2136,15 @@ void display() rlMatrixMode(RL_PROJECTION); rlLoadIdentity(); - updateCameraTransition(); + trajectory_follow.update( + camera, + head, + loComputing && !loPause && !loParked, + ImGui::IsAnyItemActive() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel) || + IsMouseButtonDown(MOUSE_BUTTON_LEFT) || IsMouseButtonDown(MOUSE_BUTTON_RIGHT) || IsMouseButtonDown(MOUSE_BUTTON_MIDDLE), + IsWindowFocused(), + GetTime(), + GetFrameTime()); reshape((int)io.DisplaySize.x, (int)io.DisplaySize.y); @@ -2221,22 +2220,14 @@ void display() { rlBegin(RL_LINES); rlColor3f(1, 0, 0); - if (display_workers.size() > 0) + if (head) { - const auto& wd = display_workers[display_workers.size() - 1]; - if (wd.intermediate_trajectory.size() > 0) - { - const auto& it = wd.intermediate_trajectory[wd.intermediate_trajectory.size() - 1]; - - rlVertex3f(it(0, 3) - 1, it(1, 3), it(2, 3)); - rlVertex3f(it(0, 3) + 1, it(1, 3), it(2, 3)); - - rlVertex3f(it(0, 3), it(1, 3) - 1, it(2, 3)); - rlVertex3f(it(0, 3), it(1, 3) + 1, it(2, 3)); - - rlVertex3f(it(0, 3), it(1, 3), it(2, 3) - 1); - rlVertex3f(it(0, 3), it(1, 3), it(2, 3) + 1); - } + rlVertex3f(head->x - 1, head->y, head->z); + rlVertex3f(head->x + 1, head->y, head->z); + rlVertex3f(head->x, head->y - 1, head->z); + rlVertex3f(head->x, head->y + 1, head->z); + rlVertex3f(head->x, head->y, head->z - 1); + rlVertex3f(head->x, head->y, head->z + 1); } rlEnd(); } @@ -2322,8 +2313,29 @@ void display() rlImGuiBegin(); + if (ImGui::IsKeyPressed(ImGuiKey_F1, false)) + info_gui = !info_gui; + ShowMainDockSpace(); + if (!io.WantCaptureMouse) + { + if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Right)) + trajectory_follow.returnToHead(); + else if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + const auto picked = step1_render::nearestProjectedTrajectoryPoint( + display_workers, + camera.frameView3D, + camera.frameProj3D, + Vector2{ io.MousePos.x, io.MousePos.y }, + io.DisplaySize.x, + io.DisplaySize.y); + if (picked) + trajectory_follow.explore(*picked, GetTime()); + } + } + view_kbd_shortcuts(); // Drag and drop: a Mandeye data folder, or any file in one, is processed like "Load & process scanning". @@ -2741,6 +2753,8 @@ void mouse(int glut_button, int state, int x, int y) { ImGuiIO& io = ImGui::GetIO(); + if (state == GLUT_UP) + mouse_buttons &= ~(1 << glut_button); if (!io.WantCaptureMouse) { if ((glut_button == GLUT_MIDDLE_BUTTON || glut_button == GLUT_RIGHT_BUTTON) && state == GLUT_DOWN && io.KeyCtrl) @@ -2748,8 +2762,6 @@ void mouse(int glut_button, int state, int x, int y) if (state == GLUT_DOWN) mouse_buttons |= 1 << glut_button; - else if (state == GLUT_UP) - mouse_buttons = 0; mouse_old_x = x; mouse_old_y = y; @@ -2891,6 +2903,7 @@ int main(int argc, char* argv[]) std::cout << argv[0] << " input_folder parameters(*.toml) output_folder" << std::endl; params.publish_trajectory = publish_trajectory_preview; + params.publish_processing_head = publish_processing_head; initGL(&argc, argv, winTitle, display, mouse); trajectory_renderer.init(); diff --git a/apps/lidar_odometry_step_1/lidar_odometry_utils.h b/apps/lidar_odometry_step_1/lidar_odometry_utils.h index 59049a68..61353ddd 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_utils.h +++ b/apps/lidar_odometry_step_1/lidar_odometry_utils.h @@ -77,6 +77,7 @@ struct LidarOdometryParams // Optional GUI observer, called by the producer only at safe trajectory boundaries. std::function&, bool)> publish_trajectory; + std::function publish_processing_head; // completed worker, never the predicted tail // filter points double filter_threshold_xy_inner = 0.3; // filtering points during load diff --git a/apps/lidar_odometry_step_1/lidar_odometry_utils_optimizers.cpp b/apps/lidar_odometry_step_1/lidar_odometry_utils_optimizers.cpp index 63d8ffb4..7b9efa82 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_utils_optimizers.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry_utils_optimizers.cpp @@ -2452,6 +2452,8 @@ static bool compute_step_2_impl( spdlog::stopwatch stopwatch_worker; if (initialize_lidar_odometry(worker_data, params, ts_failure, loProgress, pause, debugMsg, lookup_stats)) { + if (params.publish_processing_head && !worker_data.empty() && !worker_data.front().intermediate_trajectory.empty()) + params.publish_processing_head(worker_data.front().intermediate_trajectory.front().translation()); if (params.publish_trajectory) params.publish_trajectory(worker_data, true); for (int i = 0; i < worker_data.size(); i++) @@ -2677,6 +2679,9 @@ static bool compute_step_2_impl( HDMAP_ZONE_END(update_rgd_after); + if (params.publish_processing_head && !worker_data[i].intermediate_trajectory.empty()) + params.publish_processing_head(worker_data[i].intermediate_trajectory.back().translation()); + if (i > 1) { double translation = (worker_data[i - 1].intermediate_trajectory[0].translation() - diff --git a/apps/lidar_odometry_step_1/trajectory_follow.h b/apps/lidar_odometry_step_1/trajectory_follow.h new file mode 100644 index 00000000..5d81346f --- /dev/null +++ b/apps/lidar_odometry_step_1/trajectory_follow.h @@ -0,0 +1,214 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include + +namespace step1_render +{ + // Pick once on double click, using the same matrices and logical viewport as the displayed frame. + // This searches projected pose positions, without rebuilding geometry or reading back GPU buffers. + template + std::optional nearestProjectedTrajectoryPoint( + const Workers& workers, const Matrix& view, const Matrix& projection, Vector2 cursor, float width, float height) + { + if (width <= 0 || height <= 0 || !std::isfinite(cursor.x) || !std::isfinite(cursor.y)) + return std::nullopt; + const Matrix m = MatrixMultiply(view, projection); + float bestDistance = std::numeric_limits::infinity(); + float bestDepth = std::numeric_limits::infinity(); + std::optional result; + for (const auto& worker : workers) + for (const auto& pose : worker.intermediate_trajectory) + { + const auto p = pose.translation().template cast().eval(); + const float w = m.m3 * p.x() + m.m7 * p.y() + m.m11 * p.z() + m.m15; + if (!p.allFinite() || !std::isfinite(w) || w <= 1e-6f) + continue; + const float x = (m.m0 * p.x() + m.m4 * p.y() + m.m8 * p.z() + m.m12) / w; + const float y = (m.m1 * p.x() + m.m5 * p.y() + m.m9 * p.z() + m.m13) / w; + const float z = (m.m2 * p.x() + m.m6 * p.y() + m.m10 * p.z() + m.m14) / w; + if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z) || std::fabs(x) > 1 || std::fabs(y) > 1 || std::fabs(z) > 1) + continue; + const float dx = (x * 0.5f + 0.5f) * width - cursor.x; + const float dy = (0.5f - y * 0.5f) * height - cursor.y; + const float distance = dx * dx + dy * dy; + if (distance < bestDistance || (distance == bestDistance && z < bestDepth)) + { + bestDistance = distance; + bestDepth = z; + result = Vector3{ p.x(), p.y(), p.z() }; + } + } + return result; + } + + // Only an explicit point selection detaches the pivot from the processing head. + class TrajectoryFollow + { + public: + float idleSeconds = 5.f; + + void reset(double now) + { + observed = wasProcessing = suspended = transitioning = recentering = automaticReturn = requested = false; + selected.reset(); + lastNavigation = now; + } + + void explore(Vector3 point, double now) + { + if (!finite(point)) + return; + selected = point; + suspended = transitioning = recentering = true; + automaticReturn = requested = false; + lastNavigation = now; + } + + void returnToHead() + { + requested = true; + } + + bool exploring() const + { + return suspended; + } + + void update( + raylib_widgets::OrbitCamera& camera, + const std::optional& head, + bool processing, + bool interacting, + bool focused, + double now, + float dt) + { + if (observed && state(camera) != previous) + { + lastNavigation = now; + // Pan changes the framing, while orbit and zoom keep the same pivot. + if (camera.euler.translate.x + camera.euler.rotationCenter.x != previous[2] + previous[5] || + camera.euler.translate.y + camera.euler.rotationCenter.y != previous[3] + previous[6]) + recentering = false; + if (camera.isOrtho && (camera.orthoShiftX != previous[17] || camera.orthoShiftY != previous[18])) + { + // Step 1's ortho view uses the Euler transform, not updateOrtho()'s lookAt. + const float dx = camera.orthoShiftX - previous[17], dy = camera.orthoShiftY - previous[18]; + const float angle = (camera.euler.rotateX + camera.euler.rotateY) * DEG2RAD; + camera.euler.translate.x += std::cos(angle) * dx + std::sin(angle) * dy; + camera.euler.translate.y -= -std::sin(angle) * dx + std::cos(angle) * dy; + camera.eulerTransitionActive = false; + recentering = false; + } + } + // Stop an automatic return when SLAM ends; explicit exploration/return may finish. + if (wasProcessing && !processing && automaticReturn) + transitioning = recentering = automaticReturn = false; + wasProcessing = processing; + camera.updateEulerTransition(dt); + + if (!processing || interacting || !focused) + lastNavigation = now; + if (requested && head && finite(*head)) + { + suspended = automaticReturn = false; + transitioning = recentering = true; + selected.reset(); + camera.eulerTransitionActive = false; + } + else if (processing && suspended && now - lastNavigation >= idleSeconds && head && finite(*head)) + { + suspended = false; + transitioning = recentering = automaticReturn = true; + selected.reset(); + camera.eulerTransitionActive = false; + } + requested = false; + + const auto target = suspended ? selected : head; + if (focused && target && finite(*target) && (transitioning || (processing && !suspended))) + { + const float alpha = -std::expm1(-std::clamp(dt, 0.f, 0.1f) / (transitioning ? 0.15f : 0.35f)); + auto& e = camera.euler; + const Vector3 oldCenter = e.rotationCenter; + e.rotationCenter = Vector3Lerp(oldCenter, *target, alpha); + const Vector3 delta = Vector3Subtract(e.rotationCenter, oldCenter); + e.translate = Vector3Subtract(e.translate, delta); // preserve pan and zoom while the pivot moves + const float dx = recentering ? -(e.translate.x + e.rotationCenter.x) * alpha : 0; + const float dy = recentering ? -(e.translate.y + e.rotationCenter.y) * alpha : 0; + e.translate.x += dx; + e.translate.y += dy; + if (camera.eulerTransitionActive) + { + // Preserve camera-menu orientation transitions while following a moving head. + camera.eulerGoal.rotationCenter = e.rotationCenter; + camera.eulerGoal.translate = Vector3Subtract(camera.eulerGoal.translate, delta); + camera.eulerGoal.translate.x += dx; + camera.eulerGoal.translate.y += dy; + } + else + camera.eulerGoal = e; + float error = Vector3Distance(e.rotationCenter, *target); + if (recentering) + error = + std::max({ error, std::fabs(e.translate.x + e.rotationCenter.x), std::fabs(e.translate.y + e.rotationCenter.y) }); + if (error < 0.01f) + transitioning = recentering = automaticReturn = false; + } + previous = state(camera); + observed = true; + } + + private: + static bool finite(Vector3 point) + { + return std::isfinite(point.x) && std::isfinite(point.y) && std::isfinite(point.z); + } + + static std::array state(const raylib_widgets::OrbitCamera& camera) + { + const auto& e = camera.euler; + const auto& g = camera.eulerGoal; + return { e.rotateX, + e.rotateY, + e.translate.x, + e.translate.y, + e.translate.z, + e.rotationCenter.x, + e.rotationCenter.y, + e.rotationCenter.z, + g.rotateX, + g.rotateY, + g.translate.x, + g.translate.y, + g.translate.z, + g.rotationCenter.x, + g.rotationCenter.y, + g.rotationCenter.z, + camera.orthoZoom, + camera.orthoShiftX, + camera.orthoShiftY, + camera.orthoZCenterH, + static_cast(camera.isOrtho), + static_cast(camera.lockZ) }; + } + + std::array previous{}; + std::optional selected; + double lastNavigation = 0; + bool observed = false; + bool wasProcessing = false; + bool suspended = false; + bool transitioning = false; + bool recentering = false; + bool automaticReturn = false; + bool requested = false; + }; +} // namespace step1_render diff --git a/raylib_widgets/include/RaylibWidgets/ShortcutsTable.h b/raylib_widgets/include/RaylibWidgets/ShortcutsTable.h index 552a55e8..9ea0ed0a 100644 --- a/raylib_widgets/include/RaylibWidgets/ShortcutsTable.h +++ b/raylib_widgets/include/RaylibWidgets/ShortcutsTable.h @@ -18,7 +18,7 @@ namespace raylib_widgets }; // Renders `entries` as a bordered, scrollable two-column table (Shortcut | - // Description) inside the current ImGui window. - void ShowShortcutsTable(const std::vector& entries); + // Description) inside the current ImGui window, with the requested height. + void ShowShortcutsTable(const std::vector& entries, float height = 200.f); } // namespace raylib_widgets diff --git a/raylib_widgets/src/AppShell.cpp b/raylib_widgets/src/AppShell.cpp index cb30749e..63f07cb3 100644 --- a/raylib_widgets/src/AppShell.cpp +++ b/raylib_widgets/src/AppShell.cpp @@ -2,6 +2,8 @@ #include // ImGui::DockBuilder* +#include + #ifdef _WIN32 // NOGDI/NOUSER: windows.h's wingdi.h/winuser.h #define (or, for CloseWindow/ // ShowCursor, directly declare) identifiers that collide with raylib.h's own @@ -103,49 +105,51 @@ namespace raylib_widgets return; static bool show_about = false; + const ImVec2 workSize = ImGui::GetMainViewport()->WorkSize; + const ImVec2 maximum(workSize.x * 0.95f, workSize.y * 0.95f); + ImGui::SetNextWindowSize(ImVec2(std::min(1000.f, maximum.x), std::min(760.f, maximum.y)), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSizeConstraints(ImVec2(std::min(540.f, maximum.x), std::min(480.f, maximum.y)), maximum); - if (ImGui::Begin( - "Info", - &open, - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse)) + if (ImGui::Begin("Info", &open, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse)) { - bool firstLine = true; - for (const auto& line : infoLines) + if (ImGui::BeginTabBar("InfoTabs")) { - if (line.empty()) - ImGui::NewLine(); - else if (line.rfind("https://", 0) == 0) - ImGuiHyperlink(line.c_str()); - else - ImGui::TextUnformatted(line.c_str()); - - if (firstLine) + if (ImGui::BeginTabItem("Controls", nullptr, ImGuiTabItemFlags_NoPushId)) { - ImGui::SameLine( - ImGui::GetWindowWidth() - ImGui::CalcTextSize("ImGui").x - ImGui::GetStyle().ItemSpacing.x * 2 - - ImGui::GetStyle().FramePadding.x * 2); - if (ImGui::Button("ImGui")) - show_about = true; - - firstLine = false; + ShowShortcutsTable(appShortcuts, std::max(1.f, ImGui::GetContentRegionAvail().y)); + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("About / camera guide", nullptr, ImGuiTabItemFlags_NoPushId)) + { + if (ImGui::BeginChild("InfoDetails")) + { + ImGui::PushTextWrapPos(0.f); + for (const auto& line : infoLines) + { + if (line.empty()) + ImGui::NewLine(); + else if (line.rfind("https://", 0) == 0) + ImGuiHyperlink(line.c_str()); + else + ImGui::TextUnformatted(line.c_str()); + } + + ImGui::NewLine(); + ImGui::TextUnformatted("Author: Janusz Bedkowski & contributors"); + ImGui::NewLine(); + ImGui::TextUnformatted("Part of HDMapping software suite"); + ImGui::Text("Version: %s (%s)", versionString, buildDate); + ImGui::TextUnformatted("Project page:"); + ImGuiHyperlink("https://github.com/MapsHD/HDMapping"); + ImGui::PopTextWrapPos(); + if (ImGui::Button("ImGui")) + show_about = true; + } + ImGui::EndChild(); + ImGui::EndTabItem(); } + ImGui::EndTabBar(); } - - ImGui::NewLine(); - ImGui::Text("Author: Janusz Bedkowski & contributors"); - ImGui::NewLine(); - ImGui::Text("Part of HDMapping software suite"); - ImGui::Text("Version: %s (%s)", versionString, buildDate); - ImGui::Text("Project page: "); - ImGui::SameLine(); - ImGuiHyperlink("https://github.com/MapsHD/HDMapping"); - - ImGui::NewLine(); - ImGui::Separator(); - ImGui::NewLine(); - - ShowShortcutsTable(appShortcuts); - if (show_about) ImGui::ShowAboutWindow(&show_about); } diff --git a/raylib_widgets/src/ShortcutsTable.cpp b/raylib_widgets/src/ShortcutsTable.cpp index 85cc5b8c..7e9ae7bc 100644 --- a/raylib_widgets/src/ShortcutsTable.cpp +++ b/raylib_widgets/src/ShortcutsTable.cpp @@ -1,19 +1,25 @@ #include #include +#include #include namespace raylib_widgets { - void ShowShortcutsTable(const std::vector& entries) + void ShowShortcutsTable(const std::vector& entries, float height) { if (!ImGui::BeginTable( - "ShortcutsTable", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(-FLT_MIN, 200))) + "ShortcutsTable", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(-FLT_MIN, height))) return; + float shortcutWidth = 120.f; + for (const auto& entry : entries) + if (!entry.description.empty()) + shortcutWidth = + std::max(shortcutWidth, ImGui::CalcTextSize(entry.shortcut.c_str()).x + ImGui::GetStyle().CellPadding.x * 2); ImGui::TableSetupScrollFreeze(0, 1); - ImGui::TableSetupColumn("Shortcut", ImGuiTableColumnFlags_WidthFixed, 120); + ImGui::TableSetupColumn("Shortcut", ImGuiTableColumnFlags_WidthFixed, shortcutWidth); ImGui::TableSetupColumn("Description"); ImGui::TableHeadersRow();