diff options
author | crupest <crupest@outlook.com> | 2020-06-29 00:31:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-29 00:31:21 +0800 |
commit | 5c3dae62b9218dbd2493ff6390db062013ca4bdc (patch) | |
tree | 3425a9efa118eaf89627e6903cecb50a3daedb1d | |
parent | 6b5aff7b7e50fae15cb010b340099163725f664c (diff) | |
download | cru-5c3dae62b9218dbd2493ff6390db062013ca4bdc.tar.gz cru-5c3dae62b9218dbd2493ff6390db062013ca4bdc.tar.bz2 cru-5c3dae62b9218dbd2493ff6390db062013ca4bdc.zip |
...
29 files changed, 171 insertions, 105 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); diff --git a/src/common/Logger.cpp b/src/common/Logger.cpp index ed9f9e64..da55047a 100644 --- a/src/common/Logger.cpp +++ b/src/common/Logger.cpp @@ -42,12 +42,12 @@ std::string_view LogLevelToString(LogLevel level) { case LogLevel::Error: return "ERROR"; default: - std::abort(); + std::terminate(); } } } // namespace -void Logger::Log(LogLevel level, const std::string_view &s) { +void Logger::Log(LogLevel level, std::string_view s) { #ifndef CRU_DEBUG if (level == LogLevel::Debug) { return; @@ -62,4 +62,20 @@ void Logger::Log(LogLevel level, const std::string_view &s) { LogLevelToString(level), s)); } } + +void Logger::Log(LogLevel level, std::string_view tag, std::string_view s) { +#ifndef CRU_DEBUG + if (level == LogLevel::Debug) { + return; + } +#endif + for (const auto &source : sources_) { + auto now = std::time(nullptr); + std::array<char, 50> buffer; + std::strftime(buffer.data(), 50, "%c", std::localtime(&now)); + + source->Write(level, fmt::format("[{}] {} {}: {}\n", buffer.data(), + LogLevelToString(level), tag, s)); + } +} } // namespace cru::log diff --git a/src/ui/ClickDetector.cpp b/src/ui/ClickDetector.cpp index e873efd4..93e6f303 100644 --- a/src/ui/ClickDetector.cpp +++ b/src/ui/ClickDetector.cpp @@ -44,7 +44,8 @@ ClickDetector::ClickDetector(Control* control) { if (this->enable_ && (button & this->trigger_button_) && this->state_ == ClickState::Hover) { if (!this->control_->CaptureMouse()) { - log::Debug("Failed to capture mouse when begin click."); + log::TagDebug(log_tag, + "Failed to capture mouse when begin click."); return; } this->down_point_ = args.GetPoint(); @@ -120,7 +121,8 @@ void ClickDetector::SetState(ClickState state) { UnreachableCode(); } }; - log::Debug("Click state changed, new state: {}.", to_string(state)); + log::TagDebug(log_tag, "Click state changed, new state: {}.", + to_string(state)); #endif state_ = state; diff --git a/src/ui/UiHost.cpp b/src/ui/UiHost.cpp index 9bde06ad..975d0ffe 100644 --- a/src/ui/UiHost.cpp +++ b/src/ui/UiHost.cpp @@ -146,14 +146,13 @@ void UiHost::InvalidatePaint() { } void UiHost::InvalidateLayout() { + log::TagDebug(log_tag, "A relayout is requested."); if (!need_layout_) { platform::native::IUiApplication::GetInstance()->InvokeLater( [resolver = this->CreateResolver()] { if (const auto host = resolver.Resolve()) { host->Relayout(); host->need_layout_ = false; - host->after_layout_event_.Raise(AfterLayoutEventArgs{}); - log::Debug("A relayout finished."); host->InvalidatePaint(); } }); @@ -171,6 +170,8 @@ void UiHost::Relayout() { render::MeasureSize::NotSpecified()}, render::MeasureSize::NotSpecified()); root_render_object_->Layout(Point{}); + after_layout_event_.Raise(AfterLayoutEventArgs{}); + log::TagDebug(log_tag, "A relayout is finished."); } bool UiHost::RequestFocusFor(Control* control) { diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp index ad0db343..c320b0c5 100644 --- a/src/ui/controls/TextControlService.hpp +++ b/src/ui/controls/TextControlService.hpp @@ -5,9 +5,9 @@ #include "cru/platform/graph/Painter.hpp" #include "cru/platform/native/UiApplication.hpp" #include "cru/ui/Control.hpp" +#include "cru/ui/UiEvent.hpp" #include "cru/ui/render/CanvasRenderObject.hpp" #include "cru/ui/render/TextRenderObject.hpp" -#include "cru/ui/UiEvent.hpp" namespace cru::ui::controls { constexpr int k_default_caret_blink_duration = 500; @@ -18,6 +18,8 @@ constexpr int k_default_caret_blink_duration = 500; // ``` template <typename TControl> class TextControlService : public Object { + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::controls::TextControlService") + public: TextControlService(TControl* control); @@ -175,10 +177,9 @@ void TextControlService<TControl>::MouseMoveHandler( const auto result = text_render_object->TextHitTest( text_render_object->FromRootToContent(args.GetPoint())); const auto position = result.position + (result.trailing ? 1 : 0); - log::Debug( - "TextControlService: Text selection changed on mouse move, range: {}, " - "{}.", - position, this->select_start_position_); + log::TagDebug(log_tag, + "Text selection changed on mouse move, range: {}, {}.", + position, this->select_start_position_); this->control_->GetTextRenderObject()->SetSelectionRange( TextRange::FromTwoSides( static_cast<unsigned>(position), @@ -203,8 +204,8 @@ void TextControlService<TControl>::MouseDownHandler( text_render_object->SetSelectionRange(std::nullopt); text_render_object->SetCaretPosition(position); this->select_start_position_ = position; - log::Debug("TextControlService: Begin to select text, start position: {}.", - position); + log::TagDebug(log_tag, "Begin to select text, start position: {}.", + position); } } @@ -215,7 +216,7 @@ void TextControlService<TControl>::MouseUpHandler( this->select_down_button_.value() == args.GetButton()) { this->control_->ReleaseMouse(); this->select_down_button_ = std::nullopt; - log::Debug("TextControlService: End selecting text."); + log::TagDebug(log_tag, "End selecting text."); } } diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index 6513c4c4..f2e3eb9b 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -57,7 +57,7 @@ void BorderRenderObject::OnDrawCore(platform::graph::IPainter* painter) { background_brush_.get()); if (is_border_enabled_) { if (border_brush_ == nullptr) { - log::Warn("Border is enabled but brush is null"); + log::TagWarn(log_tag, "Border is enabled but border brush is null."); } else { painter->FillGeometry(geometry_.get(), border_brush_.get()); } @@ -93,9 +93,9 @@ Size BorderRenderObject::OnMeasureCore(const MeasureRequirement& requirement, if (!requirement.max.width.IsNotSpecified()) { const auto max_width = requirement.max.width.GetLengthOrMax(); if (coerced_space_size.width > max_width) { - log::Warn( - "BorderRenderObject: During measure, horizontal length of padding, " - "border and margin is bigger than required max length."); + log::TagWarn(log_tag, + "(Measure) Horizontal length of padding, border and margin " + "is bigger than required max length."); coerced_space_size.width = max_width; } content_requirement.max.width = max_width - coerced_space_size.width; @@ -109,9 +109,9 @@ Size BorderRenderObject::OnMeasureCore(const MeasureRequirement& requirement, if (!requirement.max.height.IsNotSpecified()) { const auto max_height = requirement.max.height.GetLengthOrMax(); if (coerced_space_size.height > max_height) { - log::Warn( - "BorderRenderObject: During measure, vertical length of padding, " - "border and margin is bigger than required max length."); + log::TagWarn(log_tag, + "(Measure) Vertical length of padding, border and margin is " + "bigger than required max length."); coerced_space_size.height = max_height; } content_requirement.max.height = max_height - coerced_space_size.height; @@ -149,15 +149,9 @@ void BorderRenderObject::OnLayoutCore() { auto content_size = size - space_size; if (content_size.width < 0) { - log::Warn( - "BorderRenderObject: During layout, horizontal length of padding, " - "border and margin is bigger than available length."); content_size.width = 0; } if (content_size.height < 0) { - log::Warn( - "BorderRenderObject: During layout, vertical length of padding, " - "border and margin is bigger than available length."); content_size.height = 0; } diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 9e5139ff..8e6b41fe 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -87,7 +87,8 @@ template <typename direction_tag_t, Size FlexLayoutMeasureContentImpl( const MeasureRequirement& requirement, const MeasureSize& preferred_size, const std::vector<RenderObject*>& children, - const std::vector<FlexChildLayoutData>& layout_data) { + const std::vector<FlexChildLayoutData>& layout_data, + std::string_view log_tag) { Expects(children.size() == layout_data.size()); direction_tag_t direction_tag; @@ -109,9 +110,9 @@ Size FlexLayoutMeasureContentImpl( child_cross_measure_requirement.push_back( StackLayoutCalculateChildMaxLength( preferred_cross_length, max_cross_length, - GetCross(child->GetMinSize(), direction_tag), - "StackLayoutRenderObject: Child's min cross size is bigger than " - "parent's max cross size.")); + GetCross(child->GetMinSize(), direction_tag), log_tag, + "(Measure) Child's min cross size is bigger than parent's max " + "cross size.")); } // step 1. @@ -312,9 +313,9 @@ Size FlexLayoutMeasureContentImpl( if (max_main_length.IsSpecified() && total_length > max_main_length.GetLengthOrUndefined()) { - log::Warn( - "FlexLayoutRenderObject: Children's main axis length exceeds required " - "max length."); + log::TagWarn( + log_tag, + "(Measure) Children's main axis length exceeds required max length."); total_length = max_main_length.GetLengthOrUndefined(); } else if (min_main_length.IsSpecified() && total_length < min_main_length.GetLengthOrUndefined()) { @@ -336,10 +337,12 @@ Size FlexLayoutRenderObject::OnMeasureContent( direction_ == FlexDirection::HorizontalReverse); if (horizontal) { return FlexLayoutMeasureContentImpl<tag_horizontal_t>( - requirement, preferred_size, GetChildren(), GetChildLayoutDataList()); + requirement, preferred_size, GetChildren(), GetChildLayoutDataList(), + log_tag); } else { return FlexLayoutMeasureContentImpl<tag_vertical_t>( - requirement, preferred_size, GetChildren(), GetChildLayoutDataList()); + requirement, preferred_size, GetChildren(), GetChildLayoutDataList(), + log_tag); } } diff --git a/src/ui/render/LayoutHelper.cpp b/src/ui/render/LayoutHelper.cpp index 31cf5c08..9f94b84d 100644 --- a/src/ui/render/LayoutHelper.cpp +++ b/src/ui/render/LayoutHelper.cpp @@ -19,9 +19,10 @@ 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) { if (parent_max_size.GetLengthOrMax() < child_min_size.GetLengthOr0()) { - log::Warn(exceeds_message); + log::TagWarn(log_tag, exceeds_message); return parent_max_size; } diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index d9977f2a..66b62e6e 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -151,9 +151,9 @@ Size RenderObject::OnMeasureCore(const MeasureRequirement& requirement, if (!requirement.max.width.IsNotSpecified()) { const auto max_width = requirement.max.width.GetLengthOrMax(); if (coerced_space_size.width > max_width) { - log::Warn( - "RenderObject: During measure, horizontal length of padding and " - "margin is bigger than required max length."); + log::TagWarn(log_tag, + "(Measure) Horizontal length of padding and margin is " + "bigger than required max length."); coerced_space_size.width = max_width; } content_requirement.max.width = max_width - coerced_space_size.width; @@ -167,9 +167,9 @@ Size RenderObject::OnMeasureCore(const MeasureRequirement& requirement, if (!requirement.max.height.IsNotSpecified()) { const auto max_height = requirement.max.height.GetLengthOrMax(); if (coerced_space_size.height > max_height) { - log::Warn( - "RenderObject: During measure, vertical length of padding and " - "margin is bigger than required max length."); + log::TagWarn(log_tag, + "(Measure) Vertical length of padding and margin is bigger " + "than required max length."); coerced_space_size.height = max_height; } content_requirement.max.height = max_height - coerced_space_size.height; @@ -198,15 +198,9 @@ void RenderObject::OnLayoutCore() { auto content_size = total_size - space_size; if (content_size.width < 0) { - log::Warn( - "RenderObject: During layout, horizontal length of padding and margin " - "is bigger than available length."); content_size.width = 0; } if (content_size.height < 0) { - log::Warn( - "RenderObject: During layout, vertical length of padding and margin " - "is bigger than available length."); content_size.height = 0; } diff --git a/src/ui/render/StackLayoutRenderObject.cpp b/src/ui/render/StackLayoutRenderObject.cpp index a6ed7708..168ff379 100644 --- a/src/ui/render/StackLayoutRenderObject.cpp +++ b/src/ui/render/StackLayoutRenderObject.cpp @@ -14,14 +14,14 @@ Size StackLayoutRenderObject::OnMeasureContent( MeasureRequirement{ MeasureSize{StackLayoutCalculateChildMaxLength( preferred_size.width, requirement.max.width, - child->GetMinSize().width, - "StackLayoutRenderObject: Child's min width is " - "bigger than parent's max width."), + child->GetMinSize().width, log_tag, + "(Measure) Child's min width is bigger than " + "parent's max width."), StackLayoutCalculateChildMaxLength( preferred_size.height, requirement.max.height, - child->GetMinSize().height, - "StackLayoutRenderObject: Child's min height is " - "bigger than parent's max height.")}, + child->GetMinSize().height, log_tag, + "(Measure) Child's min height is bigger than " + "parent's max height.")}, MeasureSize::NotSpecified()}, MeasureSize::NotSpecified()); const auto size = child->GetSize(); diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index ce1c3fa3..87a3c352 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -170,8 +170,8 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, if (requirement.max.width.IsSpecified() && text_size.width > requirement.max.width.GetLengthOrUndefined()) { - log::Warn( - "TextRenderObject: Text actual width exceeds the required max width."); + log::TagWarn(log_tag, + "(Measure) Text actual width exceeds the required max width."); result.width = requirement.max.width.GetLengthOrUndefined(); } else { result.width = std::max(result.width, preferred_size.width.GetLengthOr0()); @@ -180,9 +180,9 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, if (requirement.max.height.IsSpecified() && text_size.height > requirement.max.height.GetLengthOrUndefined()) { - log::Warn( - "TextRenderObject: Text actual height exceeds the required max " - "height."); + log::TagWarn( + log_tag, + "(Measure) Text actual height exceeds the required max height."); result.height = requirement.max.height.GetLengthOrUndefined(); } else { result.height = diff --git a/src/win/DebugLogger.hpp b/src/win/DebugLogger.hpp index 381803bc..4ca1567b 100644 --- a/src/win/DebugLogger.hpp +++ b/src/win/DebugLogger.hpp @@ -14,7 +14,7 @@ class WinDebugLoggerSource : public ::cru::log::ILogSource { ~WinDebugLoggerSource() = default; - void Write(::cru::log::LogLevel level, const std::string_view& s) override { + void Write(::cru::log::LogLevel level, std::string_view s) override { CRU_UNUSED(level) const std::wstring&& ws = ToUtf16String(s); diff --git a/src/win/native/Cursor.cpp b/src/win/native/Cursor.cpp index ca8bb1cd..a6ab5bfc 100644 --- a/src/win/native/Cursor.cpp +++ b/src/win/native/Cursor.cpp @@ -16,8 +16,8 @@ WinCursor::~WinCursor() { if (!::DestroyCursor(handle_)) { // This is not a fetal error but might still need notice because it may // cause leak. - log::Warn("Failed to destroy a cursor. Last error code: {}", - ::GetLastError()); + log::TagWarn(log_tag, "Failed to destroy a cursor. Last error code: {}", + ::GetLastError()); } } } diff --git a/src/win/native/GodWindow.cpp b/src/win/native/GodWindow.cpp index 076954d4..8ef2788e 100644 --- a/src/win/native/GodWindow.cpp +++ b/src/win/native/GodWindow.cpp @@ -1,11 +1,11 @@ #include "cru/win/native/GodWindow.hpp" +#include "GodWindowMessage.hpp" +#include "Timer.hpp" #include "cru/common/Logger.hpp" #include "cru/win/native/Exception.hpp" #include "cru/win/native/UiApplication.hpp" #include "cru/win/native/WindowClass.hpp" -#include "GodWindowMessage.hpp" -#include "Timer.hpp" namespace cru::platform::native::win { constexpr auto god_window_class_name = L"GodWindowClass"; @@ -45,7 +45,7 @@ GodWindow::GodWindow(WinUiApplication* application) { GodWindow::~GodWindow() { if (!::DestroyWindow(hwnd_)) { // Although this could be "safely" ignore. - log::Warn("Failed to destroy god window."); + log::TagWarn(log_tag, "Failed to destroy god window."); } } diff --git a/src/win/native/InputMethod.cpp b/src/win/native/InputMethod.cpp index 2e31108e..d3d989f3 100644 --- a/src/win/native/InputMethod.cpp +++ b/src/win/native/InputMethod.cpp @@ -1,11 +1,11 @@ #include "cru/win/native/InputMethod.hpp" +#include "DpiUtil.hpp" #include "cru/common/Logger.hpp" #include "cru/platform/Check.hpp" #include "cru/win/Exception.hpp" -#include "cru/win/native/Window.hpp" #include "cru/win/String.hpp" -#include "DpiUtil.hpp" +#include "cru/win/native/Window.hpp" #include <vector> @@ -35,7 +35,7 @@ AutoHIMC& AutoHIMC::operator=(AutoHIMC&& other) { AutoHIMC::~AutoHIMC() { if (handle_) { if (!::ImmReleaseContext(hwnd_, handle_)) - log::Warn("AutoHIMC: Failed to release HIMC."); + log::TagWarn(log_tag, "Failed to release HIMC."); } } @@ -169,7 +169,7 @@ void WinInputMethodContext::EnableIME() { const auto hwnd = native_window->GetWindowHandle(); if (::ImmAssociateContextEx(hwnd, nullptr, IACE_DEFAULT) == FALSE) { - log::Warn("WinInputMethodContext: Failed to enable ime."); + log::TagWarn(log_tag, "Failed to enable ime."); } } @@ -181,13 +181,11 @@ void WinInputMethodContext::DisableIME() { AutoHIMC himc{hwnd}; if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) { - log::Warn( - "WinInputMethodContext: Failed to complete composition before disable " - "ime."); + log::TagWarn(log_tag, "Failed to complete composition before disable ime."); } if (::ImmAssociateContextEx(hwnd, nullptr, 0) == FALSE) { - log::Warn("WinInputMethodContext: Failed to disable ime."); + log::TagWarn(log_tag, "Failed to disable ime."); } } @@ -197,7 +195,7 @@ void WinInputMethodContext::CompleteComposition() { auto himc = *std::move(optional_himc); if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) { - log::Warn("WinInputMethodContext: Failed to complete composition."); + log::TagWarn(log_tag, "Failed to complete composition."); } } @@ -207,7 +205,7 @@ void WinInputMethodContext::CancelComposition() { auto himc = *std::move(optional_himc); if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0)) { - log::Warn("WinInputMethodContext: Failed to complete composition."); + log::TagWarn(log_tag, "Failed to complete composition."); } } @@ -230,9 +228,8 @@ void WinInputMethodContext::SetCandidateWindowPosition(const Point& point) { form.ptCurrentPos = DipToPi(point); if (!::ImmSetCandidateWindow(himc.Get(), &form)) - log::Debug( - "WinInputMethodContext: Failed to set input method candidate window " - "position."); + log::TagDebug(log_tag, + "Failed to set input method candidate window position."); } IEvent<std::nullptr_t>* WinInputMethodContext::CompositionStartEvent() { @@ -261,9 +258,9 @@ void WinInputMethodContext::OnWindowNativeMessage( // I don't think this will happen because normal key strike without ime // should only trigger ascci character. If it is a charater from // supplementary planes, it should be handled with ime messages. - log::Warn( - "WinInputMethodContext: A WM_CHAR message for character from " - "supplementary planes is ignored."); + log::TagWarn(log_tag, + "A WM_CHAR message for character from supplementary " + "planes is ignored."); } else { wchar_t s[1] = {c}; auto str = platform::win::ToUtf8String({s, 1}); @@ -275,9 +272,8 @@ void WinInputMethodContext::OnWindowNativeMessage( case WM_IME_COMPOSITION: { composition_event_.Raise(nullptr); auto composition_text = GetCompositionText(); - log::Debug( - "WinInputMethodContext: WM_IME_COMPOSITION composition text:\n{}", - composition_text); + log::TagDebug(log_tag, "WM_IME_COMPOSITION composition text:\n{}", + composition_text); if (message.l_param & GCS_RESULTSTR) { auto result_string = GetResultString(); text_event_.Raise(result_string); diff --git a/src/win/native/Window.cpp b/src/win/native/Window.cpp index 9dde1af3..22505bd6 100644 --- a/src/win/native/Window.cpp +++ b/src/win/native/Window.cpp @@ -1,17 +1,17 @@ #include "cru/win/native/Window.hpp" +#include "DpiUtil.hpp" +#include "WindowD2DPainter.hpp" +#include "WindowManager.hpp" #include "cru/common/Logger.hpp" #include "cru/platform/Check.hpp" +#include "cru/win/String.hpp" #include "cru/win/native/Cursor.hpp" #include "cru/win/native/Exception.hpp" #include "cru/win/native/Keyboard.hpp" #include "cru/win/native/UiApplication.hpp" #include "cru/win/native/WindowClass.hpp" #include "cru/win/native/WindowRenderTarget.hpp" -#include "cru/win/String.hpp" -#include "DpiUtil.hpp" -#include "WindowD2DPainter.hpp" -#include "WindowManager.hpp" #include <imm.h> #include <windowsx.h> @@ -124,7 +124,7 @@ bool WinNativeWindow::ReleaseMouse() { } void WinNativeWindow::RequestRepaint() { - log::Debug("A repaint is requested."); + log::TagDebug(log_tag, "A repaint is requested."); if (!::InvalidateRect(hwnd_, nullptr, FALSE)) throw Win32Error(::GetLastError(), "Failed to invalidate window."); if (!::UpdateWindow(hwnd_)) @@ -144,19 +144,20 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) { if (!::SetClassLongPtrW(hwnd_, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor_->GetHandle()))) { - log::Warn( - "Failed to set cursor because failed to set class long. Last error " - "code: {}.", - ::GetLastError()); + log::TagWarn(log_tag, + "Failed to set cursor because failed to set class long. Last " + "error code: {}.", + ::GetLastError()); return; } if (!IsVisible()) return; auto lg = [](const std::string_view& reason) { - log::Warn( - "Failed to set cursor because {} when window is visible. (We need " - "to update cursor if it is inside the window.) Last error code: {}.", + log::TagWarn( + log_tag, + "Failed to set cursor because {} when window is visible. (We need to " + "update cursor if it is inside the window.) Last error code: {}.", reason, ::GetLastError()); }; @@ -353,6 +354,7 @@ void WinNativeWindow::OnDestroyInternal() { void WinNativeWindow::OnPaintInternal() { paint_event_.Raise(nullptr); ValidateRect(hwnd_, nullptr); + log::TagDebug(log_tag, "A repaint is finished."); } void WinNativeWindow::OnResizeInternal(const int new_width, |