Skip to main content

ImGuiLogSink.ixx File

Log sink that forwards messages to a LogWidget. More...

Included Headers

#include <string> #include <helios.ext.imgui.widgets.LogWidget> #include <helios.util.log.LogSink>

Namespaces Index

namespacehelios
namespaceext

Platform-specific extensions and backend implementations. More...

namespaceimgui

Classes Index

classImGuiLogSink

LogSink implementation that forwards messages to a LogWidget. More...

Description

Log sink that forwards messages to a LogWidget.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ImGuiLogSink.ixx
3 * @brief Log sink that forwards messages to a LogWidget.
4 */
5module;
6
7#include <string>
8
9export module helios.ext.imgui.ImGuiLogSink;
10
11import helios.util.log.LogSink;
12import helios.ext.imgui.widgets.LogWidget;
13
14export namespace helios::ext::imgui {
15
16 /**
17 * @class ImGuiLogSink
18 * @brief LogSink implementation that forwards messages to a LogWidget.
19 *
20 * This sink bridges the helios logging system with the ImGui-based LogWidget,
21 * allowing log output to be displayed in the debug overlay instead of (or in
22 * addition to) the console.
23 *
24 * ```cpp
25 * auto logWidget = std::make_shared<widgets::LogWidget>();
26 * overlay.addWidget(logWidget.get());
27 *
28 * auto sink = std::make_shared<ImGuiLogSink>(logWidget.get());
29 * LogManager::getInstance().registerSink(sink);
30 * ```
31 */
32 class ImGuiLogSink : public helios::util::log::LogSink {
33
34 private:
35 /**
36 * @brief Pointer to the LogWidget to forward messages to.
37 */
38 widgets::LogWidget* widget_ = nullptr;
39
40 public:
41 /**
42 * @brief Unique type identifier for this sink.
43 */
44 static constexpr helios::util::log::SinkTypeId TYPE_ID = "imgui";
45
46 /**
47 * @brief Constructs an ImGuiLogSink attached to a LogWidget.
48 *
49 * @param widget Pointer to the LogWidget to receive messages.
50 * Must remain valid for the lifetime of this sink.
51 */
53 : widget_(widget) {}
54
55 /**
56 * @brief Returns the unique type identifier for this sink.
57 *
58 * @return "imgui".
59 */
60 [[nodiscard]] helios::util::log::SinkTypeId typeId() const noexcept override {
61 return TYPE_ID;
62 }
63
64 /**
65 * @brief Forwards a log message to the LogWidget.
66 *
67 * @param level The severity level of the message.
68 * @param scope The source scope/module name.
69 * @param message The log message text.
70 */
72 const std::string& scope,
73 const std::string& message) override {
74 if (!widget_) return;
75
76 // Map LogLevel to LogWidget's LogLevel
77 widgets::LogLevel widgetLevel;
78 switch (level) {
80 widgetLevel = widgets::LogLevel::Debug; break;
82 widgetLevel = widgets::LogLevel::Info; break;
84 widgetLevel = widgets::LogLevel::Warn; break;
86 widgetLevel = widgets::LogLevel::Error; break;
87 default:
88 widgetLevel = widgets::LogLevel::Info;
89 }
90
91 widget_->addLog(widgetLevel, scope, message);
92 }
93 };
94
95}
96

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.