diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/ClickDetector.cpp | 14 | ||||
-rw-r--r-- | src/ui/RoutedEventDispatch.hpp | 21 | ||||
-rw-r--r-- | src/ui/UiHost.cpp | 17 | ||||
-rw-r--r-- | src/ui/UiManager.cpp | 2 | ||||
-rw-r--r-- | src/ui/Window.cpp | 2 | ||||
-rw-r--r-- | src/ui/controls/TextBlock.cpp | 4 | ||||
-rw-r--r-- | src/ui/controls/TextControlService.hpp | 15 | ||||
-rw-r--r-- | src/ui/render/BorderRenderObject.cpp | 10 | ||||
-rw-r--r-- | src/ui/render/FlexLayoutRenderObject.cpp | 8 | ||||
-rw-r--r-- | src/ui/render/LayoutHelper.cpp | 4 | ||||
-rw-r--r-- | src/ui/render/RenderObject.cpp | 8 | ||||
-rw-r--r-- | src/ui/render/ScrollRenderObject.cpp | 1 | ||||
-rw-r--r-- | src/ui/render/StackLayoutRenderObject.cpp | 8 | ||||
-rw-r--r-- | src/ui/render/TextRenderObject.cpp | 10 |
14 files changed, 65 insertions, 59 deletions
diff --git a/src/ui/ClickDetector.cpp b/src/ui/ClickDetector.cpp index 93e6f303..09f208cd 100644 --- a/src/ui/ClickDetector.cpp +++ b/src/ui/ClickDetector.cpp @@ -45,7 +45,7 @@ ClickDetector::ClickDetector(Control* control) { this->state_ == ClickState::Hover) { if (!this->control_->CaptureMouse()) { log::TagDebug(log_tag, - "Failed to capture mouse when begin click."); + u"Failed to capture mouse when begin click."); return; } this->down_point_ = args.GetPoint(); @@ -107,21 +107,21 @@ void ClickDetector::SetTriggerButton(MouseButton trigger_button) { void ClickDetector::SetState(ClickState state) { #ifdef CRU_DEBUG - auto to_string = [](ClickState state) -> std::string_view { + auto to_string = [](ClickState state) -> std::u16string_view { switch (state) { case ClickState::None: - return "None"; + return u"None"; case ClickState::Hover: - return "Hover"; + return u"Hover"; case ClickState::Press: - return "Press"; + return u"Press"; case ClickState::PressInactive: - return "PressInvactive"; + return u"PressInvactive"; default: UnreachableCode(); } }; - log::TagDebug(log_tag, "Click state changed, new state: {}.", + log::TagDebug(log_tag, u"Click state changed, new state: {}.", to_string(state)); #endif diff --git a/src/ui/RoutedEventDispatch.hpp b/src/ui/RoutedEventDispatch.hpp index 5ff21a74..9337e9ec 100644 --- a/src/ui/RoutedEventDispatch.hpp +++ b/src/ui/RoutedEventDispatch.hpp @@ -20,7 +20,7 @@ namespace cru::ui { // "original_sender", which is unchanged. And "args" will be perfectly forwarded // as the rest arguments. template <typename EventArgs, typename... Args> -void DispatchEvent(const std::string_view& event_name, +void DispatchEvent(const std::u16string_view& event_name, Control* const original_sender, event::RoutedEvent<EventArgs>* (Control::*event_ptr)(), Control* const last_receiver, Args&&... args) { @@ -30,7 +30,7 @@ void DispatchEvent(const std::string_view& event_name, #ifdef CRU_DEBUG bool do_log = true; - if (event_name == "MouseMove") do_log = false; + if (event_name == u"MouseMove") do_log = false; #endif if (original_sender == last_receiver) { @@ -56,14 +56,14 @@ void DispatchEvent(const std::string_view& event_name, #ifdef CRU_DEBUG if (do_log) { - std::string log = "Dispatch routed event "; + std::u16string log = u"Dispatch routed event "; log += event_name; - log += ". Path (parent first): "; + log += u". Path (parent first): "; auto i = receive_list.crbegin(); const auto end = --receive_list.crend(); for (; i != end; ++i) { log += (*i)->GetControlType(); - log += " -> "; + log += u" -> "; } log += (*i)->GetControlType(); log::Debug(log); @@ -89,8 +89,8 @@ void DispatchEvent(const std::string_view& event_name, #ifdef CRU_DEBUG if (do_log) log::Debug( - "Routed event is short-circuit in TUNNEL at {}-st control (count " - "from parent).", + u"Routed event is short-circuit in TUNNEL at {}-st control (count " + u"from parent).", count); #endif break; @@ -110,9 +110,8 @@ void DispatchEvent(const std::string_view& event_name, #ifdef CRU_DEBUG if (do_log) log::Debug( - "Routed event is short-circuit in BUBBLE at {}-st control " - "(count " - "from parent).", + u"Routed event is short-circuit in BUBBLE at {}-st control " + u"(count from parent).", count); #endif break; @@ -128,7 +127,7 @@ void DispatchEvent(const std::string_view& event_name, } #ifdef CRU_DEBUG - if (do_log) log::Debug("Routed event dispatch finished."); + if (do_log) log::Debug(u"Routed event dispatch finished."); #endif } } // namespace cru::ui diff --git a/src/ui/UiHost.cpp b/src/ui/UiHost.cpp index 975d0ffe..5eee3925 100644 --- a/src/ui/UiHost.cpp +++ b/src/ui/UiHost.cpp @@ -14,9 +14,11 @@ using platform::native::IUiApplication; namespace event_names { #ifdef CRU_DEBUG -#define CRU_DEFINE_EVENT_NAME(name) constexpr const char* name = #name; +// clang-format off +#define CRU_DEFINE_EVENT_NAME(name) constexpr const char16_t* name = u#name; +// clang-format on #else -#define CRU_DEFINE_EVENT_NAME(name) constexpr const char* name = ""; +#define CRU_DEFINE_EVENT_NAME(name) constexpr const char16_t* name = u""; #endif CRU_DEFINE_EVENT_NAME(LoseFocus) @@ -146,7 +148,7 @@ void UiHost::InvalidatePaint() { } void UiHost::InvalidateLayout() { - log::TagDebug(log_tag, "A relayout is requested."); + log::TagDebug(log_tag, u"A relayout is requested."); if (!need_layout_) { platform::native::IUiApplication::GetInstance()->InvokeLater( [resolver = this->CreateResolver()] { @@ -171,7 +173,7 @@ void UiHost::Relayout() { render::MeasureSize::NotSpecified()); root_render_object_->Layout(Point{}); after_layout_event_.Raise(AfterLayoutEventArgs{}); - log::TagDebug(log_tag, "A relayout is finished."); + log::TagDebug(log_tag, u"A relayout is finished."); } bool UiHost::RequestFocusFor(Control* control) { @@ -368,6 +370,11 @@ void UiHost::UpdateCursor() { Control* UiHost::HitTest(const Point& point) { const auto render_object = root_render_object_->HitTest(point); - return render_object ? render_object->GetAttachedControl() : nullptr; + if (render_object) { + const auto control = render_object->GetAttachedControl(); + Ensures(control); + return control; + } + return window_control_; } } // namespace cru::ui diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp index b8effdfd..b50a9775 100644 --- a/src/ui/UiManager.cpp +++ b/src/ui/UiManager.cpp @@ -30,7 +30,7 @@ UiManager* UiManager::GetInstance() { UiManager::UiManager() { const auto factory = GetGraphFactory(); - theme_resource_.default_font = factory->CreateFont("等线", 24.0f); + theme_resource_.default_font = factory->CreateFont(u"等线", 24.0f); const auto black_brush = std::shared_ptr<platform::graph::ISolidColorBrush>( CreateSolidColorBrush(factory, colors::black)); diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp index de7044dd..dca95ebb 100644 --- a/src/ui/Window.cpp +++ b/src/ui/Window.cpp @@ -17,7 +17,7 @@ Window::~Window() { managed_ui_host_.reset(); } -std::string_view Window::GetControlType() const { return control_type; } +std::u16string_view Window::GetControlType() const { return control_type; } render::RenderObject* Window::GetRenderObject() const { return render_object_; } diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp index 5ec15796..7f7ee38b 100644 --- a/src/ui/controls/TextBlock.cpp +++ b/src/ui/controls/TextBlock.cpp @@ -30,11 +30,11 @@ render::RenderObject* TextBlock::GetRenderObject() const { return text_render_object_.get(); } -std::string TextBlock::GetText() const { +std::u16string TextBlock::GetText() const { return text_render_object_->GetText(); } -void TextBlock::SetText(std::string text) { +void TextBlock::SetText(std::u16string text) { text_render_object_->SetText(std::move(text)); } diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp index 94d9ebf8..93a48c44 100644 --- a/src/ui/controls/TextControlService.hpp +++ b/src/ui/controls/TextControlService.hpp @@ -19,7 +19,7 @@ constexpr int k_default_caret_blink_duration = 500; // ``` template <typename TControl> class TextControlService : public Object { - CRU_DEFINE_CLASS_LOG_TAG("cru::ui::controls::TextControlService") + CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::controls::TextControlService") public: TextControlService(gsl::not_null<TControl*> control) : control_(control) {} @@ -126,22 +126,21 @@ class TextControlService : public Object { const auto text_render_object = this->GetTextRenderObject(); text_render_object->SetSelectionRange(TextRange{start, 0}); text_render_object->SetCaretPosition(start); - log::TagDebug(log_tag, "Text selection started, position: {}.", position); + log::TagDebug(log_tag, u"Text selection started, position: {}.", start); } void UpdateSelection(Index new_end) { - if (!old_selection.has_value()) return; - const auto text_render_object = this->GetTextRenderObject(); const auto old_selection = text_render_object->GetSelectionRange(); + if (!old_selection.has_value()) return; const auto old_start = old_selection->GetStart(); this->GetTextRenderObject()->SetSelectionRange( TextRange::FromTwoSides(old_start, new_end)); text_render_object->SetCaretPosition(new_end); - log::TagDebug(log_tag, "Text selection updated, range: {}, {}.", old_start, + log::TagDebug(log_tag, u"Text selection updated, range: {}, {}.", old_start, new_end); if (const auto scroll_render_object = this->GetScrollRenderObject()) { - //TODO: Implement this. + // TODO: Implement this. } } @@ -194,9 +193,9 @@ class TextControlService : public Object { } } - void KeyDownHandler(event::KeyEventArgs& args) {} + void KeyDownHandler(event::KeyEventArgs& args) { CRU_UNUSED(args); } - void KeyUpHandler(event::KeyEventArgs& args) {} + void KeyUpHandler(event::KeyEventArgs& args) { CRU_UNUSED(args); } void LoseFocusHandler(event::FocusChangeEventArgs& args) { if (!args.IsWindow()) this->AbortSelection(); diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index f2e3eb9b..b7e1e709 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::TagWarn(log_tag, "Border is enabled but border brush is null."); + log::TagWarn(log_tag, u"Border is enabled but border brush is null."); } else { painter->FillGeometry(geometry_.get(), border_brush_.get()); } @@ -94,8 +94,8 @@ Size BorderRenderObject::OnMeasureCore(const MeasureRequirement& requirement, const auto max_width = requirement.max.width.GetLengthOrMax(); if (coerced_space_size.width > max_width) { log::TagWarn(log_tag, - "(Measure) Horizontal length of padding, border and margin " - "is bigger than required max length."); + u"(Measure) Horizontal length of padding, border and margin " + u"is bigger than required max length."); coerced_space_size.width = max_width; } content_requirement.max.width = max_width - coerced_space_size.width; @@ -110,8 +110,8 @@ Size BorderRenderObject::OnMeasureCore(const MeasureRequirement& requirement, const auto max_height = requirement.max.height.GetLengthOrMax(); if (coerced_space_size.height > max_height) { log::TagWarn(log_tag, - "(Measure) Vertical length of padding, border and margin is " - "bigger than required max length."); + u"(Measure) Vertical length of padding, border and margin is " + u"bigger than required max length."); coerced_space_size.height = max_height; } content_requirement.max.height = max_height - coerced_space_size.height; diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 8e6b41fe..ade230b5 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -88,7 +88,7 @@ Size FlexLayoutMeasureContentImpl( const MeasureRequirement& requirement, const MeasureSize& preferred_size, const std::vector<RenderObject*>& children, const std::vector<FlexChildLayoutData>& layout_data, - std::string_view log_tag) { + std::u16string_view log_tag) { Expects(children.size() == layout_data.size()); direction_tag_t direction_tag; @@ -111,8 +111,8 @@ Size FlexLayoutMeasureContentImpl( StackLayoutCalculateChildMaxLength( preferred_cross_length, max_cross_length, GetCross(child->GetMinSize(), direction_tag), log_tag, - "(Measure) Child's min cross size is bigger than parent's max " - "cross size.")); + u"(Measure) Child's min cross size is bigger than parent's max " + u"cross size.")); } // step 1. @@ -315,7 +315,7 @@ Size FlexLayoutMeasureContentImpl( total_length > max_main_length.GetLengthOrUndefined()) { log::TagWarn( log_tag, - "(Measure) Children's main axis length exceeds required max length."); + u"(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()) { diff --git a/src/ui/render/LayoutHelper.cpp b/src/ui/render/LayoutHelper.cpp index 9f94b84d..9ad2d862 100644 --- a/src/ui/render/LayoutHelper.cpp +++ b/src/ui/render/LayoutHelper.cpp @@ -19,8 +19,8 @@ float CalculateAnchorByAlignment(Alignment alignment, float start_point, MeasureLength StackLayoutCalculateChildMaxLength( MeasureLength parent_preferred_size, MeasureLength parent_max_size, - MeasureLength child_min_size, std::string_view log_tag, - std::string_view exceeds_message) { + MeasureLength child_min_size, std::u16string_view log_tag, + std::u16string_view exceeds_message) { if (parent_max_size.GetLengthOrMax() < child_min_size.GetLengthOr0()) { 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 66b62e6e..30433868 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -152,8 +152,8 @@ Size RenderObject::OnMeasureCore(const MeasureRequirement& requirement, const auto max_width = requirement.max.width.GetLengthOrMax(); if (coerced_space_size.width > max_width) { log::TagWarn(log_tag, - "(Measure) Horizontal length of padding and margin is " - "bigger than required max length."); + u"(Measure) Horizontal length of padding and margin is " + u"bigger than required max length."); coerced_space_size.width = max_width; } content_requirement.max.width = max_width - coerced_space_size.width; @@ -168,8 +168,8 @@ Size RenderObject::OnMeasureCore(const MeasureRequirement& requirement, const auto max_height = requirement.max.height.GetLengthOrMax(); if (coerced_space_size.height > max_height) { log::TagWarn(log_tag, - "(Measure) Vertical length of padding and margin is bigger " - "than required max length."); + u"(Measure) Vertical length of padding and margin is bigger " + u"than required max length."); coerced_space_size.height = max_height; } content_requirement.max.height = max_height - coerced_space_size.height; diff --git a/src/ui/render/ScrollRenderObject.cpp b/src/ui/render/ScrollRenderObject.cpp index 77367970..d3996b98 100644 --- a/src/ui/render/ScrollRenderObject.cpp +++ b/src/ui/render/ScrollRenderObject.cpp @@ -69,6 +69,7 @@ void ScrollRenderObject::SetScrollOffset(const Point& offset) { void ScrollToContain(const Rect& rect) { // TODO: Implement this. + CRU_UNUSED(rect); throw std::runtime_error("Not implemented."); } diff --git a/src/ui/render/StackLayoutRenderObject.cpp b/src/ui/render/StackLayoutRenderObject.cpp index 168ff379..75ab0ee3 100644 --- a/src/ui/render/StackLayoutRenderObject.cpp +++ b/src/ui/render/StackLayoutRenderObject.cpp @@ -15,13 +15,13 @@ Size StackLayoutRenderObject::OnMeasureContent( MeasureSize{StackLayoutCalculateChildMaxLength( preferred_size.width, requirement.max.width, child->GetMinSize().width, log_tag, - "(Measure) Child's min width is bigger than " - "parent's max width."), + u"(Measure) Child's min width is bigger than " + u"parent's max width."), StackLayoutCalculateChildMaxLength( preferred_size.height, requirement.max.height, child->GetMinSize().height, log_tag, - "(Measure) Child's min height is bigger than " - "parent's max height.")}, + u"(Measure) Child's min height is bigger than " + u"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 87a3c352..8a4a4ba1 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -28,16 +28,16 @@ TextRenderObject::TextRenderObject( caret_brush.swap(caret_brush_); const auto graph_factory = GetGraphFactory(); - text_layout_ = graph_factory->CreateTextLayout(font_, ""); + text_layout_ = graph_factory->CreateTextLayout(font_, u""); } TextRenderObject::~TextRenderObject() = default; -std::string TextRenderObject::GetText() const { +std::u16string TextRenderObject::GetText() const { return text_layout_->GetText(); } -void TextRenderObject::SetText(std::string new_text) { +void TextRenderObject::SetText(std::u16string new_text) { text_layout_->SetText(std::move(new_text)); } @@ -171,7 +171,7 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, if (requirement.max.width.IsSpecified() && text_size.width > requirement.max.width.GetLengthOrUndefined()) { log::TagWarn(log_tag, - "(Measure) Text actual width exceeds the required max width."); + u"(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()); @@ -182,7 +182,7 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, text_size.height > requirement.max.height.GetLengthOrUndefined()) { log::TagWarn( log_tag, - "(Measure) Text actual height exceeds the required max height."); + u"(Measure) Text actual height exceeds the required max height."); result.height = requirement.max.height.GetLengthOrUndefined(); } else { result.height = |