aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-10 19:49:06 +0800
committercrupest <crupest@outlook.com>2022-02-10 19:49:06 +0800
commitc1dbad5fdf0560983e6c832eddded6f610eae94e (patch)
tree40f22f7e6aa7ef39c49b1c007beed37130fc0b5d /include
parentb2622f654598f82a220a98daaa84fed9ce3b92b2 (diff)
downloadcru-c1dbad5fdf0560983e6c832eddded6f610eae94e.tar.gz
cru-c1dbad5fdf0560983e6c832eddded6f610eae94e.tar.bz2
cru-c1dbad5fdf0560983e6c832eddded6f610eae94e.zip
...
Diffstat (limited to 'include')
-rw-r--r--include/cru/ui/components/Menu.h18
-rw-r--r--include/cru/ui/controls/Button.h6
-rw-r--r--include/cru/ui/controls/Container.h4
-rw-r--r--include/cru/ui/controls/FlexLayout.h6
-rw-r--r--include/cru/ui/controls/Popup.h4
-rw-r--r--include/cru/ui/controls/ScrollView.h6
-rw-r--r--include/cru/ui/controls/StackLayout.h6
-rw-r--r--include/cru/ui/controls/TextBlock.h12
-rw-r--r--include/cru/ui/controls/TextBox.h6
-rw-r--r--include/cru/ui/controls/TreeView.h5
-rw-r--r--include/cru/ui/controls/Window.h8
11 files changed, 20 insertions, 61 deletions
diff --git a/include/cru/ui/components/Menu.h b/include/cru/ui/components/Menu.h
index 32936f84..99668f62 100644
--- a/include/cru/ui/components/Menu.h
+++ b/include/cru/ui/components/Menu.h
@@ -22,7 +22,7 @@ class CRU_UI_API MenuItem : public Component {
~MenuItem();
public:
- controls::Control* GetRootControl() override { return container_; }
+ controls::Control* GetRootControl() override { return &container_; }
void SetText(String text);
@@ -31,8 +31,8 @@ class CRU_UI_API MenuItem : public Component {
}
private:
- controls::Button* container_;
- controls::TextBlock* text_;
+ controls::Button container_;
+ controls::TextBlock text_;
std::function<void()> on_click_;
};
@@ -46,7 +46,7 @@ class CRU_UI_API Menu : public Component {
~Menu();
public:
- controls::Control* GetRootControl() override { return container_; }
+ controls::Control* GetRootControl() override { return &container_; }
gsl::index GetItemCount() const {
return static_cast<gsl::index>(items_.size());
@@ -67,7 +67,7 @@ class CRU_UI_API Menu : public Component {
}
private:
- controls::FlexLayout* container_;
+ controls::FlexLayout container_;
std::vector<Component*> items_;
std::function<void(Index)> on_item_click_;
@@ -85,8 +85,8 @@ class CRU_UI_API PopupMenu : public Component {
public:
controls::Control* GetRootControl() override;
- controls::Popup* GetPopup() { return popup_; }
- Menu* GetMenu() { return menu_; }
+ controls::Popup* GetPopup() { return &popup_; }
+ Menu* GetMenu() { return &menu_; }
// position relative to screen left top.
void SetPosition(const Point& position);
@@ -101,7 +101,7 @@ class CRU_UI_API PopupMenu : public Component {
private:
controls::Control* attached_control_;
- controls::Popup* popup_;
- Menu* menu_;
+ controls::Popup popup_;
+ Menu menu_;
};
} // namespace cru::ui::components
diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h
index d35d7ef8..1828dc57 100644
--- a/include/cru/ui/controls/Button.h
+++ b/include/cru/ui/controls/Button.h
@@ -15,12 +15,8 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>,
public:
static constexpr StringView kControlType = u"Button";
- static Button* Create() { return new Button(); }
-
- protected:
- Button();
-
public:
+ Button();
Button(const Button& other) = delete;
Button(Button&& other) = delete;
Button& operator=(const Button& other) = delete;
diff --git a/include/cru/ui/controls/Container.h b/include/cru/ui/controls/Container.h
index adb0fad1..3df2b445 100644
--- a/include/cru/ui/controls/Container.h
+++ b/include/cru/ui/controls/Container.h
@@ -8,10 +8,8 @@ class CRU_UI_API Container
: public SingleChildControl<render::BorderRenderObject> {
static constexpr StringView kControlType = u"Container";
- protected:
- Container();
-
public:
+ Container();
CRU_DELETE_COPY(Container)
CRU_DELETE_MOVE(Container)
diff --git a/include/cru/ui/controls/FlexLayout.h b/include/cru/ui/controls/FlexLayout.h
index 15494742..148586c0 100644
--- a/include/cru/ui/controls/FlexLayout.h
+++ b/include/cru/ui/controls/FlexLayout.h
@@ -15,12 +15,8 @@ class CRU_UI_API FlexLayout
public:
static constexpr StringView kControlType = u"FlexLayout";
- static FlexLayout* Create() { return new FlexLayout(); }
-
- protected:
- FlexLayout();
-
public:
+ FlexLayout();
FlexLayout(const FlexLayout& other) = delete;
FlexLayout(FlexLayout&& other) = delete;
FlexLayout& operator=(const FlexLayout& other) = delete;
diff --git a/include/cru/ui/controls/Popup.h b/include/cru/ui/controls/Popup.h
index 271ad4b7..464e7278 100644
--- a/include/cru/ui/controls/Popup.h
+++ b/include/cru/ui/controls/Popup.h
@@ -10,10 +10,6 @@ class CRU_UI_API Popup : public RootControl {
public:
static constexpr StringView kControlType = u"Popup";
- static Popup* Create(Control* attached_control = nullptr) {
- return new Popup(attached_control);
- }
-
explicit Popup(Control* attached_control = nullptr);
CRU_DELETE_COPY(Popup)
diff --git a/include/cru/ui/controls/ScrollView.h b/include/cru/ui/controls/ScrollView.h
index 43b6390c..244977d5 100644
--- a/include/cru/ui/controls/ScrollView.h
+++ b/include/cru/ui/controls/ScrollView.h
@@ -7,17 +7,11 @@ namespace cru::ui::controls {
class CRU_UI_API ScrollView
: public SingleChildControl<render::ScrollRenderObject> {
public:
- static ScrollView* Create() { return new ScrollView(); }
-
static constexpr StringView kControlType = u"ScrollView";
- protected:
ScrollView();
-
- public:
CRU_DELETE_COPY(ScrollView)
CRU_DELETE_MOVE(ScrollView)
-
~ScrollView() override;
public:
diff --git a/include/cru/ui/controls/StackLayout.h b/include/cru/ui/controls/StackLayout.h
index 28e0e796..82826171 100644
--- a/include/cru/ui/controls/StackLayout.h
+++ b/include/cru/ui/controls/StackLayout.h
@@ -9,15 +9,9 @@ class CRU_UI_API StackLayout
public:
static constexpr StringView kControlType = u"StackLayout";
- static StackLayout* Create() { return new StackLayout(); }
-
- protected:
StackLayout();
-
- public:
CRU_DELETE_COPY(StackLayout)
CRU_DELETE_MOVE(StackLayout)
-
~StackLayout() override;
String GetControlType() const final { return kControlType.ToString(); }
diff --git a/include/cru/ui/controls/TextBlock.h b/include/cru/ui/controls/TextBlock.h
index feb5cfa3..dc47d00a 100644
--- a/include/cru/ui/controls/TextBlock.h
+++ b/include/cru/ui/controls/TextBlock.h
@@ -10,19 +10,19 @@ class CRU_UI_API TextBlock : public NoChildControl,
public:
static constexpr StringView kControlType = u"TextBlock";
- static TextBlock* Create();
- static TextBlock* Create(String text, bool selectable = false);
-
- protected:
- TextBlock();
-
public:
+ TextBlock();
TextBlock(const TextBlock& other) = delete;
TextBlock(TextBlock&& other) = delete;
TextBlock& operator=(const TextBlock& other) = delete;
TextBlock& operator=(TextBlock&& other) = delete;
~TextBlock() override;
+ TextBlock(String text, bool selectable = false) : TextBlock() {
+ SetText(std::move(text));
+ SetSelectable(selectable);
+ }
+
String GetControlType() const final { return kControlType.ToString(); }
render::RenderObject* GetRenderObject() const override;
diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h
index 0632cc12..94a1ac0c 100644
--- a/include/cru/ui/controls/TextBox.h
+++ b/include/cru/ui/controls/TextBox.h
@@ -15,15 +15,9 @@ class CRU_UI_API TextBox : public NoChildControl,
public:
static constexpr StringView control_type = u"TextBox";
- static TextBox* Create() { return new TextBox(); }
-
- protected:
TextBox();
-
- public:
CRU_DELETE_COPY(TextBox)
CRU_DELETE_MOVE(TextBox)
-
~TextBox() override;
String GetControlType() const final { return control_type.ToString(); }
diff --git a/include/cru/ui/controls/TreeView.h b/include/cru/ui/controls/TreeView.h
index 2e782ee0..b36ca553 100644
--- a/include/cru/ui/controls/TreeView.h
+++ b/include/cru/ui/controls/TreeView.h
@@ -7,13 +7,10 @@ class TreeView;
class CRU_UI_API TreeViewItem : public Object {
friend TreeView;
- private:
- TreeViewItem(TreeView* tree_view, TreeViewItem* parent);
-
public:
+ TreeViewItem(TreeView* tree_view, TreeViewItem* parent);
CRU_DELETE_COPY(TreeViewItem)
CRU_DELETE_MOVE(TreeViewItem)
-
~TreeViewItem() override;
TreeView* GetTreeView() { return tree_view_; }
diff --git a/include/cru/ui/controls/Window.h b/include/cru/ui/controls/Window.h
index 5fb6d594..a1a97f87 100644
--- a/include/cru/ui/controls/Window.h
+++ b/include/cru/ui/controls/Window.h
@@ -10,15 +10,9 @@ class CRU_UI_API Window final : public RootControl {
static constexpr StringView control_type = u"Window";
public:
- static Window* Create(Control* attached_control = nullptr);
-
- private:
- explicit Window(Control* attached_control);
-
- public:
+ explicit Window(Control* attached_control = nullptr);
CRU_DELETE_COPY(Window)
CRU_DELETE_MOVE(Window)
-
~Window() override;
public: