aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/common/Base.hpp4
-rw-r--r--include/cru/common/Logger.hpp34
-rw-r--r--include/cru/ui/ClickDetector.hpp3
-rw-r--r--include/cru/ui/UiHost.hpp2
-rw-r--r--include/cru/ui/render/BorderRenderObject.hpp2
-rw-r--r--include/cru/ui/render/FlexLayoutRenderObject.hpp2
-rw-r--r--include/cru/ui/render/LayoutHelper.hpp3
-rw-r--r--include/cru/ui/render/RenderObject.hpp2
-rw-r--r--include/cru/ui/render/StackLayoutRenderObject.hpp2
-rw-r--r--include/cru/ui/render/TextRenderObject.hpp2
-rw-r--r--include/cru/win/native/Cursor.hpp2
-rw-r--r--include/cru/win/native/GodWindow.hpp2
-rw-r--r--include/cru/win/native/InputMethod.hpp6
-rw-r--r--include/cru/win/native/Window.hpp4
14 files changed, 63 insertions, 7 deletions
diff --git a/include/cru/common/Base.hpp b/include/cru/common/Base.hpp
index ff7ab31e..409c2b0e 100644
--- a/include/cru/common/Base.hpp
+++ b/include/cru/common/Base.hpp
@@ -44,4 +44,8 @@ struct Interface {
}
using Index = gsl::index;
+
+#define CRU_DEFINE_CLASS_LOG_TAG(tag) \
+ private: \
+ constexpr static std::string_view log_tag = tag;
} // namespace cru
diff --git a/include/cru/common/Logger.hpp b/include/cru/common/Logger.hpp
index bd16678b..f76e4626 100644
--- a/include/cru/common/Logger.hpp
+++ b/include/cru/common/Logger.hpp
@@ -15,7 +15,7 @@ enum class LogLevel { Debug, Info, Warn, Error };
struct ILogSource : virtual Interface {
// Write the string s. LogLevel is just a helper. It has no effect on the
// content to write.
- virtual void Write(LogLevel level, const std::string_view& s) = 0;
+ virtual void Write(LogLevel level, std::string_view s) = 0;
};
class StdioLogSource : public virtual ILogSource {
@@ -27,7 +27,7 @@ class StdioLogSource : public virtual ILogSource {
~StdioLogSource() override = default;
- void Write(LogLevel level, const std::string_view& s) override {
+ void Write(LogLevel level, std::string_view s) override {
// TODO: Emmm... Since it is buggy to use narrow char in UTF-8 on Windows. I
// think this implementation might be broken. (However, I didn't test it.)
// Maybe, I should detect Windows and use wide char (And I didn't test this
@@ -58,7 +58,8 @@ class Logger : public Object {
void RemoveSource(ILogSource* source);
public:
- void Log(LogLevel level, const std::string_view& s);
+ void Log(LogLevel level, std::string_view s);
+ void Log(LogLevel level, std::string_view tag, std::string_view s);
public:
std::list<std::unique_ptr<ILogSource>> sources_;
@@ -89,4 +90,31 @@ void Error(TArgs&&... args) {
Logger::GetInstance()->Log(LogLevel::Error,
fmt::format(std::forward<TArgs>(args)...));
}
+
+template <typename... TArgs>
+void TagDebug([[maybe_unused]] std::string_view tag,
+ [[maybe_unused]] TArgs&&... args) {
+#ifdef CRU_DEBUG
+ Logger::GetInstance()->Log(LogLevel::Debug, tag,
+ fmt::format(std::forward<TArgs>(args)...));
+#endif
+}
+
+template <typename... TArgs>
+void TagInfo(std::string_view tag, TArgs&&... args) {
+ Logger::GetInstance()->Log(LogLevel::Info, tag,
+ fmt::format(std::forward<TArgs>(args)...));
+}
+
+template <typename... TArgs>
+void TagWarn(std::string_view tag, TArgs&&... args) {
+ Logger::GetInstance()->Log(LogLevel::Warn, tag,
+ fmt::format(std::forward<TArgs>(args)...));
+}
+
+template <typename... TArgs>
+void TagError(std::string_view tag, TArgs&&... args) {
+ Logger::GetInstance()->Log(LogLevel::Error, tag,
+ fmt::format(std::forward<TArgs>(args)...));
+}
} // namespace cru::log
diff --git a/include/cru/ui/ClickDetector.hpp b/include/cru/ui/ClickDetector.hpp
index f5fd3d8f..3977fb8e 100644
--- a/include/cru/ui/ClickDetector.hpp
+++ b/include/cru/ui/ClickDetector.hpp
@@ -1,7 +1,6 @@
#pragma once
#include "Control.hpp"
-
namespace cru::ui {
class ClickEventArgs : Object {
public:
@@ -37,6 +36,8 @@ enum class ClickState {
};
class ClickDetector : public Object {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::ClickDetector")
+
public:
explicit ClickDetector(Control* control);
diff --git a/include/cru/ui/UiHost.hpp b/include/cru/ui/UiHost.hpp
index 651dab81..1a5c6302 100644
--- a/include/cru/ui/UiHost.hpp
+++ b/include/cru/ui/UiHost.hpp
@@ -32,6 +32,8 @@ struct AfterLayoutEventArgs {};
// 4. Delete Window when deleting_ is false and IsRetainAfterDestroy is false in
// OnNativeDestroy.
class UiHost : public Object, public SelfResolvable<UiHost> {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::UiHost")
+
public:
// This will create root window render object and attach it to window.
// It will also create and manage a native window.
diff --git a/include/cru/ui/render/BorderRenderObject.hpp b/include/cru/ui/render/BorderRenderObject.hpp
index db989453..94e888d4 100644
--- a/include/cru/ui/render/BorderRenderObject.hpp
+++ b/include/cru/ui/render/BorderRenderObject.hpp
@@ -3,6 +3,8 @@
namespace cru::ui::render {
class BorderRenderObject : public RenderObject {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::BorderRenderObject")
+
public:
BorderRenderObject();
BorderRenderObject(const BorderRenderObject& other) = delete;
diff --git a/include/cru/ui/render/FlexLayoutRenderObject.hpp b/include/cru/ui/render/FlexLayoutRenderObject.hpp
index 4b1e079d..87a41c7e 100644
--- a/include/cru/ui/render/FlexLayoutRenderObject.hpp
+++ b/include/cru/ui/render/FlexLayoutRenderObject.hpp
@@ -74,6 +74,8 @@ namespace cru::ui::render {
// and just fill the rest space with blank.
//
class FlexLayoutRenderObject : public LayoutRenderObject<FlexChildLayoutData> {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::FlexLayoutRenderObject")
+
public:
FlexLayoutRenderObject() = default;
FlexLayoutRenderObject(const FlexLayoutRenderObject& other) = delete;
diff --git a/include/cru/ui/render/LayoutHelper.hpp b/include/cru/ui/render/LayoutHelper.hpp
index 8536c451..3469ccf0 100644
--- a/include/cru/ui/render/LayoutHelper.hpp
+++ b/include/cru/ui/render/LayoutHelper.hpp
@@ -9,5 +9,6 @@ float CalculateAnchorByAlignment(Alignment alignment, float start_point,
MeasureLength StackLayoutCalculateChildMaxLength(
MeasureLength parent_preferred_size, MeasureLength parent_max_size,
- MeasureLength child_min_size, std::string_view exceeds_message);
+ MeasureLength child_min_size, std::string_view log_tag,
+ std::string_view exceeds_message);
} // namespace cru::ui::render
diff --git a/include/cru/ui/render/RenderObject.hpp b/include/cru/ui/render/RenderObject.hpp
index 2d9cd817..2e784afc 100644
--- a/include/cru/ui/render/RenderObject.hpp
+++ b/include/cru/ui/render/RenderObject.hpp
@@ -37,6 +37,8 @@ namespace cru::ui::render {
class RenderObject : public Object {
friend WindowRenderObject;
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::RenderObject")
+
protected:
enum class ChildMode {
None,
diff --git a/include/cru/ui/render/StackLayoutRenderObject.hpp b/include/cru/ui/render/StackLayoutRenderObject.hpp
index f6b4ffb7..534d7f22 100644
--- a/include/cru/ui/render/StackLayoutRenderObject.hpp
+++ b/include/cru/ui/render/StackLayoutRenderObject.hpp
@@ -23,6 +23,8 @@ namespace cru::ui::render {
// to min size.
class StackLayoutRenderObject
: public LayoutRenderObject<StackChildLayoutData> {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render:StackLayoutRenderObject")
+
public:
StackLayoutRenderObject() = default;
CRU_DELETE_COPY(StackLayoutRenderObject)
diff --git a/include/cru/ui/render/TextRenderObject.hpp b/include/cru/ui/render/TextRenderObject.hpp
index 26c8db40..77a92b4f 100644
--- a/include/cru/ui/render/TextRenderObject.hpp
+++ b/include/cru/ui/render/TextRenderObject.hpp
@@ -18,6 +18,8 @@ namespace cru::ui::render {
// If the result layout box is bigger than actual text box, then text is center
// aligned.
class TextRenderObject : public RenderObject {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::TextRenderObject")
+
public:
constexpr static float default_caret_width = 2;
diff --git a/include/cru/win/native/Cursor.hpp b/include/cru/win/native/Cursor.hpp
index 152374d8..44a6a362 100644
--- a/include/cru/win/native/Cursor.hpp
+++ b/include/cru/win/native/Cursor.hpp
@@ -7,6 +7,8 @@
namespace cru::platform::native::win {
class WinCursor : public WinNativeResource, public virtual ICursor {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::WinCursor")
+
public:
WinCursor(HCURSOR handle, bool auto_destroy);
diff --git a/include/cru/win/native/GodWindow.hpp b/include/cru/win/native/GodWindow.hpp
index 1dd99661..0820bdb3 100644
--- a/include/cru/win/native/GodWindow.hpp
+++ b/include/cru/win/native/GodWindow.hpp
@@ -5,6 +5,8 @@
namespace cru::platform::native::win {
class GodWindow : public Object {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::GodWindow")
+
public:
explicit GodWindow(WinUiApplication* application);
diff --git a/include/cru/win/native/InputMethod.hpp b/include/cru/win/native/InputMethod.hpp
index 0e9634aa..45422ace 100644
--- a/include/cru/win/native/InputMethod.hpp
+++ b/include/cru/win/native/InputMethod.hpp
@@ -5,13 +5,15 @@
#pragma once
#include "Resource.hpp"
-#include "cru/platform/native/InputMethod.hpp"
#include "WindowNativeMessageEventArgs.hpp"
+#include "cru/platform/native/InputMethod.hpp"
#include <imm.h>
namespace cru::platform::native::win {
class AutoHIMC : public Object {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::AutoHIMC")
+
public:
explicit AutoHIMC(HWND hwnd);
@@ -33,6 +35,8 @@ class AutoHIMC : public Object {
class WinInputMethodContext : public WinNativeResource,
public virtual IInputMethodContext {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::WinInputMethodContext")
+
public:
WinInputMethodContext(gsl::not_null<WinNativeWindow*> window);
diff --git a/include/cru/win/native/Window.hpp b/include/cru/win/native/Window.hpp
index 80bee39e..521a0a06 100644
--- a/include/cru/win/native/Window.hpp
+++ b/include/cru/win/native/Window.hpp
@@ -1,13 +1,15 @@
#pragma once
#include "Resource.hpp"
-#include "cru/platform/native/Window.hpp"
#include "WindowNativeMessageEventArgs.hpp"
+#include "cru/platform/native/Window.hpp"
#include <memory>
namespace cru::platform::native::win {
class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::WinNativeWindow")
+
public:
WinNativeWindow(WinUiApplication* application, WindowClass* window_class,
DWORD window_style, WinNativeWindow* parent);