aboutsummaryrefslogtreecommitdiff
path: root/CruUI/main.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-22 22:57:44 +0800
committercrupest <crupest@outlook.com>2018-09-22 22:57:44 +0800
commit5d91d1e5594e37ca5c282e602407eaeb34c6d986 (patch)
tree0086bb88c152b8ea9eb31e86906afcd238309cda /CruUI/main.cpp
parentdc293cef8f25ba70c5d99d73aa472277484ca879 (diff)
downloadcru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.tar.gz
cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.tar.bz2
cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.zip
Done 3 things:
1. Add some helper functions for create controls with layout params. 2. Fix a bug in measure of linear layout. 3. Fix a bug in exception.
Diffstat (limited to 'CruUI/main.cpp')
-rw-r--r--CruUI/main.cpp35
1 files changed, 9 insertions, 26 deletions
diff --git a/CruUI/main.cpp b/CruUI/main.cpp
index f2c5747d..0fd747a1 100644
--- a/CruUI/main.cpp
+++ b/CruUI/main.cpp
@@ -10,10 +10,10 @@
using cru::String;
using cru::Application;
using cru::ui::Window;
-using cru::ui::MeasureMode;
using cru::ui::Alignment;
using cru::ui::LayoutLength;
using cru::ui::Thickness;
+using cru::ui::CreateWithLayout;
using cru::ui::controls::LinearLayout;
using cru::ui::controls::TextBlock;
using cru::ui::controls::ToggleButton;
@@ -76,9 +76,7 @@ int APIENTRY wWinMain(
//test 2
- const auto layout = LinearLayout::Create();
-
- layout->GetLayoutParams()->width = LayoutLength::Exactly(500);
+ const auto layout = CreateWithLayout<LinearLayout>(LayoutLength::Exactly(500), LayoutLength::Content());
layout->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args)
{
@@ -87,10 +85,7 @@ int APIENTRY wWinMain(
});
{
- const auto inner_layout = LinearLayout::Create(LinearLayout::Orientation::Horizontal);
- inner_layout->GetLayoutParams()->width.alignment = Alignment::End;
-
- layout->AddChild(inner_layout);
+ const auto inner_layout = CreateWithLayout<LinearLayout>(LayoutLength::Content(Alignment::End), LayoutLength::Content(), LinearLayout::Orientation::Horizontal);
inner_layout->AddChild(TextBlock::Create(L"Toggle debug border"));
@@ -101,24 +96,17 @@ int APIENTRY wWinMain(
});
inner_layout->AddChild(toggle_button);
+ layout->AddChild(inner_layout);
}
{
const auto button = Button::Create();
- button->AddChild(MarginContainer::Create(Thickness(20, 5), {TextBlock::Create(L"button")}));
+ button->AddChild(MarginContainer::Create(Thickness(20, 5), { TextBlock::Create(L"button") }));
layout->AddChild(button);
}
- auto&& create_text_block = [](const String& text, const LayoutLength& width = LayoutLength::Content(), const LayoutLength& height = LayoutLength::Content())
{
- const auto text_block = TextBlock::Create(text);
- text_block->GetLayoutParams()->width = width;
- text_block->GetLayoutParams()->height = height;
- return text_block;
- };
-
- {
- const auto text_block = create_text_block(L"Hello World!!!", LayoutLength::Exactly(200), LayoutLength::Exactly(80));
+ const auto text_block = CreateWithLayout<TextBlock>(LayoutLength::Exactly(200), LayoutLength::Exactly(80), L"Hello World!!!");
text_block->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args)
{
@@ -129,18 +117,13 @@ int APIENTRY wWinMain(
}
{
- const auto text_block = create_text_block(L"This is a very very very very very long sentence!!!", LayoutLength::Stretch(), LayoutLength::Stretch());
+ const auto text_block = CreateWithLayout<TextBlock>(LayoutLength::Stretch(), LayoutLength::Stretch(), L"This is a very very very very very long sentence!!!");
text_block->SetSelectable(true);
layout->AddChild(text_block);
}
- {
- const auto text_block = TextBlock::Create(L"This is a little short sentence!!!");
- text_block->GetLayoutParams()->width.alignment = Alignment::Start;
- layout->AddChild(text_block);
- }
-
- layout->AddChild(create_text_block(L"By crupest!!!", LayoutLength::Stretch(), LayoutLength::Stretch()));
+ layout->AddChild(CreateWithLayout<TextBlock>(LayoutLength::Content(Alignment::Start), LayoutLength::Content(), L"This is a little short sentence!!!"));
+ layout->AddChild(CreateWithLayout<TextBlock>(LayoutLength::Content(Alignment::End), LayoutLength::Stretch(), L"By crupest!!!"));
window.AddChild(layout);