refactor(debug): add d_rep template and remove widget ID

This commit is contained in:
2026-07-17 13:39:25 +08:00
parent 643b702aee
commit 8591d20e61
12 changed files with 81 additions and 54 deletions

View File

@@ -4,6 +4,7 @@
#include "Cubed/ui/label.hpp"
#include "Cubed/ui/widget.hpp"
#include <format>
#include <unordered_map>
namespace Cubed {
@@ -23,4 +24,11 @@ private:
std::unordered_map<std::string, Label*> m_component;
};
template <typename... Args>
void d_rep(const std::string& key, std::format_string<Args...> fmt,
Args&&... args) {
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
DebugCollector::get().report(key, msg);
}
} // namespace Cubed

View File

@@ -157,6 +157,36 @@ inline std::string get_cpu_info() {
#endif
}
inline std::string get_compiler_info() {
std::string result;
#if defined(__clang__)
result = "Clang ";
result += __clang_version__;
#elif defined(__GNUC__)
result = "GCC ";
result += std::to_string(__GNUC__);
result += ".";
result += std::to_string(__GNUC_MINOR__);
result += ".";
result += std::to_string(__GNUC_PATCHLEVEL__);
#elif defined(_MSC_VER)
result = "MSVC ";
result += std::to_string(_MSC_VER);
#else
result = "Unknown Compiler";
#endif
result += " (C++";
result += std::to_string(__cplusplus);
result += ")";
return result;
}
} // namespace Tools
} // namespace Cubed

View File

@@ -10,7 +10,6 @@ public:
Label& operator=(const Label&) = delete;
Label& operator=(Label&&) = delete;
Label(const std::string& id, Widget* parent);
Label(Widget* parent);
virtual ~Label() = default;

View File

@@ -25,12 +25,10 @@ public:
Widget& operator=(const Widget&) = delete;
Widget& operator=(Widget&&) = delete;
Widget(const std::string& id, Widget* parent);
Widget(Widget* parent);
virtual ~Widget() = default;
virtual void update(float dt);
virtual void render(Renderer& renderer);
virtual const std::string& id() const;
virtual Widget& set_anchor(Anchor anchor);
virtual Widget& set_offset(glm::ivec2 offset);
virtual Widget& set_window_size(int width, int height);
@@ -58,7 +56,6 @@ public:
protected:
Widget* m_parent = nullptr;
std::string m_id;
float m_window_height = 0;
float m_window_width = 0;
// Center is at the top-left corner, position is at the top-left corner