diff --git a/application/editormodejoints.cpp b/application/editormodejoints.cpp index 12c1e4357..c78321c6c 100644 --- a/application/editormodejoints.cpp +++ b/application/editormodejoints.cpp @@ -611,7 +611,7 @@ void joints_tool::render_options() } if (ImGui::TreeNode(STR_C("Thresholds"))) { - if (begin_fields("##jointlimits", 0.55f)) + if (begin_fields_fitted("##jointlimits", 0.55f, {"Around the camera (m)", "Gap up to (m)", "Step (m)", "Kink (deg)", "Cant jump (mm)", "Grade break (per mille)", "Off the terrain model (m)"})) { auto const limit = [](char const *Label, char const *Id, double &Value, char const *Format) { field_row(Label); @@ -675,36 +675,41 @@ void joints_tool::render_options() "Kinks and grade breaks: the end is turned in line with the other path. Cant: the cant of the other path.\n" "The plain path moves, a switch stays as it is. One Ctrl+Z takes it all back")); } - auto const namewidth{std::max(110.0f, ImGui::GetContentRegionAvail().x * 0.32f)}; bool const chosen{state.selected >= 0 && state.selected < static_cast(state.issues.size())}; auto const details{chosen ? ImGui::GetFrameHeightWithSpacing() + ImGui::GetTextLineHeightWithSpacing() * 2.0f : 0.0f}; - ImGui::BeginChild("jointresults", ImVec2(0.0f, -details), true); - ImGui::Columns(4, "jointrows", false); - ImGui::SetColumnWidth(0, 90.0f); - ImGui::SetColumnWidth(1, 80.0f); - ImGui::SetColumnWidth(2, namewidth); - ImGuiListClipper clipper; - clipper.Begin(static_cast(listed.size())); - while (clipper.Step()) - for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) - { - auto const index{listed[row]}; - auto const &issue{state.issues[index]}; - auto const colour{ImGui::ColorConvertU32ToFloat4(kind_colour(issue.type))}; - ImGui::PushStyleColor(ImGuiCol_Text, issue.fixed ? ImVec4(0.5f, 0.8f, 0.5f, 1.0f) : colour); - if (ImGui::Selectable(format("%s##joint%d", STR_C(kind_name(issue.type)), index).c_str(), state.selected == index, ImGuiSelectableFlags_SpanAllColumns)) - joints_focus(index); - ImGui::PopStyleColor(); - ImGui::NextColumn(); - ImGui::TextUnformatted(issue.fixed ? STR_C("fixed") : value_text(issue).c_str()); - ImGui::NextColumn(); - ImGui::TextUnformatted(label_of(issue.track).c_str()); - ImGui::NextColumn(); - ImGui::TextUnformatted(label_of(issue.other).c_str()); - ImGui::NextColumn(); - } - ImGui::Columns(1); - ImGui::EndChild(); + // the kind, the value, the track and the other one, each column as wide as what's in it and a little apart: in a window + // docked across the bottom the tracks stay next to each other + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(std::round(ImGui::GetFontSize() * 0.6f), ImGui::GetStyle().CellPadding.y)); + if (ImGui::BeginTable("jointresults", 4, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter, ImVec2(0.0f, -details))) + { + ImGui::TableSetupColumn("##kind"); + ImGui::TableSetupColumn("##value"); + ImGui::TableSetupColumn("##track"); + ImGui::TableSetupColumn("##other", ImGuiTableColumnFlags_WidthStretch); + ImGuiListClipper clipper; + clipper.Begin(static_cast(listed.size())); + while (clipper.Step()) + for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) + { + auto const index{listed[row]}; + auto const &issue{state.issues[index]}; + auto const colour{ImGui::ColorConvertU32ToFloat4(kind_colour(issue.type))}; + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::PushStyleColor(ImGuiCol_Text, issue.fixed ? ImVec4(0.5f, 0.8f, 0.5f, 1.0f) : colour); + if (ImGui::Selectable(format("%s##joint%d", STR_C(kind_name(issue.type)), index).c_str(), state.selected == index, ImGuiSelectableFlags_SpanAllColumns)) + joints_focus(index); + ImGui::PopStyleColor(); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(issue.fixed ? STR_C("fixed") : value_text(issue).c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(label_of(issue.track).c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(label_of(issue.other).c_str()); + } + ImGui::EndTable(); + } + ImGui::PopStyleVar(); if (chosen) { auto &issue{state.issues[state.selected]}; diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index 9f19a2a6b..aad3333b1 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -2348,7 +2348,6 @@ void editor_mode::render_lay_ui() {1, STR_C("Curve Tab"), "Click points along the middle of a curve seen on the photo: the curve, compound or with a straight in it, is fitted to them and ends at the last one, heading as they do there. It comes from the straight before it, of the points clicked before or of the free end, and goes on with the curve of a free end, a switch too, where the points turn its way"}}) && (mode == 1) != (tool.mode == lay_mode::curve)) lay_switch_mode(); - ImGui::PushItemWidth(120.0f); if (tool.mode == lay_mode::straights) { ImGui::TextDisabled("%s", STR_C("Radius of the curves at the bends")); @@ -2365,7 +2364,6 @@ void editor_mode::render_lay_ui() } else { - ImGui::PopItemWidth(); segmented("layradii", tool.radii, {{0, STR_C("Auto"), "As few radii as follow the points, up to three"}, {1, STR_C("1 R"), "One radius"}, {2, STR_C("2 R"), "A compound curve of two radii"}, {3, STR_C("3 R"), "A compound curve of three radii"}}); ImGui::Checkbox(STR_C("Two curves with a straight between them, where the points show one"), &tool.straights_between); @@ -2384,13 +2382,17 @@ void editor_mode::render_lay_ui() ImGui::TextDisabled("%s", STR_C("Click points along the middle of the track on the photo; the curve ends at the last one")); ImGui::PopTextWrapPos(); } - ImGui::PushItemWidth(120.0f); } - ImGui::DragScalar(STR_C("Speed (km/h)"), ImGuiDataType_Double, &tool.style.velocity, 1.0f, nullptr, nullptr, "%.0f"); - item_tooltip("Speed limit of the new paths, and the design speed of the transition curves and of the cant; the speed of the track joined comes first, and none higher than the radius allows"); + // the name on the left of the field, as in the inspector, the values to pick with a click under it + if (begin_fields("##layspeed")) + { + field_row("Speed (km/h)"); + ImGui::DragScalar("##velocity", ImGuiDataType_Double, &tool.style.velocity, 1.0f, nullptr, nullptr, "%.0f"); + item_tooltip("Speed limit of the new paths, and the design speed of the transition curves and of the cant; the speed of the track joined comes first, and none higher than the radius allows"); + ImGui::EndTable(); + } value_chips("speeds", tool.style.velocity, {40.0, 60.0, 80.0, 100.0, 120.0, 160.0}, "%.0f"); tool.style.velocity = std::clamp(tool.style.velocity, 0.0, 400.0); - ImGui::PopItemWidth(); ImGui::Checkbox(STR_C("This speed also on from a track with a speed of its own"), &tool.own_speed); item_tooltip("Off: a track laid on from another one, or joined to it, is designed for the speed of that track and takes it.\nOn: it's designed for the speed above and the new tracks get it.\nWhile laying: Ctrl+Shift+wheel"); if (auto const [from, to]{laying_ends()}; from != nullptr || to != nullptr) @@ -2441,17 +2443,23 @@ void editor_mode::render_lay_ui() return; } ImGui::TextDisabled("%s", STR_C("Dragged from a free end, or laid from a point to one")); - ImGui::PushItemWidth(120.0f); - ImGui::DragScalar(STR_C("Curve radius (m)"), ImGuiDataType_Double, &tool.radius, 5.0f, nullptr, nullptr, "%.0f"); - item_tooltip("Drag to change, Ctrl+click to type the value. While dragging: Ctrl+wheel"); + if (begin_fields("##layradius")) + { + field_row("Curve radius (m)"); + ImGui::DragScalar("##radius", ImGuiDataType_Double, &tool.radius, 5.0f, nullptr, nullptr, "%.0f"); + item_tooltip("Drag to change, Ctrl+click to type the value. While dragging: Ctrl+wheel"); + ImGui::EndTable(); + } value_chips("radii", tool.radius, {190.0, 300.0, 500.0, 800.0, 1200.0, 2000.0}, "%.0f"); tool.radius = std::max(10.0, tool.radius); - ImGui::PopItemWidth(); ImGui::Spacing(); - ImGui::PushItemWidth(120.0f); - ImGui::DragScalar(STR_C("Longest path (m)"), ImGuiDataType_Double, &tool.piece_length, 1.0f, nullptr, nullptr, "%.0f"); + if (begin_fields("##laypiece")) + { + field_row("Longest path (m)"); + ImGui::DragScalar("##piece", ImGuiDataType_Double, &tool.piece_length, 1.0f, nullptr, nullptr, "%.0f"); + ImGui::EndTable(); + } tool.piece_length = std::clamp(tool.piece_length, 5.0, 1000.0); - ImGui::PopItemWidth(); ImGui::TextDisabled("%s", STR_C("Look of the new track")); int source{tool.copy_selected ? 1 : 0}; if (segmented("laylook", source, diff --git a/application/editormodeprofile.cpp b/application/editormodeprofile.cpp index 2b7956f97..d011d0d01 100644 --- a/application/editormodeprofile.cpp +++ b/application/editormodeprofile.cpp @@ -1952,7 +1952,7 @@ void editor_mode::render_profile_body() if (stored >= 0) { ImGui::TextDisabled(STR_C("Design kept in %s%s"), scene::Layers.layer(m_profiles[stored].layer).name.c_str(), state.changed ? STR_C(", changes go there on save") : ""); - ImGui::SameLine(); + same_line_if_fits(STR_C("Forget the design")); if (ImGui::SmallButton(STR_C("Forget the design"))) profile_forget(); } @@ -2994,7 +2994,7 @@ void editor_mode::draw_profile_canvas(profile_view const &View, ImDrawList &Draw auto const x{View.x_of(middle)}; if (View.x_of(points[i + 1].chainage) - View.x_of(points[i].chainage) < 70.0f) continue; - auto const text{format("%+.2f o/oo L %.0f m", profile::grade_after(line, i) * 1000.0, points[i + 1].chainage - points[i].chainage)}; + auto const text{format("%+.2f %s L %.0f m", profile::grade_after(line, i) * 1000.0, STR_C("per mille"), points[i + 1].chainage - points[i].chainage)}; auto const size{ImGui::CalcTextSize(text.c_str())}; if (View.x_of(points[i + 1].chainage) - View.x_of(points[i].chainage) < size.x + 30.0f) continue; @@ -3152,7 +3152,7 @@ void editor_mode::draw_profile_overlay() const if (to - from < 5.0) continue; auto const grade{(points[k + 1].elevation - points[k].elevation) / std::max(1e-6, points[k + 1].chainage - points[k].chainage) * 1000.0}; - label(on_line((from + to) * 0.5), format("%+.2f o/oo L %.0f m", grade, points[k + 1].chainage - points[k].chainage), kGradeLine); + label(on_line((from + to) * 0.5), format("%+.2f %s L %.0f m", grade, STR_C("per mille"), points[k + 1].chainage - points[k].chainage), kGradeLine); } // the vertical curves: their range along the track, the ends marked, the radius at the point for (auto const &curve : curves) diff --git a/application/editormoderoute.cpp b/application/editormoderoute.cpp index dd79147ac..83b9b2244 100644 --- a/application/editormoderoute.cpp +++ b/application/editormoderoute.cpp @@ -373,7 +373,7 @@ void editor_mode::render_route_stored() route.status = STR_C("The kept design is loaded, applying it lays the paths by it again"); } item_tooltip("Loads the design kept in the scenery in place of the one read from the paths; nothing changes until it's applied"); - ImGui::SameLine(); + same_line_if_fits(STR_C("Forget the kept design")); if (ImGui::SmallButton(STR_C("Forget the kept design"))) { alignment_store::forget(route.departed); @@ -1468,7 +1468,7 @@ void editor_mode::render_route_trace() route_trace_end(true); if (ImGui::Button(STR_C("Drop Esc"))) route_trace_end(false); - ImGui::SameLine(); + same_line_if_fits(STR_C("Take out the last point Backspace")); ImGui::BeginDisabled(trace.points.empty()); if (ImGui::Button(STR_C("Take out the last point Backspace"))) { @@ -1639,7 +1639,8 @@ void editor_mode::render_route_ui() ImGui::TextDisabled(STR_P("%zu path, %.2f m", "%zu paths, %.2f m", route.chain.tracks.size()), route.chain.tracks.size(), route.chain.length); auto const reset{STR_C("Reset design")}; auto const reset_width{ImGui::CalcTextSize(reset).x + ImGui::GetStyle().FramePadding.x * 2.0f}; - ImGui::SameLine(std::max(ImGui::GetCursorPosX(), ImGui::GetWindowContentRegionMax().x - reset_width)); + same_line_if_fits(reset_width); + ImGui::SetCursorPosX(std::max(ImGui::GetCursorPosX(), ImGui::GetWindowContentRegionMax().x - reset_width)); if (ImGui::Button(reset)) { auto *track{route.chain.tracks[route.chain.tracks.size() / 2]}; @@ -1670,7 +1671,7 @@ void editor_mode::render_route_ui() return; } item_tooltip("Every line of the scenery not digitized yet is kept in it with its straights, arcs and transition curves, the way the drawn tracks are kept; the paths stay as they are"); - ImGui::SameLine(); + same_line_if_fits(STR_C("Digitize the scenery")); if (ImGui::Button(STR_C("Digitize the scenery"))) { digitize_scenery(true); @@ -2050,7 +2051,7 @@ bool editor_mode::render_route_vertices() { ImGui::Checkbox(STR_C("Keep to the points clicked"), &m_route.hold); item_tooltip("The scenery keeps the points clicked when the line was laid: a curve whose transitions or cants are changed gets its radii fitted to them again, so it stays where it was seen on the photo"); - ImGui::SameLine(); + same_line_if_fits(STR_C("Fit all to them")); if (ImGui::SmallButton(STR_C("Fit all to them"))) { for (int i = 0; i < count; ++i) @@ -2132,7 +2133,7 @@ bool editor_mode::render_route_vertex(int const Index) mark(part::whole, 0); if (clicked >= 3) { - ImGui::SameLine(); + same_line_if_fits(STR_C("Fit to them")); if (ImGui::SmallButton(STR_C("Fit to them"))) changed |= route_hold_clicks(Index); item_tooltip("The radii of the curve and their shares fitted again to the points clicked, the transitions and the cants as they are"); @@ -2294,7 +2295,7 @@ bool editor_mode::render_route_vertex(int const Index) } if (false == vertex.spirals) { - ImGui::SameLine(); + same_line_if_fits(STR_C("Transitions for these cants")); if (ImGui::SmallButton(STR_C("Transitions for these cants"))) reshape([&] { alignment::norm_transitions(vertex, design.speed, design.norms); }); item_tooltip("The transition curves as long as the norms ask for at these radii and cants, the cants staying: a cant lowered asks for longer ones"); diff --git a/application/editormodeshared.h b/application/editormodeshared.h index 516aada88..cb0817989 100644 --- a/application/editormodeshared.h +++ b/application/editormodeshared.h @@ -58,6 +58,20 @@ inline void item_tooltip(char const *Text) ImGui::SetTooltip("%s", STR_C(Text)); } +// the next item on the line of the one before it when it fits in what's left of the line, at the start of the next line +// otherwise, where SameLine would put it past the edge of the panel and cut it off; Width is the width of the next item +inline void same_line_if_fits(float const Width) +{ + ImGui::SameLine(); + if (ImGui::GetContentRegionAvail().x < Width) + ImGui::NewLine(); +} +// the same for a button (or a small button) with this label, as drawn +inline void same_line_if_fits(char const *Label) +{ + same_line_if_fits(ImGui::CalcTextSize(Label, nullptr, true).x + ImGui::GetStyle().FramePadding.x * 2.0f); +} + // grid points without a height (or another value) take the one of the nearest point which has it (by steps along the grid) template inline void fill_from_nearest(std::vector &Heights, std::vector &Found, std::size_t const Side) { @@ -162,21 +176,64 @@ struct segment_option }; inline bool segmented(char const *Id, int &Value, std::initializer_list Options) { - auto const count{static_cast(Options.size())}; auto const width{ImGui::GetContentRegionAvail().x}; auto const height{ImGui::GetFrameHeight()}; auto const at{ImGui::GetCursorScreenPos()}; auto *draw{ImGui::GetWindowDrawList()}; auto const rounding{height * 0.5f}; - draw->AddRectFilled(at, ImVec2(at.x + width, at.y + height), ImGui::GetColorU32(ImGuiCol_FrameBg), rounding); + // the segments share the bar evenly while each name fits in its share; else the short names give up some of the room + // around them to the long ones, and the names which don't fit side by side even so go on in a bar under it + auto const room{std::round(ImGui::GetFontSize())}; + std::vector needs; + for (auto const &option : Options) + needs.push_back(ImGui::CalcTextSize(option.label).x + room); + std::vector bars{0}; // the first option of each bar, and the end + float used{0.0f}; + for (std::size_t i = 0; i < needs.size(); ++i) + { + if (i > bars.back() && used + needs[i] > width) + { + bars.push_back(i); + used = 0.0f; + } + used += needs[i]; + } + bars.push_back(needs.size()); + auto const gap{std::round(ImGui::GetStyle().ItemSpacing.y * 0.5f)}; + std::vector spans; // the left and the right of each segment + std::vector tops; + for (std::size_t bar = 0; bar + 1 < bars.size(); ++bar) + { + auto const first{bars[bar]}; + auto const last{bars[bar + 1]}; + auto const count{static_cast(last - first)}; + auto const top{at.y + static_cast(bar) * (height + gap)}; + draw->AddRectFilled(ImVec2(at.x, top), ImVec2(at.x + width, top + height), ImGui::GetColorU32(ImGuiCol_FrameBg), rounding); + float sum{0.0f}; + bool even{true}; + for (auto i{first}; i < last; ++i) + { + sum += needs[i]; + even = even && needs[i] <= width / count; + } + auto left{at.x}; + for (auto i{first}; i < last; ++i) + { + auto const share{even ? width / count : needs[i] + (width - sum) / count}; + spans.emplace_back(std::round(left), i + 1 == last ? at.x + width : std::round(left + share)); + tops.push_back(top); + left += share; + } + } ImGui::PushID(Id); bool changed{false}; - float index{0.0f}; + std::size_t index{0}; for (auto const &option : Options) { - auto const left{std::round(at.x + width * index / count)}; - auto const right{std::round(at.x + width * (index + 1.0f) / count)}; - ImGui::SetCursorScreenPos(ImVec2(left, at.y)); + auto const left{spans[index].x}; + auto const right{spans[index].y}; + auto const top{tops[index]}; + ImGui::SetCursorScreenPos(ImVec2(left, top)); ImGui::PushID(option.value); if (ImGui::InvisibleButton("##segment", ImVec2(std::max(1.0f, right - left), height)) && Value != option.value) { @@ -189,16 +246,16 @@ inline bool segmented(char const *Id, int &Value, std::initializer_listAddRectFilled(ImVec2(left + 2.0f, at.y + 2.0f), ImVec2(right - 2.0f, at.y + height - 2.0f), chosen ? family_colour(0, 0.8f) : ImGui::GetColorU32(ImGuiCol_FrameBgHovered), rounding - 2.0f); + draw->AddRectFilled(ImVec2(left + 2.0f, top + 2.0f), ImVec2(right - 2.0f, top + height - 2.0f), chosen ? family_colour(0, 0.8f) : ImGui::GetColorU32(ImGuiCol_FrameBgHovered), rounding - 2.0f); auto const text{ImGui::CalcTextSize(option.label)}; - draw->PushClipRect(ImVec2(left + 4.0f, at.y), ImVec2(right - 4.0f, at.y + height), true); - draw->AddText(ImVec2(std::round(std::max(left + 6.0f, (left + right - text.x) * 0.5f)), std::round(at.y + (height - text.y) * 0.5f)), ImGui::GetColorU32(chosen ? ImGuiCol_Text : ImGuiCol_TextDisabled), option.label); + draw->PushClipRect(ImVec2(left + 4.0f, top), ImVec2(right - 4.0f, top + height), true); + draw->AddText(ImVec2(std::round(std::max(left + 6.0f, (left + right - text.x) * 0.5f)), std::round(top + (height - text.y) * 0.5f)), ImGui::GetColorU32(chosen ? ImGuiCol_Text : ImGuiCol_TextDisabled), option.label); draw->PopClipRect(); - index += 1.0f; + ++index; } ImGui::PopID(); ImGui::SetCursorScreenPos(at); - ImGui::Dummy(ImVec2(width, height)); + ImGui::Dummy(ImVec2(width, tops.empty() ? height : tops.back() + height - at.y)); return changed; } @@ -357,14 +414,31 @@ inline bool state_chip(char const *Label, ImVec4 const &Colour) // fields as rows of a table: the name wrapped in a column on the left, the field as wide as the rest of the panel; // field_row takes the untranslated "Name##id" (a literal: the translations are cached by the pointer, a name made at run // time goes with Translate false) and leaves the cursor where the field goes -inline bool begin_fields(char const *Id, float const Names = 0.42f) +inline bool begin_fields(char const *Id, float const Names = 0.42f, float const Width = 0.0f) { - if (false == ImGui::BeginTable(Id, 2, ImGuiTableFlags_SizingStretchProp)) + if (false == ImGui::BeginTable(Id, 2, ImGuiTableFlags_SizingStretchProp, ImVec2(Width, 0.0f))) return false; ImGui::TableSetupColumn("##name", ImGuiTableColumnFlags_WidthStretch, Names); ImGui::TableSetupColumn("##field", ImGuiTableColumnFlags_WidthStretch, 1.0f - Names); return true; } +// fields as begin_fields, in a block no wider than its widest name with a field of Field font sizes beside it, where the panel +// is wider than that (a window docked across the bottom); Labels are the names of its rows as field_row takes them +inline bool begin_fields_fitted(char const *Id, float const Names, std::initializer_list Labels, float const Field = 10.0f) +{ + float widest{0.0f}; + for (auto const *label : Labels) + { + auto const *text{STR_C(label)}; + widest = std::max(widest, ImGui::CalcTextSize(text, std::strstr(text, "##")).x); + } + // the padding of the cells, and a little to spare so the widest name isn't wrapped + widest += ImGui::GetStyle().CellPadding.x * 2.0f + ImGui::GetFontSize(); + auto const width{widest + std::round(ImGui::GetFontSize() * Field)}; + if (width >= ImGui::GetContentRegionAvail().x) + return begin_fields(Id, Names); + return begin_fields(Id, widest / width, width); +} inline void field_row(char const *Label, bool const Translate = true) { ImGui::TableNextRow(); diff --git a/application/editormodespeed.cpp b/application/editormodespeed.cpp index f3278dce2..dd2a6b8d6 100644 --- a/application/editormodespeed.cpp +++ b/application/editormodespeed.cpp @@ -231,7 +231,7 @@ void speed_tool::render_options() if (ImGui::TreeNode(STR_C("Thresholds"))) { auto &options{state.options}; - if (begin_fields("##speedlimits", 0.6f)) + if (begin_fields_fitted("##speedlimits", 0.6f, {"Unbalanced acceleration (m/s2)", "Switch branches (m/s2)", "Cant change rate (mm/s)", "Cant ramp 1:(k*V), k", "Unbalanced acc. change rate (m/s3)", "Reference length (m)"})) { auto const limit = [](char const *Label, char const *Id, double &Value, char const *Format) { field_row(Label); @@ -288,64 +288,68 @@ void speed_tool::render_options() "A switch has one velocity for both its tracks: negative limits only the diverging one, the main one keeping no limit.\n" "When the main track needs a limit of its own, the lower of the two applies to both")); } - auto const namewidth{std::max(120.0f, ImGui::GetContentRegionAvail().x * 0.3f)}; - ImGui::Columns(6, "speedcolumns", false); - ImGui::SetColumnWidth(0, namewidth + 8.0f); - for (auto const *header : {"Path", "Limit", "Safe", "Suggested", "Cause", "R / cant"}) - { - ImGui::TextDisabled("%s", STR_C(header)); - ImGui::NextColumn(); - } - ImGui::Columns(1); bool const chosen{state.selected >= 0 && state.selected < static_cast(state.results.size())}; auto const details{chosen ? ImGui::GetFrameHeightWithSpacing() + ImGui::GetTextLineHeightWithSpacing() * 5.0f : 0.0f}; - ImGui::BeginChild("speedresults", ImVec2(0.0f, -details), true); - ImGui::Columns(6, "speedrows", false); - ImGui::SetColumnWidth(0, namewidth); - ImGuiListClipper clipper; - clipper.Begin(static_cast(listed.size())); - while (clipper.Step()) - for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) + // each column as wide as what's in it and its name and a little apart, the last one to the edge; the names stay at the top + // as the list scrolls + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(std::round(ImGui::GetFontSize() * 0.6f), ImGui::GetStyle().CellPadding.y)); + if (ImGui::BeginTable("speedresults", 6, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter, ImVec2(0.0f, -details))) + { + for (int column = 0; column < 6; ++column) + ImGui::TableSetupColumn(nullptr, column == 5 ? ImGuiTableColumnFlags_WidthStretch : ImGuiTableColumnFlags_None); + ImGui::TableSetupScrollFreeze(0, 1); + ImGui::TableNextRow(); + for (auto const *header : {"Path", "Limit", "Safe", "Suggested", "Cause", "R / cant"}) { - auto const index{listed[row]}; - auto const &verdict{state.results[index]}; - bool const violated{verdict.violated(state.options)}; - bool const bad{violated || verdict.warned(state.options)}; - auto const colour{violated ? ImVec4(1.0f, 0.45f, 0.4f, 1.0f) : ImVec4(1.0f, 0.75f, 0.3f, 1.0f)}; - auto name{name_of(*verdict.track)}; - if (verdict.track->eType == tt_Switch) - name += verdict.path == 0 ? STR_C(" (main)") : STR_C(" (branch)"); - if (bad) - ImGui::PushStyleColor(ImGuiCol_Text, colour); - if (ImGui::Selectable((name + "##speed" + std::to_string(index)).c_str(), state.selected == index, ImGuiSelectableFlags_SpanAllColumns)) - speed_focus(index); - if (ImGui::IsItemHovered()) + ImGui::TableNextColumn(); + ImGui::TextDisabled("%s", STR_C(header)); + } + ImGuiListClipper clipper; + clipper.Begin(static_cast(listed.size())); + while (clipper.Step()) + for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) { - if (bad) - ImGui::PopStyleColor(); - ImGui::SetTooltip("%s", speed_check::explain(verdict, state.options).c_str()); + auto const index{listed[row]}; + auto const &verdict{state.results[index]}; + bool const violated{verdict.violated(state.options)}; + bool const bad{violated || verdict.warned(state.options)}; + auto const colour{violated ? ImVec4(1.0f, 0.45f, 0.4f, 1.0f) : ImVec4(1.0f, 0.75f, 0.3f, 1.0f)}; + auto name{name_of(*verdict.track)}; + if (verdict.track->eType == tt_Switch) + name += verdict.path == 0 ? STR_C(" (main)") : STR_C(" (branch)"); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); if (bad) ImGui::PushStyleColor(ImGuiCol_Text, colour); + if (ImGui::Selectable((name + "##speed" + std::to_string(index)).c_str(), state.selected == index, ImGuiSelectableFlags_SpanAllColumns)) + speed_focus(index); + if (ImGui::IsItemHovered()) + { + if (bad) + ImGui::PopStyleColor(); + ImGui::SetTooltip("%s", speed_check::explain(verdict, state.options).c_str()); + if (bad) + ImGui::PushStyleColor(ImGuiCol_Text, colour); + } + ImGui::TableNextColumn(); + ImGui::TextUnformatted(speed_text(verdict.set).c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(verdict.safe >= state.options.top ? STR_C("any") : format("%.0f", verdict.safe).c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(verdict.safe >= state.options.top ? "-" : format("%.0f", speed_check::suggested(verdict.safe)).c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(STR_C(speed_check::describe(verdict.why))); + ImGui::TableNextColumn(); + if (verdict.radius > 0.0) + ImGui::Text(STR_C("%.0f m / %.0f mm"), verdict.radius, verdict.cant); + else + ImGui::TextUnformatted("-"); + if (bad) + ImGui::PopStyleColor(); } - ImGui::NextColumn(); - ImGui::TextUnformatted(speed_text(verdict.set).c_str()); - ImGui::NextColumn(); - ImGui::TextUnformatted(verdict.safe >= state.options.top ? STR_C("any") : format("%.0f", verdict.safe).c_str()); - ImGui::NextColumn(); - ImGui::TextUnformatted(verdict.safe >= state.options.top ? "-" : format("%.0f", speed_check::suggested(verdict.safe)).c_str()); - ImGui::NextColumn(); - ImGui::TextUnformatted(STR_C(speed_check::describe(verdict.why))); - ImGui::NextColumn(); - if (verdict.radius > 0.0) - ImGui::Text(STR_C("%.0f m / %.0f mm"), verdict.radius, verdict.cant); - else - ImGui::TextUnformatted("-"); - ImGui::NextColumn(); - if (bad) - ImGui::PopStyleColor(); - } - ImGui::Columns(1); - ImGui::EndChild(); + ImGui::EndTable(); + } + ImGui::PopStyleVar(); if (chosen) { auto const &verdict{state.results[state.selected]}; diff --git a/application/editormodetrack.cpp b/application/editormodetrack.cpp index b0790adb3..c8c5fbe2e 100644 --- a/application/editormodetrack.cpp +++ b/application/editormodetrack.cpp @@ -864,58 +864,107 @@ void editor_mode::render_track_guide() ImGui::TextUnformatted(family_name(family)); ImGui::PopStyleColor(); ImGui::EndGroup(); + // a click on the title row folds the card to it and opens it again; kept with the settings of the editor, for all the tools + auto const below{ImGui::GetCursorScreenPos()}; + ImGui::SetCursorScreenPos(row); + auto folded{EditorSettings.track_card_folded()}; + if (ImGui::InvisibleButton("##trackguidefold", ImVec2(std::max(1.0f, right - row.x), std::max(1.0f, below.y - row.y - ImGui::GetStyle().ItemSpacing.y)))) + { + folded = !folded; + EditorSettings.track_card_folded(folded); + EditorSettings.save(); + } + auto const hovered{ImGui::IsItemHovered()}; + if (hovered) + ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); + ImGui::SetCursorScreenPos(below); + auto marker{right - pad}; if (found != modes.end() && found->key != nullptr) { auto const height{std::round(font * 1.35f)}; auto const cap{std::max(std::round(ImGui::CalcTextSize(found->key).x + height * 0.6f), height)}; gesture_key(*list, ImVec2(right - pad - cap, row.y + std::round((iconside - height) * 0.5f)), height, found->key); + marker -= cap + pad; } - ImGui::PushTextWrapPos(right - pad - ImGui::GetWindowPos().x); - if (found != modes.end()) + // the marker of the fold left of the key: pointing right while folded, down while open { - ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); - ImGui::TextWrapped("%s", STR_C(found->tooltip)); - ImGui::PopStyleColor(); + auto const half{std::round(font * 0.3f)}; + ImVec2 const centre{marker - half, row.y + std::round(iconside * 0.5f)}; + auto const colour{ImGui::GetColorU32(hovered ? ImGuiCol_Text : ImGuiCol_TextDisabled)}; + if (folded) + list->AddTriangleFilled(ImVec2(centre.x - half * 0.6f, centre.y - half), ImVec2(centre.x - half * 0.6f, centre.y + half), ImVec2(centre.x + half * 0.8f, centre.y), colour); + else + list->AddTriangleFilled(ImVec2(centre.x - half, centre.y - half * 0.6f), ImVec2(centre.x + half, centre.y - half * 0.6f), ImVec2(centre.x, centre.y + half * 0.8f), colour); } - // the gestures, each drawn: the mouse with the button lit, the keys as caps - auto const hints{track_key_hints(false)}; - auto const gesture{std::round(font * 1.25f)}; - std::vector> drawn; - float column{0.0f}; - for (auto const &hint : hints) + if (false == folded) { - drawn.push_back(gesture_picture(hint.raw != nullptr ? hint.raw : hint.key)); - column = std::max(column, gesture_width(gesture, drawn.back())); - } - column = std::min(column, font * 6.0f); - if (false == hints.empty()) - ImGui::Dummy(ImVec2(0.0f, pad * 0.3f)); - for (std::size_t i = 0; i < hints.size() && i < 7; ++i) - { - auto const at{ImGui::GetCursorScreenPos()}; - auto const line{ImGui::GetTextLineHeight()}; - auto const height{std::max(gesture, line)}; - list->PushClipRect(at, ImVec2(at.x + column, at.y + height), true); - gesture_draw(*list, ImVec2(at.x, at.y + std::round((height - gesture) * 0.5f)), gesture, drawn[i], ImGui::GetColorU32(ImGuiCol_Text)); - list->PopClipRect(); - ImGui::Dummy(ImVec2(column, height)); - ImGui::SameLine(0.0f, pad); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + std::round((height - line) * 0.5f)); - if (hints[i].raw == nullptr || false == gesture_keys_only(hints[i].raw)) + auto const wrap{right - pad}; + ImGui::PushTextWrapPos(wrap - ImGui::GetWindowPos().x); + if (found != modes.end()) { - ImGui::TextColored(ImVec4(1.0f, 0.83f, 0.3f, 1.0f), "%s", hints[i].key); - ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); + ImGui::TextWrapped("%s", STR_C(found->tooltip)); + ImGui::PopStyleColor(); } - ImGui::TextWrapped("%s", hints[i].action.c_str()); + // the gestures, each drawn: the mouse with the button lit, the keys as caps + auto const hints{track_key_hints(false)}; + auto const gesture{std::round(font * 1.25f)}; + std::vector> drawn; + float column{0.0f}; + for (auto const &hint : hints) + { + drawn.push_back(gesture_picture(hint.raw != nullptr ? hint.raw : hint.key)); + column = std::max(column, gesture_width(gesture, drawn.back())); + } + column = std::min(column, font * 6.0f); + // the widest word of a text, which wrapping can't break + auto const widest_word = [](std::string const &Text) { + float widest{0.0f}; + for (std::size_t from{0}; from < Text.size();) + { + auto const end{std::min(Text.find(' ', from), Text.size())}; + widest = std::max(widest, ImGui::CalcTextSize(Text.c_str() + from, Text.c_str() + end).x); + from = end + 1; + } + return widest; + }; + if (false == hints.empty()) + ImGui::Dummy(ImVec2(0.0f, pad * 0.3f)); + for (std::size_t i = 0; i < hints.size() && i < 7; ++i) + { + auto const at{ImGui::GetCursorScreenPos()}; + auto const line{ImGui::GetTextLineHeight()}; + auto const height{std::max(gesture, line)}; + list->PushClipRect(at, ImVec2(at.x + column, at.y + height), true); + gesture_draw(*list, ImVec2(at.x, at.y + std::round((height - gesture) * 0.5f)), gesture, drawn[i], ImGui::GetColorU32(ImGuiCol_Text)); + list->PopClipRect(); + ImGui::Dummy(ImVec2(column, height)); + ImGui::SameLine(0.0f, pad); + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + std::round((height - line) * 0.5f)); + if (hints[i].raw == nullptr || false == gesture_keys_only(hints[i].raw)) + { + auto const indent{ImGui::GetCursorPosX()}; + ImGui::TextColored(ImVec4(1.0f, 0.83f, 0.3f, 1.0f), "%s", hints[i].key); + ImGui::SameLine(); + // after a long gesture the action goes under it, at its indent, rather than into a sliver of the row where it + // would break in the middle of its words + if (wrap - ImGui::GetCursorScreenPos().x < std::max(font * 8.0f, widest_word(hints[i].action))) + { + ImGui::NewLine(); + ImGui::SetCursorPosX(indent); + } + } + ImGui::TextWrapped("%s", hints[i].action.c_str()); + } + ImGui::PopTextWrapPos(); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); + ImGui::TextUnformatted(STR_C("F1: all the shortcuts")); + ImGui::PopStyleColor(); + if (ImGui::IsItemHovered()) + ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); + if (ImGui::IsItemClicked()) + m_shortcuts_open = true; } - ImGui::PopTextWrapPos(); - ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); - ImGui::TextUnformatted(STR_C("F1: all the shortcuts")); - ImGui::PopStyleColor(); - if (ImGui::IsItemHovered()) - ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); - if (ImGui::IsItemClicked()) - m_shortcuts_open = true; ImGui::Unindent(pad + 3.0f); ImGui::Dummy(ImVec2(width, pad * 0.5f)); ImGui::EndGroup(); @@ -1509,14 +1558,14 @@ void editor_mode::render_path_ui() ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.2f, 1.0f), STR_C("Geometry locked: %s"), reason.c_str()); if (track->eType == tt_Switch && m_track_tab == track_tab::path) { - ImGui::SameLine(); + same_line_if_fits(STR_C("Edit the switch (T)")); if (ImGui::SmallButton(STR_C("Edit the switch (T)"))) show_track_tab(track_tab::turnout); item_tooltip("A switch: the turnout tool sets its geometry, side and drive"); } if (track->eType == tt_Switch && track->SwitchExtension != nullptr) { - ImGui::SameLine(); + same_line_if_fits(STR_C("Throw (H)")); if (ImGui::SmallButton(STR_C("Throw (H)"))) throw_switch(*track); item_tooltip(track->SwitchExtension->CurrentIndex ? "Set to the diverging track: throws it over to the main one. In the editor only, to see the blades and the route; the simulation starts with the switches set to the main track" diff --git a/editor/editorSettings.cpp b/editor/editorSettings.cpp index dd475b183..0f5996028 100644 --- a/editor/editorSettings.cpp +++ b/editor/editorSettings.cpp @@ -151,6 +151,8 @@ bool editorSettings::load() m_terrain_buried_ask = (value == "1"); else if (key == "track_tools_all") m_track_tools_more = (value == "1"); + else if (key == "track_card_folded") + m_track_card_folded = (value == "1"); else if (key == "terrain_while_laying") m_terrain_while_laying = (value == "1"); else if (key == "nmt_band") @@ -270,6 +272,7 @@ bool editorSettings::save() stream << "terrain_offer " << (m_terrain_offer ? 1 : 0) << "\n"; stream << "terrain_buried_ask " << (m_terrain_buried_ask ? 1 : 0) << "\n"; stream << "track_tools_all " << (m_track_tools_more ? 1 : 0) << "\n"; + stream << "track_card_folded " << (m_track_card_folded ? 1 : 0) << "\n"; stream << "terrain_while_laying " << (m_terrain_while_laying ? 1 : 0) << "\n"; stream << "nmt_band " << m_terrain_model.band << "\n"; stream << "nmt_around " << m_terrain_model.around << "\n"; diff --git a/editor/editorSettings.hpp b/editor/editorSettings.hpp index 5223fca51..b5164b139 100644 --- a/editor/editorSettings.hpp +++ b/editor/editorSettings.hpp @@ -104,6 +104,9 @@ public: void terrain_model_offset(std::string const &Scenery, double Offset, bool Fitted); bool track_tools_more() const { return m_track_tools_more; } void track_tools_more(bool Show) { m_track_tools_more = Show; } + // the card of the track tool in use folded to its title row, for all the tools + bool track_card_folded() const { return m_track_card_folded; } + void track_card_folded(bool const Folded) { m_track_card_folded = Folded; } // the ballast of the railway drawn in the top view int top_tracks() const { return m_top_tracks; } void top_tracks(int const Tracks) { m_top_tracks = Tracks; } @@ -144,6 +147,7 @@ private: bool m_terrain_offer{true}; bool m_terrain_buried_ask{true}; bool m_track_tools_more{false}; + bool m_track_card_folded{false}; bool m_terrain_while_laying{true}; terrain_model_settings m_terrain_model; std::map> m_terrain_model_offsets;