diff options
-rw-r--r-- | include/cru/ui/DebugFlags.hpp | 4 | ||||
-rw-r--r-- | src/ui/RoutedEventDispatch.hpp | 45 | ||||
-rw-r--r-- | src/ui/UiHost.cpp | 7 | ||||
-rw-r--r-- | src/ui/controls/TextControlService.hpp | 13 | ||||
-rw-r--r-- | src/ui/render/ScrollRenderObject.cpp | 1 |
5 files changed, 27 insertions, 43 deletions
diff --git a/include/cru/ui/DebugFlags.hpp b/include/cru/ui/DebugFlags.hpp index a0003e9d..fceef081 100644 --- a/include/cru/ui/DebugFlags.hpp +++ b/include/cru/ui/DebugFlags.hpp @@ -1,6 +1,8 @@ #pragma once namespace cru::ui::debug_flags { +constexpr bool routed_event = false; constexpr bool layout = false; -constexpr bool shortcut = true; +constexpr bool shortcut = false; +constexpr bool text_service = false; } // namespace cru::ui::debug_flags diff --git a/src/ui/RoutedEventDispatch.hpp b/src/ui/RoutedEventDispatch.hpp index 9337e9ec..b6e0999b 100644 --- a/src/ui/RoutedEventDispatch.hpp +++ b/src/ui/RoutedEventDispatch.hpp @@ -2,6 +2,7 @@ #include "cru/ui/Control.hpp" #include "cru/common/Logger.hpp" +#include "cru/ui/DebugFlags.hpp" #include <list> @@ -24,25 +25,14 @@ void DispatchEvent(const std::u16string_view& event_name, Control* const original_sender, event::RoutedEvent<EventArgs>* (Control::*event_ptr)(), Control* const last_receiver, Args&&... args) { -#ifndef CRU_DEBUG CRU_UNUSED(event_name) -#endif - -#ifdef CRU_DEBUG - bool do_log = true; - if (event_name == u"MouseMove") do_log = false; -#endif if (original_sender == last_receiver) { - /* - #ifdef CRU_DEBUG - if (do_log) - log::Debug( - "Routed event {} no need to dispatch (original_sender == " - "last_receiver). Original sender is {}.", - event_name, original_sender->GetControlType()); - #endif - */ + if constexpr (debug_flags::routed_event) + log::Debug( + "Routed event {} no need to dispatch (original_sender == " + "last_receiver). Original sender is {}.", + event_name, original_sender->GetControlType()); return; } @@ -54,8 +44,7 @@ void DispatchEvent(const std::u16string_view& event_name, parent = parent->GetParent(); } -#ifdef CRU_DEBUG - if (do_log) { + if constexpr (debug_flags::routed_event) { std::u16string log = u"Dispatch routed event "; log += event_name; log += u". Path (parent first): "; @@ -68,31 +57,24 @@ void DispatchEvent(const std::u16string_view& event_name, log += (*i)->GetControlType(); log::Debug(log); } -#endif auto handled = false; -#ifdef CRU_DEBUG int count = 0; -#endif // tunnel for (auto i = receive_list.crbegin(); i != receive_list.crend(); ++i) { -#ifdef CRU_DEBUG count++; -#endif EventArgs event_args(*i, original_sender, std::forward<Args>(args)...); static_cast<Event<EventArgs&>*>(((*i)->*event_ptr)()->Tunnel()) ->Raise(event_args); if (event_args.IsHandled()) { handled = true; -#ifdef CRU_DEBUG - if (do_log) + if constexpr (debug_flags::routed_event) log::Debug( u"Routed event is short-circuit in TUNNEL at {}-st control (count " u"from parent).", count); -#endif break; } } @@ -100,20 +82,16 @@ void DispatchEvent(const std::u16string_view& event_name, // bubble if (!handled) { for (auto i : receive_list) { -#ifdef CRU_DEBUG count--; -#endif EventArgs event_args(i, original_sender, std::forward<Args>(args)...); static_cast<Event<EventArgs&>*>((i->*event_ptr)()->Bubble()) ->Raise(event_args); if (event_args.IsHandled()) { -#ifdef CRU_DEBUG - if (do_log) + if constexpr (debug_flags::routed_event) log::Debug( u"Routed event is short-circuit in BUBBLE at {}-st control " u"(count from parent).", count); -#endif break; } } @@ -126,8 +104,7 @@ void DispatchEvent(const std::u16string_view& event_name, ->Raise(event_args); } -#ifdef CRU_DEBUG - if (do_log) log::Debug(u"Routed event dispatch finished."); -#endif + if constexpr (debug_flags::routed_event) + log::Debug(u"Routed event dispatch finished."); } } // namespace cru::ui diff --git a/src/ui/UiHost.cpp b/src/ui/UiHost.cpp index ccc5fea0..a881c16d 100644 --- a/src/ui/UiHost.cpp +++ b/src/ui/UiHost.cpp @@ -6,6 +6,7 @@ #include "cru/platform/native/InputMethod.hpp" #include "cru/platform/native/UiApplication.hpp" #include "cru/platform/native/Window.hpp" +#include "cru/ui/DebugFlags.hpp" #include "cru/ui/Window.hpp" #include "cru/ui/render/MeasureRequirement.hpp" #include "cru/ui/render/WindowRenderObject.hpp" @@ -156,7 +157,8 @@ void UiHost::InvalidatePaint() { } void UiHost::InvalidateLayout() { - log::TagDebug(log_tag, u"A relayout is requested."); + if constexpr (debug_flags::layout) + log::TagDebug(log_tag, u"A relayout is requested."); if (!need_layout_) { platform::native::IUiApplication::GetInstance()->SetImmediate( [resolver = this->CreateResolver()] { @@ -196,7 +198,8 @@ void UiHost::Relayout() { for (auto& action : after_layout_stable_action_) action(); after_layout_stable_action_.clear(); after_layout_event_.Raise(AfterLayoutEventArgs{}); - log::TagDebug(log_tag, u"A relayout is finished."); + if constexpr (debug_flags::layout) + log::TagDebug(log_tag, u"A relayout is finished."); } bool UiHost::RequestFocusFor(Control* control) { diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp index fe33f459..b4102a49 100644 --- a/src/ui/controls/TextControlService.hpp +++ b/src/ui/controls/TextControlService.hpp @@ -1,5 +1,4 @@ #pragma once -#include <string> #include "../Helper.hpp" #include "cru/common/Logger.hpp" #include "cru/common/StringUtil.hpp" @@ -10,13 +9,15 @@ #include "cru/platform/native/Window.hpp" #include "cru/ui/Base.hpp" #include "cru/ui/Control.hpp" +#include "cru/ui/DebugFlags.hpp" #include "cru/ui/ShortcutHub.hpp" #include "cru/ui/UiEvent.hpp" #include "cru/ui/UiHost.hpp" #include "cru/ui/render/CanvasRenderObject.hpp" #include "cru/ui/render/ScrollRenderObject.hpp" #include "cru/ui/render/TextRenderObject.hpp" -#include "gsl/gsl_util" + +#include <string> namespace cru::ui::controls { constexpr int k_default_caret_blink_duration = 500; @@ -262,15 +263,17 @@ class TextControlService : public Object { void StartSelection(Index start) { SetSelection(start); - log::TagDebug(log_tag, u"Text selection started, position: {}.", start); + if constexpr (debug_flags::text_service) + log::TagDebug(log_tag, u"Text selection started, position: {}.", start); } void UpdateSelection(Index new_end) { auto selection = GetSelection(); selection.AdjustEnd(new_end); this->SetSelection(selection); - log::TagDebug(log_tag, u"Text selection updated, range: {}, {}.", - selection.GetStart(), selection.GetEnd()); + if constexpr (debug_flags::text_service) + log::TagDebug(log_tag, u"Text selection updated, range: {}, {}.", + selection.GetStart(), selection.GetEnd()); } template <typename TArgs> diff --git a/src/ui/render/ScrollRenderObject.cpp b/src/ui/render/ScrollRenderObject.cpp index 08ce744b..24ea351a 100644 --- a/src/ui/render/ScrollRenderObject.cpp +++ b/src/ui/render/ScrollRenderObject.cpp @@ -138,7 +138,6 @@ Size ScrollRenderObject::OnMeasureContent(const MeasureRequirement& requirement, void ScrollRenderObject::OnLayoutContent(const Rect& content_rect) { if (const auto child = GetSingleChild()) { - const auto child_size = child->GetSize(); child->Layout(content_rect.GetLeftTop() - GetScrollOffset()); } } |