From 3b875091c445b7465b9bd044914318989a94d2ad Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 21 Nov 2025 21:43:42 +0800 Subject: Clean codes. Remove member function const. --- src/ui/controls/Control.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/ui/controls/Control.cpp') diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index 70a3b1f3..41644755 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -14,7 +14,8 @@ using platform::gui::ICursor; using platform::gui::IUiApplication; using platform::gui::SystemCursorType; -Control::Control() { +Control::Control(std::string name) + : name_(std::move(name)), host_(nullptr), parent_(nullptr) { style_rule_set_ = std::make_shared(); style_rule_set_bind_ = std::make_unique(this, style_rule_set_); @@ -30,9 +31,10 @@ Control::~Control() { RemoveAllChild(); } -std::string Control::GetDebugId() const { - return std::format("{}({})", GetControlType(), - static_cast(this)); +std::string Control::GetName() { return name_; } + +std::string Control::GetDebugId() { + return std::format("{}({})", GetName(), static_cast(this)); } ControlHost* Control::GetControlHost() { return host_; } @@ -50,6 +52,15 @@ bool Control::HasAncestor(Control* control) { const std::vector& Control::GetChildren() { return children_; } +Index Control::IndexOfChild(Control* control) { + const auto& children = GetChildren(); + auto iter = std::ranges::find(children, control); + if (iter == children.cend()) { + return -1; + } + return iter - children.begin(); +} + void Control::RemoveChild(Control* child) { auto iter = std::ranges::find(children_, child); if (iter != children_.cend()) { -- cgit v1.2.3