From e38ea3de29ede0e45aab8e595da5e8e3782a396d Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 2 Apr 2020 20:51:19 +0800 Subject: ... --- src/ui/click_detector.cpp | 3 +-- src/ui/content_control.cpp | 4 +--- src/ui/control.cpp | 3 +-- src/ui/controls/flex_layout.cpp | 4 ++-- src/ui/controls/text_control_service.hpp | 6 +++--- src/ui/layout_control.cpp | 10 ++++------ src/ui/render/border_render_object.cpp | 1 - src/ui/render/flex_layout_render_object.cpp | 1 - src/ui/render/render_object.cpp | 24 ++++++++++++------------ src/ui/render/text_render_object.cpp | 7 +++---- src/ui/render/window_render_object.cpp | 4 +--- src/ui/window.cpp | 3 +-- 12 files changed, 29 insertions(+), 41 deletions(-) (limited to 'src/ui') diff --git a/src/ui/click_detector.cpp b/src/ui/click_detector.cpp index b620201c..3f342a31 100644 --- a/src/ui/click_detector.cpp +++ b/src/ui/click_detector.cpp @@ -2,12 +2,11 @@ #include "cru/common/logger.hpp" -#include #include namespace cru::ui { ClickDetector::ClickDetector(Control* control) { - assert(control); + Expects(control); control_ = control; event_rovoker_guards_.push_back( diff --git a/src/ui/content_control.cpp b/src/ui/content_control.cpp index 5bc8eda4..5dcd89d9 100644 --- a/src/ui/content_control.cpp +++ b/src/ui/content_control.cpp @@ -2,8 +2,6 @@ #include "cru/ui/window.hpp" -#include - namespace cru::ui { ContentControl::ContentControl() : child_vector_{nullptr}, child_(child_vector_[0]) {} @@ -11,7 +9,7 @@ ContentControl::ContentControl() ContentControl::~ContentControl() { delete child_; } void ContentControl::SetChild(Control* child) { - assert(!dynamic_cast(child)); // Can't add a window as child. + Expects(!dynamic_cast(child)); // Can't add a window as child. if (child == child_) return; const auto window = GetWindow(); diff --git a/src/ui/control.cpp b/src/ui/control.cpp index e3b7b967..180ba476 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -7,7 +7,6 @@ #include "cru/ui/window.hpp" #include "routed_event_dispatch.hpp" -#include #include namespace cru::ui { @@ -38,7 +37,7 @@ void Control::_SetDescendantWindow(Window* window) { if (window == nullptr && window_ == nullptr) return; // You can only attach or detach window. - assert((window != nullptr && window_ == nullptr) || + Expects((window != nullptr && window_ == nullptr) || (window == nullptr && window_ != nullptr)); if (window == nullptr) { diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp index 1c649e3b..c881b6f1 100644 --- a/src/ui/controls/flex_layout.cpp +++ b/src/ui/controls/flex_layout.cpp @@ -29,14 +29,14 @@ int FindPosition(render::RenderObject* parent, render::RenderObject* child) { } // namespace FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { - assert(control); + Expects(control); return *render_object_->GetChildLayoutData( FindPosition(render_object_.get(), control->GetRenderObject())); } void FlexLayout::SetChildLayoutData(Control* control, const FlexChildLayoutData& data) { - assert(control); + Expects(control); *render_object_->GetChildLayoutData( FindPosition(render_object_.get(), control->GetRenderObject())) = data; } diff --git a/src/ui/controls/text_control_service.hpp b/src/ui/controls/text_control_service.hpp index d4f3ecf9..0da8abed 100644 --- a/src/ui/controls/text_control_service.hpp +++ b/src/ui/controls/text_control_service.hpp @@ -141,7 +141,7 @@ void TextControlService::AbortSelection() { template void TextControlService::SetupCaretTimer() { #ifdef CRU_DEBUG - assert(!caret_timer_set_); + Expects(!caret_timer_set_); caret_timer_set_ = true; #endif caret_timer_tag_ = @@ -155,7 +155,7 @@ void TextControlService::SetupCaretTimer() { template void TextControlService::TearDownCaretTimer() { #ifdef CRU_DEBUG - assert(!caret_timer_set_); + Expects(!caret_timer_set_); caret_timer_set_ = false; #endif platform::native::IUiApplication::GetInstance()->CancelTimer( @@ -164,7 +164,7 @@ void TextControlService::TearDownCaretTimer() { template void TextControlService::SetupHandlers() { - assert(event_revoker_guards_.empty()); + Expects(event_revoker_guards_.empty()); event_revoker_guards_.push_back( EventRevokerGuard{control_->MouseMoveEvent()->Direct()->AddHandler( std::bind(&TextControlService::MouseMoveHandler, this, diff --git a/src/ui/layout_control.cpp b/src/ui/layout_control.cpp index 3b4646e5..cb71da30 100644 --- a/src/ui/layout_control.cpp +++ b/src/ui/layout_control.cpp @@ -2,17 +2,15 @@ #include "cru/ui/window.hpp" -#include - namespace cru::ui { LayoutControl::~LayoutControl() { for (const auto child : children_) delete child; } void LayoutControl::AddChild(Control* control, const int position) { - assert(control->GetParent() == nullptr); // The control already has a parent. - assert(!dynamic_cast(control)); // Can't add a window as child. - assert(position >= 0 || + Expects(control->GetParent() == nullptr); // The control already has a parent. + Expects(!dynamic_cast(control)); // Can't add a window as child. + Expects(position >= 0 || position <= static_cast( this->children_.size())); // The position is out of range. @@ -26,7 +24,7 @@ void LayoutControl::AddChild(Control* control, const int position) { } void LayoutControl::RemoveChild(const int position) { - assert(position >= 0 && + Expects(position >= 0 && position < static_cast( this->children_.size())); // The position is out of range. diff --git a/src/ui/render/border_render_object.cpp b/src/ui/render/border_render_object.cpp index 5b6cdb3c..7c96a3b6 100644 --- a/src/ui/render/border_render_object.cpp +++ b/src/ui/render/border_render_object.cpp @@ -7,7 +7,6 @@ #include "cru/platform/graph/util/painter.hpp" #include -#include namespace cru::ui::render { BorderRenderObject::BorderRenderObject() { diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp index 791e705a..f40a9b3e 100644 --- a/src/ui/render/flex_layout_render_object.cpp +++ b/src/ui/render/flex_layout_render_object.cpp @@ -3,7 +3,6 @@ #include "cru/platform/graph/util/painter.hpp" #include -#include #include namespace cru::ui::render { diff --git a/src/ui/render/render_object.cpp b/src/ui/render/render_object.cpp index 5cce6d0d..c1b1b19b 100644 --- a/src/ui/render/render_object.cpp +++ b/src/ui/render/render_object.cpp @@ -3,18 +3,18 @@ #include "cru/common/logger.hpp" #include -#include namespace cru::ui::render { void RenderObject::AddChild(RenderObject* render_object, const int position) { - assert(child_mode_ != ChildMode::None); - assert(!(child_mode_ == ChildMode::Single && children_.size() > 0)); + Expects(child_mode_ != ChildMode::None); + Expects(!(child_mode_ == ChildMode::Single && children_.size() > 0)); - assert(render_object->GetParent() == - nullptr); // Render object already has a parent. - assert(position >= 0); // Position index is less than 0. - assert(position <= static_cast( - children_.size())); // Position index is out of bound. + Expects(render_object->GetParent() == + nullptr); // Render object already has a parent. + Expects(position >= 0); // Position index is less than 0. + Expects( + position <= + static_cast(children_.size())); // Position index is out of bound. children_.insert(children_.cbegin() + position, render_object); render_object->SetParent(this); @@ -23,9 +23,9 @@ void RenderObject::AddChild(RenderObject* render_object, const int position) { } void RenderObject::RemoveChild(const int position) { - assert(position >= 0); // Position index is less than 0. - assert(position < static_cast( - children_.size())); // Position index is out of bound. + Expects(position >= 0); // Position index is less than 0. + Expects(position < static_cast( + children_.size())); // Position index is out of bound. const auto i = children_.cbegin() + position; const auto removed_child = *i; @@ -45,7 +45,7 @@ Point RenderObject::GetTotalOffset() const { result.y += o.y; render_object = render_object->GetParent(); } - + return result; } diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp index d14a46e2..be02f8fe 100644 --- a/src/ui/render/text_render_object.cpp +++ b/src/ui/render/text_render_object.cpp @@ -6,7 +6,6 @@ #include "cru/platform/graph/util/painter.hpp" #include -#include // TODO: Null Check!!! @@ -15,9 +14,9 @@ TextRenderObject::TextRenderObject( std::shared_ptr brush, std::shared_ptr font, std::shared_ptr selection_brush) { - assert(brush); - assert(font); - assert(selection_brush); + Expects(brush); + Expects(font); + Expects(selection_brush); SetChildMode(ChildMode::None); diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp index 43269d09..29313645 100644 --- a/src/ui/render/window_render_object.cpp +++ b/src/ui/render/window_render_object.cpp @@ -7,15 +7,13 @@ #include "cru/platform/native/window.hpp" #include "cru/ui/window.hpp" -#include - namespace cru::ui::render { class WindowRenderHost : public IRenderHost, public SelfResolvable { public: WindowRenderHost(WindowRenderObject* render_object) : render_object_(render_object) { - assert(render_object != nullptr); + Expects(render_object != nullptr); } void InvalidateLayout() override; diff --git a/src/ui/window.cpp b/src/ui/window.cpp index dbe90478..a3279ba7 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -6,7 +6,6 @@ #include "cru/ui/render/window_render_object.hpp" #include "routed_event_dispatch.hpp" -#include #include namespace cru::ui { @@ -151,7 +150,7 @@ platform::native::INativeWindow* Window::ResolveNativeWindow() { } bool Window::RequestFocusFor(Control* control) { - assert(control != nullptr); // The control to request focus can't be null. + Expects(control != nullptr); // The control to request focus can't be null. // You can set it as the window. if (focus_control_ == control) return true; -- cgit v1.2.3