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 /src/ui | |
parent | 6b5aff7b7e50fae15cb010b340099163725f664c (diff) | |
download | cru-5c3dae62b9218dbd2493ff6390db062013ca4bdc.tar.gz cru-5c3dae62b9218dbd2493ff6390db062013ca4bdc.tar.bz2 cru-5c3dae62b9218dbd2493ff6390db062013ca4bdc.zip |
...
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/ClickDetector.cpp | 6 | ||||
-rw-r--r-- | src/ui/UiHost.cpp | 5 | ||||
-rw-r--r-- | src/ui/controls/TextControlService.hpp | 17 | ||||
-rw-r--r-- | src/ui/render/BorderRenderObject.cpp | 20 | ||||
-rw-r--r-- | src/ui/render/FlexLayoutRenderObject.cpp | 21 | ||||
-rw-r--r-- | src/ui/render/LayoutHelper.cpp | 5 | ||||
-rw-r--r-- | src/ui/render/RenderObject.cpp | 18 | ||||
-rw-r--r-- | src/ui/render/StackLayoutRenderObject.cpp | 12 | ||||
-rw-r--r-- | src/ui/render/TextRenderObject.cpp | 10 |
9 files changed, 55 insertions, 59 deletions
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 = |