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

refactor(editor): the helpers repeated over the editor files are shared

The name of a node or "(no name)" was written out in twenty places and
four local functions, a lower-case copy of a text in four files, the
test for a number, the file name of a template made comparable and the
heading of a direction in three and two, the green main button of a
panel in five and the key=value parameters of a self-test command in
five. Each of them is one helper now: name_of, tall_button_height and
main_button with the panel helpers, numeric with format, normalized
with the include helpers, heading_of with the plan geometry and
selftest_values with the tools; lower gives way to ToLower.
This commit is contained in:
maj00r
2026-10-21 10:28:42 +02:00
parent 747c6817f0
commit 87bacede74
27 changed files with 137 additions and 218 deletions

View File

@@ -24,6 +24,25 @@ http://mozilla.org/MPL/2.0/.
float constexpr kDragPixels{5.0f};
template <typename Node_> inline std::string name_of(Node_ const &Node)
{
return Node.name().empty() ? std::string{STR_C("(no name)")} : Node.name();
}
inline float tall_button_height()
{
return std::round(ImGui::GetFrameHeight() * 1.3f);
}
inline bool main_button(char const *Label, ImVec2 const &Size)
{
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.55f, 0.25f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.25f, 0.65f, 0.3f, 1.0f));
auto const pressed{ImGui::Button(Label, Size)};
ImGui::PopStyleColor(2);
return pressed;
}
inline void item_tooltip(char const *Text)
{
if (ImGui::IsItemHovered())