mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 23:17:56 +01:00
f065098717
While the points of a line were clicked, the same things were told in four places at once: the card of the
tool with seven gestures, the panel (the points not laid, the buttons, the modes with their explanation,
the speed with its chips, the height, the curves with their legend), six lines by the cursor with the full
texts of the norms, and the gestures again in the bar under the view. The panel of the lay tool now goes by
states, each with one line of what to do now at its top (editor-lay-flow.md):
- Ready, nothing clicked: "Click on the ground or at a free end of a track" (with a curve traced: "Click
points along the curve on the photo"), and the three settings: the shape [Straights | Curve], with what it
makes of the points under the "?" beside it (a click opens its lesson), the radii of a curve traced in the
same place, the speed (the field and its chips), the height [Fitted | Point to point | Flat]. The rest
under More settings, the pieces added at the free end of the selected track there too.
- Clicking, a point or more: "Click the next bends" and the keys "Enter lays, Backspace takes back a point,
Esc drops". The line in one line, "Length 300 m, 2 curves, slowest 35 km/h", and a badge, green "meets the
norms" or orange "2 curves below the norms for 100 km/h"; "details" (or the badge) opens the curves one by
one, the breaches of the norms in their words, how the curves go on from those of the tracks joined, the
speed designed for, the grades and what the norms say where the line goes on from a switch. The legend of
the labels is by the cursor over a curve. [Lay (Enter)] as the main button and [Drop]. The settings
folded to one line, "Straights, 100 km/h, through the points" (a curve traced with its radii), a pencil at
its end opening them. The details open under it all, so the buttons stay where they are.
- Laid: back to ready, with one line over the settings, "Laid 214 m (14 tracks), Ctrl+Z undoes" in green,
the rest of what the laying told under "notes" beside it. It goes as the history moves on or back.
- Dragged out of a free end: "Drag to lay from the end; let go to lay it", the line of its length and
radius with the badge, the settings as the line of their summary. The drag tells the line laid as Enter
does.
- By the cursor, the leg drawn to it in a line or two: "straight 40 m", "curve R 76 m, up to 35 km/h" with
the sign of a warning (drawn, the font has no glyph of it) and the line in orange where it's below the
norms; joining a free end, the shape of the join, a line that can't be laid, Alt, the first Esc and what
Tab switched to. The texts of the norms are in the details only.
- The labels in the view short: "R 198, up to 60 km/h", orange below the norms; the straights as before.
- The bar under the view shows the three gestures of the state: ready "LMB the first point, LMB on a free
end from the end, Tab a curve from the photo"; clicking "LMB the next bend, Enter lay, Backspace take
back". The rest of them in the card unfolded and in F1, Ctrl+Shift+wheel (the speed) added there; the
length typed after the three.
Nothing is taken away: what the panel showed is behind a fold, the pencil, the "?" or F1. The messages the
lay tool logs for the self-tests keep their words, the line laid told as "Laid 214 m (14 tracks)" now.
The flow: application/editorflow.h, the step line, the summary line with its pencil, the badge with its
details, the message of one line with the rest in its tooltip, for the panels of other tools as well.
Self-test: expect laypanel <ready|clicking|laid|extending> <shown|folded>, and the case lf_1_lay_panel_states
through the states, in straights and in a curve traced.
lang/editor_pl.po: the Polish of the new texts as the spec words them; the laying texts of "the photo"
named the orthophoto as the rest of the editor ("na ortofotomapie", "z ortofotomapy").
180 lines
8.0 KiB
C++
180 lines
8.0 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
// the flow of the panel of a tool: one line of what to do now at its top, the settings folded to a line of their summary while
|
|
// they aren't being changed, what's being made as one line of its quality with a badge, the details of it on demand
|
|
|
|
#include "application/editormodeshared.h"
|
|
|
|
#include "imgui/imgui.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace editor_flow
|
|
{
|
|
|
|
ImVec4 constexpr kGood{0.40f, 0.85f, 0.45f, 1.0f};
|
|
ImVec4 constexpr kBelow{1.0f, 0.58f, 0.18f, 1.0f};
|
|
ImVec4 constexpr kRefused{1.0f, 0.38f, 0.30f, 1.0f};
|
|
|
|
// the sign of a warning in the text by the cursor: the font has no glyph of its own for it, a triangle is drawn in its place
|
|
inline constexpr std::string_view kWarningMark{" \xE2\x9A\xA0"};
|
|
|
|
// a pencil, drawn: the sign of a line which opens what it sums up for editing
|
|
inline void draw_pencil(ImDrawList &List, ImVec2 const Centre, float const Size, ImU32 const Colour)
|
|
{
|
|
auto const half{Size * 0.5f};
|
|
auto const thick{std::max(2.0f, std::round(Size * 0.26f)) * 0.5f};
|
|
float constexpr diagonal{0.70710678f};
|
|
// along the diagonal from the tip at the lower left to the end at the upper right; across it
|
|
ImVec2 const tip{Centre.x - half, Centre.y + half};
|
|
ImVec2 const end{Centre.x + half, Centre.y - half};
|
|
ImVec2 const across{diagonal * thick, diagonal * thick};
|
|
ImVec2 const neck{tip.x + diagonal * Size * 0.32f, tip.y - diagonal * Size * 0.32f};
|
|
List.AddQuadFilled(ImVec2(neck.x - across.x, neck.y - across.y), ImVec2(end.x - across.x, end.y - across.y), ImVec2(end.x + across.x, end.y + across.y), ImVec2(neck.x + across.x, neck.y + across.y), Colour);
|
|
List.AddTriangleFilled(ImVec2(neck.x - across.x, neck.y - across.y), ImVec2(neck.x + across.x, neck.y + across.y), tip, Colour);
|
|
}
|
|
|
|
// the sign of a warning, drawn: a triangle with the mark in it
|
|
inline void draw_warning(ImDrawList &List, ImVec2 const Centre, float const Size, ImU32 const Colour)
|
|
{
|
|
auto const half{Size * 0.5f};
|
|
List.AddTriangleFilled(ImVec2(Centre.x, Centre.y - half), ImVec2(Centre.x + half * 1.1f, Centre.y + half * 0.85f), ImVec2(Centre.x - half * 1.1f, Centre.y + half * 0.85f), Colour);
|
|
auto const ink{IM_COL32(20, 20, 20, 255)};
|
|
List.AddLine(ImVec2(Centre.x, Centre.y - half * 0.3f), ImVec2(Centre.x, Centre.y + half * 0.3f), ink, std::max(1.0f, Size * 0.13f));
|
|
List.AddCircleFilled(ImVec2(Centre.x, Centre.y + half * 0.58f), std::max(1.0f, Size * 0.07f), ink);
|
|
}
|
|
|
|
// the one line of what to do now, at the top of the panel of the tool: larger and white, with the accent of the tools of building at
|
|
// its left; the keys of the step under it, dimmed
|
|
inline void step_line(char const *Text, char const *Keys = nullptr)
|
|
{
|
|
auto *list{ImGui::GetWindowDrawList()};
|
|
auto const font{ImGui::GetFontSize()};
|
|
auto const top{ImGui::GetCursorScreenPos()};
|
|
auto const bar{std::max(3.0f, std::round(font * 0.22f))};
|
|
auto const indent{bar + std::round(font * 0.5f)};
|
|
ImGui::Indent(indent);
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
ImGui::SetWindowFontScale(1.12f);
|
|
ImGui::TextWrapped("%s", Text);
|
|
ImGui::SetWindowFontScale(1.0f);
|
|
ImGui::PopStyleColor();
|
|
if (Keys != nullptr && *Keys != '\0')
|
|
{
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
|
|
ImGui::TextWrapped("%s", Keys);
|
|
ImGui::PopStyleColor();
|
|
}
|
|
auto const bottom{ImGui::GetItemRectMax().y};
|
|
ImGui::Unindent(indent);
|
|
list->AddRectFilled(top, ImVec2(top.x + bar, bottom), family_colour(0), bar * 0.5f);
|
|
ImGui::Spacing();
|
|
}
|
|
|
|
// settings folded to the line of their summary, a pencil at its end: a click on it opens them, another one folds them again; true when
|
|
// clicked
|
|
inline bool summary_line(char const *Id, std::string const &Text, bool const Open, char const *Tooltip = nullptr)
|
|
{
|
|
auto const height{ImGui::GetFrameHeight()};
|
|
auto const width{std::max(1.0f, ImGui::GetContentRegionAvail().x)};
|
|
auto const at{ImGui::GetCursorScreenPos()};
|
|
ImGui::PushID(Id);
|
|
auto const clicked{ImGui::InvisibleButton("##summary", ImVec2(width, height))};
|
|
ImGui::PopID();
|
|
auto const hovered{ImGui::IsItemHovered()};
|
|
if (hovered)
|
|
{
|
|
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
if (Tooltip != nullptr && *Tooltip != '\0')
|
|
ImGui::SetTooltip("%s", Tooltip);
|
|
}
|
|
auto *list{ImGui::GetWindowDrawList()};
|
|
list->AddRectFilled(at, ImVec2(at.x + width, at.y + height), ImGui::GetColorU32(hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), std::round(height * 0.3f));
|
|
auto const pad{std::round(ImGui::GetStyle().FramePadding.x)};
|
|
auto const pencil{std::round(height * 0.5f)};
|
|
auto const right{at.x + width - pad - pencil};
|
|
list->PushClipRect(at, ImVec2(right - pad, at.y + height), true);
|
|
list->AddText(ImVec2(at.x + pad, std::round(at.y + (height - ImGui::GetTextLineHeight()) * 0.5f)), ImGui::GetColorU32(ImGuiCol_Text), Text.c_str());
|
|
list->PopClipRect();
|
|
auto const colour{Open ? family_colour(0) : ImGui::GetColorU32(hovered ? ImGuiCol_Text : ImGuiCol_TextDisabled)};
|
|
draw_pencil(*list, ImVec2(right + pencil * 0.5f, at.y + height * 0.5f), pencil, colour);
|
|
return clicked;
|
|
}
|
|
|
|
// a link which opens what it names under it and folds it again, a marker after it pointing right while folded, down while open; true
|
|
// when clicked
|
|
inline bool fold_link(char const *Id, char const *Text, bool &Open)
|
|
{
|
|
auto const size{ImGui::CalcTextSize(Text)};
|
|
auto const mark{std::round(ImGui::GetFontSize() * 0.3f)};
|
|
auto const height{ImGui::GetFrameHeight()};
|
|
auto const at{ImGui::GetCursorScreenPos()};
|
|
ImGui::PushID(Id);
|
|
auto const clicked{ImGui::InvisibleButton("##fold", ImVec2(size.x + mark * 3.5f, height))};
|
|
ImGui::PopID();
|
|
auto const hovered{ImGui::IsItemHovered()};
|
|
if (hovered)
|
|
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
auto *list{ImGui::GetWindowDrawList()};
|
|
auto const colour{ImGui::GetColorU32(hovered || Open ? ImGuiCol_Text : ImGuiCol_TextDisabled)};
|
|
auto const y{std::round(at.y + (height - size.y) * 0.5f)};
|
|
list->AddText(ImVec2(at.x, y), colour, Text);
|
|
list->AddLine(ImVec2(at.x, y + size.y), ImVec2(at.x + size.x, y + size.y), (colour & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 110));
|
|
ImVec2 const centre{at.x + size.x + mark * 2.0f, at.y + height * 0.5f};
|
|
if (Open)
|
|
list->AddTriangleFilled(ImVec2(centre.x - mark, centre.y - mark * 0.6f), ImVec2(centre.x + mark, centre.y - mark * 0.6f), ImVec2(centre.x, centre.y + mark * 0.8f), colour);
|
|
else
|
|
list->AddTriangleFilled(ImVec2(centre.x - mark * 0.6f, centre.y - mark), ImVec2(centre.x - mark * 0.6f, centre.y + mark), ImVec2(centre.x + mark * 0.8f, centre.y), colour);
|
|
if (clicked)
|
|
Open = !Open;
|
|
return clicked;
|
|
}
|
|
|
|
// the quality of what's being made at a glance: a badge, green where it meets what it should, orange where it doesn't, and beside it the
|
|
// link to the details it sums up; a click on either opens them
|
|
inline void quality_badge(char const *Id, char const *Text, bool const Good, char const *Details, bool &Open)
|
|
{
|
|
ImGui::PushID(Id);
|
|
if (state_chip(Text, Good ? kGood : kBelow))
|
|
Open = !Open;
|
|
auto const room{ImGui::CalcTextSize(Details).x + ImGui::GetFontSize() * 1.2f};
|
|
same_line_if_fits(room);
|
|
fold_link("##details", Details, Open);
|
|
ImGui::PopID();
|
|
}
|
|
|
|
// one line of a message in its colour, the rest of it in the tooltip of the line; true when the message has more lines than the one
|
|
inline bool message_line(std::string_view const Text, ImVec4 const &Colour)
|
|
{
|
|
auto const end{Text.find('\n')};
|
|
std::string const first{Text.substr(0, end)};
|
|
ImGui::PushStyleColor(ImGuiCol_Text, Colour);
|
|
ImGui::TextWrapped("%s", first.c_str());
|
|
ImGui::PopStyleColor();
|
|
if (end == std::string_view::npos)
|
|
return false;
|
|
if (ImGui::IsItemHovered())
|
|
{
|
|
std::string const rest{Text.substr(end + 1)};
|
|
ImGui::BeginTooltip();
|
|
ImGui::PushTextWrapPos(std::round(ImGui::GetFontSize() * 32.0f));
|
|
ImGui::TextUnformatted(rest.c_str());
|
|
ImGui::PopTextWrapPos();
|
|
ImGui::EndTooltip();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} // namespace editor_flow
|