aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-19 23:10:45 +0800
committercrupest <crupest@outlook.com>2018-11-19 23:10:45 +0800
commit5291b587708b7f1b9be9187aa4df99ea2cfe0538 (patch)
tree7d5d91ba4a0d979ceefea05bbe99efc47a9bf6a3
parent3edc249f48b4d7e692c782c1ca4809e07fa0726f (diff)
downloadcru-5291b587708b7f1b9be9187aa4df99ea2cfe0538.tar.gz
cru-5291b587708b7f1b9be9187aa4df99ea2cfe0538.tar.bz2
cru-5291b587708b7f1b9be9187aa4df99ea2cfe0538.zip
Add FrameLayout.
-rw-r--r--CruUI-Generate/cru_ui.cpp27
-rw-r--r--CruUI-Generate/cru_ui.hpp52
-rw-r--r--CruUI.vcxproj2
-rw-r--r--CruUI.vcxproj.filters6
-rw-r--r--src/main.cpp7
-rw-r--r--src/ui/controls/frame_layout.cpp16
-rw-r--r--src/ui/controls/frame_layout.hpp33
-rw-r--r--src/ui/ui_base.hpp15
8 files changed, 156 insertions, 2 deletions
diff --git a/CruUI-Generate/cru_ui.cpp b/CruUI-Generate/cru_ui.cpp
index 3436f3f4..497af786 100644
--- a/CruUI-Generate/cru_ui.cpp
+++ b/CruUI-Generate/cru_ui.cpp
@@ -283,6 +283,7 @@ using cru::ui::controls::ToggleButton;
using cru::ui::controls::Button;
using cru::ui::controls::TextBox;
using cru::ui::controls::ListItem;
+using cru::ui::controls::FrameLayout;
int APIENTRY wWinMain(
HINSTANCE hInstance,
@@ -363,6 +364,8 @@ int APIENTRY wWinMain(
inner_layout->AddChild(TextBlock::Create(L"Toggle debug border"));
+ const auto l = FrameLayout::Create();
+ l->GetLayoutParams()->padding.SetLeftRight(20.0f);
const auto toggle_button = ToggleButton::Create();
#ifdef CRU_DEBUG_LAYOUT
toggle_button->toggle_event.AddHandler([&window](cru::ui::events::ToggleEventArgs& args)
@@ -370,7 +373,8 @@ int APIENTRY wWinMain(
window->SetDebugLayout(args.GetNewState());
});
#endif
- inner_layout->AddChild(toggle_button);
+ l->AddChild(toggle_button);
+ inner_layout->AddChild(l);
layout->AddChild(inner_layout);
}
@@ -3083,6 +3087,27 @@ namespace cru::ui::controls
//-------end of file: src\ui\controls\button.cpp
//--------------------------------------------------------
//--------------------------------------------------------
+//-------begin of file: src\ui\controls\frame_layout.cpp
+//--------------------------------------------------------
+
+namespace cru::ui::controls
+{
+ FrameLayout::FrameLayout() : Control(true)
+ {
+
+ }
+
+ FrameLayout::~FrameLayout() = default;
+
+ StringView FrameLayout::GetControlType() const
+ {
+ return control_type;
+ }
+}
+//--------------------------------------------------------
+//-------end of file: src\ui\controls\frame_layout.cpp
+//--------------------------------------------------------
+//--------------------------------------------------------
//-------begin of file: src\ui\controls\linear_layout.cpp
//--------------------------------------------------------
diff --git a/CruUI-Generate/cru_ui.hpp b/CruUI-Generate/cru_ui.hpp
index ddfd8d9e..93360e3a 100644
--- a/CruUI-Generate/cru_ui.hpp
+++ b/CruUI-Generate/cru_ui.hpp
@@ -701,6 +701,21 @@ namespace cru::ui
return top + bottom;
}
+ void SetLeftRight(const float value)
+ {
+ left = right = value;
+ }
+
+ void SetTopBottom(const float value)
+ {
+ top = bottom = value;
+ }
+
+ void SetAll(const float value)
+ {
+ left = top = right = bottom = value;
+ }
+
float Validate() const
{
return left >= 0.0 && top >= 0.0 && right >= 0.0 && bottom >= 0.0;
@@ -2775,6 +2790,43 @@ namespace cru::ui::controls
//-------end of file: src\ui\controls\popup_menu.hpp
//--------------------------------------------------------
//--------------------------------------------------------
+//-------begin of file: src\ui\controls\frame_layout.hpp
+//--------------------------------------------------------
+
+#include <initializer_list>
+
+
+namespace cru::ui::controls
+{
+ class FrameLayout : public Control
+ {
+ public:
+ static constexpr auto control_type = L"FrameLayout";
+
+ static FrameLayout* Create(const std::initializer_list<Control*>& children = std::initializer_list<Control*>{})
+ {
+ const auto layout = new FrameLayout();
+ for (auto child : children)
+ layout->AddChild(child);
+ return layout;
+ }
+
+ protected:
+ FrameLayout();
+ public:
+ FrameLayout(const FrameLayout& other) = delete;
+ FrameLayout(FrameLayout&& other) = delete;
+ FrameLayout& operator=(const FrameLayout& other) = delete;
+ FrameLayout& operator=(FrameLayout&& other) = delete;
+ ~FrameLayout() override;
+
+ StringView GetControlType() const override final;
+ };
+}
+//--------------------------------------------------------
+//-------end of file: src\ui\controls\frame_layout.hpp
+//--------------------------------------------------------
+//--------------------------------------------------------
//-------begin of file: src\graph\graph.hpp
//--------------------------------------------------------
diff --git a/CruUI.vcxproj b/CruUI.vcxproj
index 3ca8fb40..932726cf 100644
--- a/CruUI.vcxproj
+++ b/CruUI.vcxproj
@@ -129,6 +129,7 @@
<ClCompile Include="src\ui\control.cpp" />
<ClCompile Include="src\ui\border_property.cpp" />
<ClCompile Include="src\ui\controls\button.cpp" />
+ <ClCompile Include="src\ui\controls\frame_layout.cpp" />
<ClCompile Include="src\ui\controls\linear_layout.cpp" />
<ClCompile Include="src\ui\controls\list_item.cpp" />
<ClCompile Include="src\ui\controls\popup_menu.cpp" />
@@ -137,6 +138,7 @@
<ClInclude Include="src\any_map.hpp" />
<ClInclude Include="src\format.hpp" />
<ClInclude Include="src\ui\border_property.hpp" />
+ <ClInclude Include="src\ui\controls\frame_layout.hpp" />
<ClInclude Include="src\ui\controls\list_item.hpp" />
<ClInclude Include="src\ui\controls\popup_menu.hpp" />
<ClInclude Include="src\ui\controls\text_control.hpp" />
diff --git a/CruUI.vcxproj.filters b/CruUI.vcxproj.filters
index 460cd233..b8c89bb1 100644
--- a/CruUI.vcxproj.filters
+++ b/CruUI.vcxproj.filters
@@ -87,6 +87,9 @@
<ClCompile Include="src\ui\controls\popup_menu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\ui\controls\frame_layout.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\graph\graph.hpp">
@@ -176,6 +179,9 @@
<ClInclude Include="src\ui\controls\popup_menu.hpp">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\ui\controls\frame_layout.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\application.cpp">
diff --git a/src/main.cpp b/src/main.cpp
index 8815b3ac..376c03b8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,7 @@
#include "ui/controls/text_box.hpp"
#include "ui/controls/list_item.hpp"
#include "ui/controls/popup_menu.hpp"
+#include "ui/controls/frame_layout.hpp"
#include "graph/graph.hpp"
using cru::String;
@@ -25,6 +26,7 @@ using cru::ui::controls::ToggleButton;
using cru::ui::controls::Button;
using cru::ui::controls::TextBox;
using cru::ui::controls::ListItem;
+using cru::ui::controls::FrameLayout;
int APIENTRY wWinMain(
HINSTANCE hInstance,
@@ -105,6 +107,8 @@ int APIENTRY wWinMain(
inner_layout->AddChild(TextBlock::Create(L"Toggle debug border"));
+ const auto l = FrameLayout::Create();
+ l->GetLayoutParams()->padding.SetLeftRight(20.0f);
const auto toggle_button = ToggleButton::Create();
#ifdef CRU_DEBUG_LAYOUT
toggle_button->toggle_event.AddHandler([&window](cru::ui::events::ToggleEventArgs& args)
@@ -112,7 +116,8 @@ int APIENTRY wWinMain(
window->SetDebugLayout(args.GetNewState());
});
#endif
- inner_layout->AddChild(toggle_button);
+ l->AddChild(toggle_button);
+ inner_layout->AddChild(l);
layout->AddChild(inner_layout);
}
diff --git a/src/ui/controls/frame_layout.cpp b/src/ui/controls/frame_layout.cpp
new file mode 100644
index 00000000..32d25edc
--- /dev/null
+++ b/src/ui/controls/frame_layout.cpp
@@ -0,0 +1,16 @@
+#include "frame_layout.hpp"
+
+namespace cru::ui::controls
+{
+ FrameLayout::FrameLayout() : Control(true)
+ {
+
+ }
+
+ FrameLayout::~FrameLayout() = default;
+
+ StringView FrameLayout::GetControlType() const
+ {
+ return control_type;
+ }
+}
diff --git a/src/ui/controls/frame_layout.hpp b/src/ui/controls/frame_layout.hpp
new file mode 100644
index 00000000..ca022780
--- /dev/null
+++ b/src/ui/controls/frame_layout.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <initializer_list>
+
+#include "ui/control.hpp"
+
+namespace cru::ui::controls
+{
+ class FrameLayout : public Control
+ {
+ public:
+ static constexpr auto control_type = L"FrameLayout";
+
+ static FrameLayout* Create(const std::initializer_list<Control*>& children = std::initializer_list<Control*>{})
+ {
+ const auto layout = new FrameLayout();
+ for (auto child : children)
+ layout->AddChild(child);
+ return layout;
+ }
+
+ protected:
+ FrameLayout();
+ public:
+ FrameLayout(const FrameLayout& other) = delete;
+ FrameLayout(FrameLayout&& other) = delete;
+ FrameLayout& operator=(const FrameLayout& other) = delete;
+ FrameLayout& operator=(FrameLayout&& other) = delete;
+ ~FrameLayout() override;
+
+ StringView GetControlType() const override final;
+ };
+}
diff --git a/src/ui/ui_base.hpp b/src/ui/ui_base.hpp
index c20d44b6..d9c9d0b2 100644
--- a/src/ui/ui_base.hpp
+++ b/src/ui/ui_base.hpp
@@ -91,6 +91,21 @@ namespace cru::ui
return top + bottom;
}
+ void SetLeftRight(const float value)
+ {
+ left = right = value;
+ }
+
+ void SetTopBottom(const float value)
+ {
+ top = bottom = value;
+ }
+
+ void SetAll(const float value)
+ {
+ left = top = right = bottom = value;
+ }
+
float Validate() const
{
return left >= 0.0 && top >= 0.0 && right >= 0.0 && bottom >= 0.0;