aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-04-02 20:51:19 +0800
committercrupest <crupest@outlook.com>2020-04-02 20:51:19 +0800
commite38ea3de29ede0e45aab8e595da5e8e3782a396d (patch)
tree1e0fae414abea5b5cf1fd4fb4194f8c6a9795d7e /src/ui
parent7dd9494e957af8280f7221395333f886c500edf5 (diff)
downloadcru-e38ea3de29ede0e45aab8e595da5e8e3782a396d.tar.gz
cru-e38ea3de29ede0e45aab8e595da5e8e3782a396d.tar.bz2
cru-e38ea3de29ede0e45aab8e595da5e8e3782a396d.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/click_detector.cpp3
-rw-r--r--src/ui/content_control.cpp4
-rw-r--r--src/ui/control.cpp3
-rw-r--r--src/ui/controls/flex_layout.cpp4
-rw-r--r--src/ui/controls/text_control_service.hpp6
-rw-r--r--src/ui/layout_control.cpp10
-rw-r--r--src/ui/render/border_render_object.cpp1
-rw-r--r--src/ui/render/flex_layout_render_object.cpp1
-rw-r--r--src/ui/render/render_object.cpp24
-rw-r--r--src/ui/render/text_render_object.cpp7
-rw-r--r--src/ui/render/window_render_object.cpp4
-rw-r--r--src/ui/window.cpp3
12 files changed, 29 insertions, 41 deletions
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 <cassert>
#include <optional>
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 <cassert>
-
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<Window*>(child)); // Can't add a window as child.
+ Expects(!dynamic_cast<Window*>(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 <cassert>
#include <memory>
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<TControl>::AbortSelection() {
template <typename TControl>
void TextControlService<TControl>::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<TControl>::SetupCaretTimer() {
template <typename TControl>
void TextControlService<TControl>::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<TControl>::TearDownCaretTimer() {
template <typename TControl>
void TextControlService<TControl>::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 <cassert>
-
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<Window*>(control)); // Can't add a window as child.
- assert(position >= 0 ||
+ Expects(control->GetParent() == nullptr); // The control already has a parent.
+ Expects(!dynamic_cast<Window*>(control)); // Can't add a window as child.
+ Expects(position >= 0 ||
position <=
static_cast<int>(
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<int>(
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 <algorithm>
-#include <cassert>
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 <algorithm>
-#include <cassert>
#include <functional>
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 <algorithm>
-#include <cassert>
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<int>(
- 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<int>(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<int>(
- children_.size())); // Position index is out of bound.
+ Expects(position >= 0); // Position index is less than 0.
+ Expects(position < static_cast<int>(
+ 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 <algorithm>
-#include <cassert>
// TODO: Null Check!!!
@@ -15,9 +14,9 @@ TextRenderObject::TextRenderObject(
std::shared_ptr<platform::graph::IBrush> brush,
std::shared_ptr<platform::graph::IFont> font,
std::shared_ptr<platform::graph::IBrush> 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 <cassert>
-
namespace cru::ui::render {
class WindowRenderHost : public IRenderHost,
public SelfResolvable<WindowRenderHost> {
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 <cassert>
#include <list>
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;