From 6315e654ce0be2d2cc148e9ff80f611ac1176348 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Thu, 6 Nov 2025 17:27:10 +0800 Subject: Refactor Event. --- include/cru/ui/controls/Button.h | 2 +- include/cru/ui/controls/IconButton.h | 5 +++-- include/cru/ui/controls/RootControl.h | 2 +- include/cru/ui/controls/TextHostControlService.h | 4 ++-- include/cru/ui/events/RoutedEvent.h | 2 +- include/cru/ui/helper/ClickDetector.h | 6 +++--- include/cru/ui/helper/ShortcutHub.h | 2 +- include/cru/ui/host/WindowHost.h | 2 +- include/cru/ui/render/ScrollBar.h | 2 +- include/cru/ui/render/ScrollRenderObject.h | 2 +- include/cru/ui/style/StyleRuleSet.h | 4 ++-- 11 files changed, 17 insertions(+), 16 deletions(-) (limited to 'include/cru/ui') diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h index 3c01be32..e8fa50f1 100644 --- a/include/cru/ui/controls/Button.h +++ b/include/cru/ui/controls/Button.h @@ -33,7 +33,7 @@ class CRU_UI_API Button : public SingleChildControl, return click_detector_.StateChangeEvent(); } - IEvent* ClickEvent() { + IEvent* ClickEvent() { return click_detector_.ClickEvent(); } diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h index 9e7572e0..e52d2a26 100644 --- a/include/cru/ui/controls/IconButton.h +++ b/include/cru/ui/controls/IconButton.h @@ -39,7 +39,7 @@ class CRU_UI_API IconButton : public NoChildControl, return click_detector_.StateChangeEvent(); } - IEvent* ClickEvent() { + IEvent* ClickEvent() { return click_detector_.ClickEvent(); } @@ -87,7 +87,8 @@ class CRU_UI_API IconButton : public NoChildControl, void SetIconWithSvgPathDataString(std::string_view icon_svg_path_data_string, const Rect& view_port); void SetIconWithSvgPathDataStringResourceKey( - std::string_view icon_svg_path_data_string_resource_key, const Rect& view_port); + std::string_view icon_svg_path_data_string_resource_key, + const Rect& view_port); std::shared_ptr GetContentBrush() const override { return GetIconFillBrush(); diff --git a/include/cru/ui/controls/RootControl.h b/include/cru/ui/controls/RootControl.h index 5fa8090e..e662b655 100644 --- a/include/cru/ui/controls/RootControl.h +++ b/include/cru/ui/controls/RootControl.h @@ -28,7 +28,7 @@ class CRU_UI_API RootControl Control* attached_control_; - EventRevokerListGuard + EventHandlerRevokerListGuard gain_focus_on_create_and_destroy_when_lose_focus_event_guard_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h index 529225a7..a9f4f22b 100644 --- a/include/cru/ui/controls/TextHostControlService.h +++ b/include/cru/ui/controls/TextHostControlService.h @@ -187,8 +187,8 @@ class CRU_UI_API TextHostControlService : public Object { Event text_change_event_; - EventRevokerListGuard event_guard_; - EventRevokerListGuard input_method_context_event_guard_; + EventHandlerRevokerListGuard event_guard_; + EventHandlerRevokerListGuard input_method_context_event_guard_; std::string text_; TextRange selection_; diff --git a/include/cru/ui/events/RoutedEvent.h b/include/cru/ui/events/RoutedEvent.h index a01839a6..9a07e1e9 100644 --- a/include/cru/ui/events/RoutedEvent.h +++ b/include/cru/ui/events/RoutedEvent.h @@ -16,7 +16,7 @@ class CRU_UI_API RoutedEvent { using RawEventArgs = TEventArgs; using IEventType = IEvent; - using EventArgs = typename IEventType::EventArgs; + using EventArgs = typename IEventType::Args; RoutedEvent() = default; RoutedEvent(const RoutedEvent& other) = delete; diff --git a/include/cru/ui/helper/ClickDetector.h b/include/cru/ui/helper/ClickDetector.h index eaf1f4af..2eb453d9 100644 --- a/include/cru/ui/helper/ClickDetector.h +++ b/include/cru/ui/helper/ClickDetector.h @@ -57,7 +57,7 @@ class ClickDetector : public Object { // deactivated. void SetTriggerButton(MouseButton trigger_button); - IEvent* ClickEvent() { return &event_; } + IEvent* ClickEvent() { return &event_; } IEvent* StateChangeEvent() { return &state_change_event_; } @@ -72,10 +72,10 @@ class ClickDetector : public Object { bool enable_ = true; MouseButton trigger_button_ = MouseButtons::Left | MouseButtons::Right; - Event event_; + Event event_; Event state_change_event_; - std::vector event_rovoker_guards_; + std::vector event_rovoker_guards_; Point down_point_; MouseButton button_; diff --git a/include/cru/ui/helper/ShortcutHub.h b/include/cru/ui/helper/ShortcutHub.h index d2c9952b..1b600c48 100644 --- a/include/cru/ui/helper/ShortcutHub.h +++ b/include/cru/ui/helper/ShortcutHub.h @@ -131,6 +131,6 @@ class CRU_UI_API ShortcutHub : public Object { Event fallback_event_; - EventRevokerListGuard event_guard_; + EventHandlerRevokerListGuard event_guard_; }; } // namespace cru::ui::helper diff --git a/include/cru/ui/host/WindowHost.h b/include/cru/ui/host/WindowHost.h index 6e7a0f2e..889665d5 100644 --- a/include/cru/ui/host/WindowHost.h +++ b/include/cru/ui/host/WindowHost.h @@ -156,7 +156,7 @@ class CRU_UI_API WindowHost : public Object, public SelfResolvable { Event after_layout_event_; std::vector > after_layout_stable_action_; - std::vector event_revoker_guards_; + std::vector event_revoker_guards_; controls::Control* mouse_hover_control_ = nullptr; diff --git a/include/cru/ui/render/ScrollBar.h b/include/cru/ui/render/ScrollBar.h index 8c531489..50b21386 100644 --- a/include/cru/ui/render/ScrollBar.h +++ b/include/cru/ui/render/ScrollBar.h @@ -136,7 +136,7 @@ class CRU_UI_API ScrollBar : public Object { std::optional mouse_hover_; std::optional mouse_press_; - EventRevokerListGuard event_guard_; + EventHandlerRevokerListGuard event_guard_; Event scroll_attempt_event_; diff --git a/include/cru/ui/render/ScrollRenderObject.h b/include/cru/ui/render/ScrollRenderObject.h index 63a49aa3..348d7af1 100644 --- a/include/cru/ui/render/ScrollRenderObject.h +++ b/include/cru/ui/render/ScrollRenderObject.h @@ -95,6 +95,6 @@ class CRU_UI_API ScrollRenderObject : public SingleChildRenderObject { bool is_mouse_wheel_enabled_ = true; - EventRevokerListGuard guard_; + EventHandlerRevokerListGuard guard_; }; } // namespace cru::ui::render diff --git a/include/cru/ui/style/StyleRuleSet.h b/include/cru/ui/style/StyleRuleSet.h index 0b7a237d..d89c3ae1 100644 --- a/include/cru/ui/style/StyleRuleSet.h +++ b/include/cru/ui/style/StyleRuleSet.h @@ -63,7 +63,7 @@ class CRU_UI_API StyleRuleSet : public Object, public model::IListChangeNotify { Event list_change_event_; std::shared_ptr parent_ = nullptr; - EventRevokerGuard parent_change_event_guard_; + EventHandlerRevokerGuard parent_change_event_guard_; std::vector rules_; }; @@ -90,6 +90,6 @@ class CRU_UI_API StyleRuleSetBind { // child first, parent last. std::vector ruleset_chain_cache_; - EventRevokerListGuard guard_; + EventHandlerRevokerListGuard guard_; }; } // namespace cru::ui::style -- cgit v1.2.3