17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 02:49:19 +02:00

refactor(editor): shared plan geometry and formatting helpers

This commit is contained in:
maj00r
2026-10-04 00:33:44 +02:00
parent 8778353b22
commit e5c91d8a1a
10 changed files with 392 additions and 487 deletions

26
editor/editorFormat.hpp Normal file
View File

@@ -0,0 +1,26 @@
/*
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
#include <cstdio>
#include <string>
// printf-style formatting into a string, for the messages and the data lines of the editor
template <typename... Args>
std::string format(char const *Format, Args... Arguments)
{
auto const length{std::snprintf(nullptr, 0, Format, Arguments...)};
if (length <= 0)
return {};
std::string text(static_cast<std::size_t>(length) + 1, '\0');
std::snprintf(text.data(), text.size(), Format, Arguments...);
text.resize(static_cast<std::size_t>(length));
return text;
}