aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-21 18:44:40 +0800
committercrupest <crupest@outlook.com>2022-02-21 18:44:40 +0800
commitced1a63686e6c64cb574d74a34d1bbd07d0a668e (patch)
tree4082e4689e5e7cede8d59a0538d0f1ae37064acb /src/ui
parent6b00fca7c662301bf657a99cb1e89f21541a46bc (diff)
downloadcru-ced1a63686e6c64cb574d74a34d1bbd07d0a668e.tar.gz
cru-ced1a63686e6c64cb574d74a34d1bbd07d0a668e.tar.bz2
cru-ced1a63686e6c64cb574d74a34d1bbd07d0a668e.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/controls/TextHostControlService.cpp14
-rw-r--r--src/ui/helper/ClickDetector.cpp6
-rw-r--r--src/ui/helper/ShortcutHub.cpp25
-rw-r--r--src/ui/host/RoutedEventDispatch.h21
-rw-r--r--src/ui/host/WindowHost.cpp4
-rw-r--r--src/ui/mapper/BorderStyleMapper.cpp4
-rw-r--r--src/ui/render/BorderRenderObject.cpp8
-rw-r--r--src/ui/render/FlexLayoutRenderObject.cpp11
-rw-r--r--src/ui/render/LayoutHelper.cpp2
-rw-r--r--src/ui/render/RenderObject.cpp16
-rw-r--r--src/ui/render/StackLayoutRenderObject.cpp2
-rw-r--r--src/ui/render/TextRenderObject.cpp13
12 files changed, 62 insertions, 64 deletions
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index 81365a8b..15d9102c 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -2,7 +2,7 @@
#include "../Helper.h"
#include "cru/common/Base.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/common/String.h"
#include "cru/common/StringUtil.h"
#include "cru/platform/graphics/Font.h"
@@ -226,7 +226,7 @@ void TextHostControlService::SetText(String text, bool stop_composition) {
void TextHostControlService::InsertText(gsl::index position, StringView text,
bool stop_composition) {
if (!Utf16IsValidInsertPosition(this->text_, position)) {
- log::TagError(log_tag, u"Invalid text insert position.");
+ CRU_LOG_ERROR(u"Invalid text insert position.");
return;
}
this->text_.insert(this->text_.cbegin() + position, text);
@@ -240,7 +240,7 @@ void TextHostControlService::InsertText(gsl::index position, StringView text,
void TextHostControlService::DeleteChar(gsl::index position,
bool stop_composition) {
if (!Utf16IsValidInsertPosition(this->text_, position)) {
- log::TagError(log_tag, u"Invalid text delete position.");
+ CRU_LOG_ERROR(u"Invalid text delete position.");
return;
}
if (position == static_cast<gsl::index>(this->text_.size())) return;
@@ -253,7 +253,7 @@ void TextHostControlService::DeleteChar(gsl::index position,
gsl::index TextHostControlService::DeleteCharPrevious(gsl::index position,
bool stop_composition) {
if (!Utf16IsValidInsertPosition(this->text_, position)) {
- log::TagError(log_tag, u"Invalid text delete position.");
+ CRU_LOG_ERROR(u"Invalid text delete position.");
return 0;
}
if (position == 0) return 0;
@@ -269,11 +269,11 @@ void TextHostControlService::DeleteText(TextRange range,
if (range.count == 0) return;
range = range.Normalize();
if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) {
- log::TagError(log_tag, u"Invalid text delete start position.");
+ CRU_LOG_ERROR(u"Invalid text delete start position.");
return;
}
if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) {
- log::TagError(log_tag, u"Invalid text delete end position.");
+ CRU_LOG_ERROR(u"Invalid text delete end position.");
return;
}
this->text_.erase(this->text_.cbegin() + range.GetStart(),
@@ -465,7 +465,7 @@ void TextHostControlService::UpdateInputMethodPosition() {
right_bottom.y += 5;
if constexpr (debug_flags::text_service) {
- log::TagDebug(log_tag,
+ CRU_LOG_DEBUG(
u"Calculate input method candidate window position: {}.",
right_bottom);
}
diff --git a/src/ui/helper/ClickDetector.cpp b/src/ui/helper/ClickDetector.cpp
index a10133e9..8ebdfabc 100644
--- a/src/ui/helper/ClickDetector.cpp
+++ b/src/ui/helper/ClickDetector.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/helper/ClickDetector.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/ui/DebugFlags.h"
#include "cru/ui/controls/Control.h"
#include "cru/ui/host/WindowHost.h"
@@ -58,7 +58,7 @@ ClickDetector::ClickDetector(controls::Control* control) {
this->state_ == ClickState::Hover) {
if (!this->control_->CaptureMouse()) {
if constexpr (debug_flags::click_detector) {
- log::TagDebug(log_tag,
+ CRU_LOG_DEBUG(
u"Failed to capture mouse when begin click.");
}
return;
@@ -136,7 +136,7 @@ void ClickDetector::SetState(ClickState state) {
UnreachableCode();
}
};
- log::TagDebug(log_tag, u"Click state changed, new state: {}.",
+ CRU_LOG_DEBUG(u"Click state changed, new state: {}.",
to_string(state));
}
diff --git a/src/ui/helper/ShortcutHub.cpp b/src/ui/helper/ShortcutHub.cpp
index 3df07409..8fbf0b8d 100644
--- a/src/ui/helper/ShortcutHub.cpp
+++ b/src/ui/helper/ShortcutHub.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/helper/ShortcutHub.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/ui/DebugFlags.h"
#include "cru/ui/controls/Control.h"
@@ -64,7 +64,7 @@ const std::vector<ShortcutInfo>& ShortcutHub::GetShortcutByKeyBind(
void ShortcutHub::Install(controls::Control* control) {
if (!event_guard_.IsEmpty()) {
- log::Error(u"Shortcut hub is already installed. Failed to install.");
+ CRU_LOG_ERROR(u"Shortcut hub is already installed. Failed to install.");
return;
}
@@ -74,7 +74,7 @@ void ShortcutHub::Install(controls::Control* control) {
void ShortcutHub::Uninstall() {
if (event_guard_.IsEmpty()) {
- log::Warn(u"Shortcut hub is not installed. Failed to uninstall.");
+ CRU_LOG_WARN(u"Shortcut hub is not installed. Failed to uninstall.");
return;
}
@@ -89,17 +89,17 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
if constexpr (debug_flags::shortcut) {
if (shortcut_list.empty()) {
- log::Debug(u"No shortcut for key bind {}.", key_bind.ToString());
+ CRU_LOG_DEBUG(u"No shortcut for key bind {}.", key_bind.ToString());
}
- log::Debug(u"Begin to handle shortcut for key bind {}.",
- key_bind.ToString());
+ CRU_LOG_DEBUG(u"Begin to handle shortcut for key bind {}.",
+ key_bind.ToString());
}
for (const auto& shortcut : shortcut_list) {
auto is_handled = shortcut.handler();
if (is_handled) {
if constexpr (debug_flags::shortcut) {
- log::Debug(u"Handle {} handled it.", shortcut.name);
+ CRU_LOG_DEBUG(u"Handle {} handled it.", shortcut.name);
}
handled = true;
@@ -108,22 +108,23 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
break;
} else {
if constexpr (debug_flags::shortcut) {
- log::Debug(u"Handle {} didn't handle it.", shortcut.name);
+ CRU_LOG_DEBUG(u"Handle {} didn't handle it.", shortcut.name);
}
}
}
if constexpr (debug_flags::shortcut) {
if (!shortcut_list.empty()) {
- log::Debug(u"End handling shortcut for key bind {}.",
- key_bind.ToString());
+ CRU_LOG_DEBUG(u"End handling shortcut for key bind {}.",
+ key_bind.ToString());
}
}
if (!handled) {
if constexpr (debug_flags::shortcut) {
- log::Debug(u"Raise fallback event for unhandled shortcut of key bind {}.",
- key_bind.ToString());
+ CRU_LOG_DEBUG(
+ u"Raise fallback event for unhandled shortcut of key bind {}.",
+ key_bind.ToString());
}
fallback_event_.Raise(event);
}
diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h
index 2ab51645..3c2a98d8 100644
--- a/src/ui/host/RoutedEventDispatch.h
+++ b/src/ui/host/RoutedEventDispatch.h
@@ -1,5 +1,5 @@
#pragma once
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/ui/DebugFlags.h"
#include "cru/ui/controls/Control.h"
@@ -21,18 +21,19 @@ namespace cru::ui {
// as the rest arguments.
template <typename EventArgs, typename... Args>
void DispatchEvent(
- const std::u16string_view& event_name,
- controls::Control* const original_sender,
+ const String& event_name, controls::Control* const original_sender,
events::RoutedEvent<EventArgs>* (controls::Control::*event_ptr)(),
controls::Control* const last_receiver, Args&&... args) {
+ constexpr auto kLogTag = u"DispatchEvent";
+
if (original_sender == nullptr) return;
CRU_UNUSED(event_name)
if (original_sender == last_receiver) {
if constexpr (debug_flags::routed_event)
- log::Debug(
- "Routed event {} no need to dispatch (original_sender == "
+ CRU_LOG_DEBUG(
+ u"Routed event {} no need to dispatch (original_sender == "
"last_receiver). Original sender is {}.",
event_name, original_sender->GetControlType());
return;
@@ -49,7 +50,7 @@ void DispatchEvent(
}
if constexpr (debug_flags::routed_event) {
- std::u16string log = u"Dispatch routed event ";
+ String log = u"Dispatch routed event ";
log += event_name;
log += u". Path (parent first): ";
auto i = receive_list.crbegin();
@@ -59,7 +60,7 @@ void DispatchEvent(
log += u" -> ";
}
log += (*i)->GetControlType();
- log::Debug(log);
+ CRU_LOG_DEBUG(log);
}
auto handled = false;
@@ -75,7 +76,7 @@ void DispatchEvent(
if (event_args.IsHandled()) {
handled = true;
if constexpr (debug_flags::routed_event)
- log::Debug(
+ CRU_LOG_DEBUG(
u"Routed event is short-circuit in TUNNEL at {}-st control (count "
u"from parent).",
count);
@@ -92,7 +93,7 @@ void DispatchEvent(
->Raise(event_args);
if (event_args.IsHandled()) {
if constexpr (debug_flags::routed_event)
- log::Debug(
+ CRU_LOG_DEBUG(
u"Routed event is short-circuit in BUBBLE at {}-st control "
u"(count from parent).",
count);
@@ -109,6 +110,6 @@ void DispatchEvent(
}
if constexpr (debug_flags::routed_event)
- log::Debug(u"Routed event dispatch finished.");
+ CRU_LOG_DEBUG(u"Routed event dispatch finished.");
}
} // namespace cru::ui
diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp
index 91b5f438..42d0945f 100644
--- a/src/ui/host/WindowHost.cpp
+++ b/src/ui/host/WindowHost.cpp
@@ -2,7 +2,7 @@
#include "RoutedEventDispatch.h"
#include "cru/common/Base.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/platform/graphics/Painter.h"
#include "cru/platform/gui/InputMethod.h"
#include "cru/platform/gui/UiApplication.h"
@@ -191,7 +191,7 @@ void WindowHost::RelayoutWithSize(const Size& available_size,
after_layout_event_.Raise(AfterLayoutEventArgs{});
after_layout_stable_action_.clear();
if constexpr (debug_flags::layout)
- log::TagDebug(log_tag, u"A relayout is finished.");
+ CRU_LOG_DEBUG(u"A relayout is finished.");
}
void WindowHost::Repaint() {
diff --git a/src/ui/mapper/BorderStyleMapper.cpp b/src/ui/mapper/BorderStyleMapper.cpp
index 8daa9d1b..3dea0776 100644
--- a/src/ui/mapper/BorderStyleMapper.cpp
+++ b/src/ui/mapper/BorderStyleMapper.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/mapper/BorderStyleMapper.h"
#include "../Helper.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/ui/mapper/MapperRegistry.h"
@@ -21,7 +21,6 @@ ApplyBorderStyleInfo BorderStyleMapper::DoMapFromXml(
for (auto child : node->GetChildren()) {
if (child->GetType() == XmlNode::Type::Text) {
- log::Debug(u"Ignore text node.");
} else {
auto c = child->AsElement();
auto thickness_mapper =
@@ -43,7 +42,6 @@ ApplyBorderStyleInfo BorderStyleMapper::DoMapFromXml(
} else if (name->CaseInsensitiveCompare(u"background") == 0) {
result.background_brush = std::move(brush);
} else {
- log::Debug(u"Unknown brush name: {}", *name);
}
} else {
result.border_brush = std::move(brush);
diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp
index 30493a49..cbea4b81 100644
--- a/src/ui/render/BorderRenderObject.cpp
+++ b/src/ui/render/BorderRenderObject.cpp
@@ -1,7 +1,7 @@
#include "cru/ui/render/BorderRenderObject.h"
#include "../Helper.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/graphics/Geometry.h"
#include "cru/platform/graphics/Painter.h"
@@ -80,8 +80,8 @@ RenderObject* BorderRenderObject::HitTest(const Point& point) {
void BorderRenderObject::Draw(platform::graphics::IPainter* painter) {
if constexpr (debug_flags::draw) {
- log::TagDebug(
- log_tag, u"BorderRenderObject draw, background: {}, foreground: {}.",
+ CRU_LOG_DEBUG(
+ u"BorderRenderObject draw, background: {}, foreground: {}.",
background_brush_ == nullptr ? u"NONE"
: background_brush_->GetDebugString(),
foreground_brush_ == nullptr ? u"NONE"
@@ -94,7 +94,7 @@ void BorderRenderObject::Draw(platform::graphics::IPainter* painter) {
if (is_border_enabled_) {
if (border_brush_ == nullptr) {
- log::TagWarn(log_tag, u"Border is enabled but border brush is null.");
+ CRU_LOG_WARN(u"Border is enabled but border brush is null.");
} else {
painter->FillGeometry(geometry_.get(), border_brush_.get());
}
diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp
index 0699768a..988e7590 100644
--- a/src/ui/render/FlexLayoutRenderObject.cpp
+++ b/src/ui/render/FlexLayoutRenderObject.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/render/FlexLayoutRenderObject.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/ui/render/LayoutHelper.h"
#include <algorithm>
@@ -90,7 +90,7 @@ Size FlexLayoutMeasureContentImpl(
const MeasureRequirement& requirement, const MeasureSize& preferred_size,
const std::vector<RenderObject*>& children,
const std::vector<FlexChildLayoutData>& layout_data,
- Alignment item_cross_align, StringView log_tag) {
+ Alignment item_cross_align, String kLogTag) {
Expects(children.size() == layout_data.size());
direction_tag_t direction_tag;
@@ -300,8 +300,7 @@ Size FlexLayoutMeasureContentImpl(
if (max_main_length.IsSpecified() &&
total_length > max_main_length.GetLengthOrUndefined()) {
- log::TagWarn(
- log_tag,
+ CRU_LOG_WARN(
u"(Measure) Children's main axis length exceeds required max length.");
total_length = max_main_length.GetLengthOrUndefined();
} else if (min_main_length.IsSpecified() &&
@@ -345,11 +344,11 @@ Size FlexLayoutRenderObject::OnMeasureContent(
if (horizontal) {
return FlexLayoutMeasureContentImpl<tag_horizontal_t>(
requirement, preferred_size, children, layout_data_list,
- item_cross_align_, log_tag);
+ item_cross_align_, kLogTag);
} else {
return FlexLayoutMeasureContentImpl<tag_vertical_t>(
requirement, preferred_size, children, layout_data_list,
- item_cross_align_, log_tag);
+ item_cross_align_, kLogTag);
}
}
diff --git a/src/ui/render/LayoutHelper.cpp b/src/ui/render/LayoutHelper.cpp
index 7a82bb2d..a9121321 100644
--- a/src/ui/render/LayoutHelper.cpp
+++ b/src/ui/render/LayoutHelper.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/render/LayoutHelper.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
namespace cru::ui::render {
float CalculateAnchorByAlignment(Alignment alignment, float start_point,
diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp
index 6c09ce99..b6de5782 100644
--- a/src/ui/render/RenderObject.cpp
+++ b/src/ui/render/RenderObject.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/render/RenderObject.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/ui/DebugFlags.h"
#include "cru/ui/controls/Control.h"
#include "cru/ui/host/WindowHost.h"
@@ -80,16 +80,16 @@ void RenderObject::Measure(const MeasureRequirement& requirement,
preferred_size.OverrideBy(preferred_size_);
if constexpr (cru::ui::debug_flags::layout) {
- log::Debug(u"{} Measure begins :\nrequirement: {}\npreferred size: {}",
- this->GetDebugPathInTree(), requirement.ToDebugString(),
- preferred_size.ToDebugString());
+ CRU_LOG_DEBUG(u"{} Measure begins :\nrequirement: {}\npreferred size: {}",
+ this->GetDebugPathInTree(), requirement.ToDebugString(),
+ preferred_size.ToDebugString());
}
desired_size_ = OnMeasureCore(merged_requirement, merged_preferred_size);
if constexpr (cru::ui::debug_flags::layout) {
- log::Debug(u"{} Measure ends :\nresult size: {}",
- this->GetDebugPathInTree(), desired_size_);
+ CRU_LOG_DEBUG(u"{} Measure ends :\nresult size: {}",
+ this->GetDebugPathInTree(), desired_size_);
}
Ensures(desired_size_.width >= 0);
@@ -98,8 +98,8 @@ void RenderObject::Measure(const MeasureRequirement& requirement,
void RenderObject::Layout(const Point& offset) {
if constexpr (cru::ui::debug_flags::layout) {
- log::Debug(u"{} Layout :\noffset: {} size: {}", this->GetDebugPathInTree(),
- offset, desired_size_);
+ CRU_LOG_DEBUG(u"{} Layout :\noffset: {} size: {}",
+ this->GetDebugPathInTree(), offset, desired_size_);
}
offset_ = offset;
size_ = desired_size_;
diff --git a/src/ui/render/StackLayoutRenderObject.cpp b/src/ui/render/StackLayoutRenderObject.cpp
index fda9a420..9ca9bf02 100644
--- a/src/ui/render/StackLayoutRenderObject.cpp
+++ b/src/ui/render/StackLayoutRenderObject.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/render/StackLayoutRenderObject.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/ui/render/LayoutHelper.h"
#include "cru/ui/render/MeasureRequirement.h"
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index 82f314bd..0b9009c5 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -1,7 +1,7 @@
#include "cru/ui/render/TextRenderObject.h"
#include "../Helper.h"
-#include "cru/common/Logger.h"
+#include "cru/common/log/Logger.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/graphics/Painter.h"
#include "cru/platform/graphics/TextLayout.h"
@@ -176,12 +176,11 @@ RenderObject* TextRenderObject::HitTest(const Point& point) {
void TextRenderObject::Draw(platform::graphics::IPainter* painter) {
if constexpr (debug_flags::draw) {
- log::TagDebug(log_tag,
- u"Begin to paint, total_offset: {}, size: {}, text_layout: "
- u"{}, brush: {}.",
- this->GetTotalOffset(), this->GetDesiredSize(),
- this->text_layout_->GetDebugString(),
- this->brush_->GetDebugString());
+ CRU_LOG_DEBUG(
+ u"Begin to paint, total_offset: {}, size: {}, text_layout: "
+ u"{}, brush: {}.",
+ this->GetTotalOffset(), this->GetDesiredSize(),
+ this->text_layout_->GetDebugString(), this->brush_->GetDebugString());
}
if (this->selection_range_.has_value()) {