aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2018-11-10 20:05:29 +0800
committerGitHub <noreply@github.com>2018-11-10 20:05:29 +0800
commit0e9e897d306c71ab46fd9b5371d811950124ee27 (patch)
tree6e7c9dcda090b0fd0153c634165393e693894c10 /src/main.cpp
parent09be0d0c86a789d568addc3153917aa604e4c7d7 (diff)
parentfd3f899964bb0a3cad80bbb9afc4445fac1e6412 (diff)
downloadcru-0e9e897d306c71ab46fd9b5371d811950124ee27.tar.gz
cru-0e9e897d306c71ab46fd9b5371d811950124ee27.tar.bz2
cru-0e9e897d306c71ab46fd9b5371d811950124ee27.zip
Merge pull request #7 from crupest/parent-window
Add parent window support.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 264b3c7c..f9bc975c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,6 +6,7 @@
#include "ui/controls/button.hpp"
#include "ui/controls/text_box.hpp"
+using cru::ui::Rect;
using cru::String;
using cru::Application;
using cru::ui::Window;
@@ -28,7 +29,7 @@ int APIENTRY wWinMain(
Application application(hInstance);
- Window window;
+ const auto window = Window::CreateOverlapped();
/*
window.native_message_event.AddHandler([](cru::ui::events::WindowNativeMessageEventArgs& args)
{
@@ -86,7 +87,6 @@ int APIENTRY wWinMain(
//test 2
-
const auto layout = CreateWithLayout<LinearLayout>(LayoutSideParams::Exactly(500), LayoutSideParams::Content());
layout->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args)
@@ -104,7 +104,7 @@ int APIENTRY wWinMain(
#ifdef CRU_DEBUG_LAYOUT
toggle_button->toggle_event.AddHandler([&window](cru::ui::events::ToggleEventArgs& args)
{
- window.SetDebugLayout(args.GetNewState());
+ window->SetDebugLayout(args.GetNewState());
});
#endif
inner_layout->AddChild(toggle_button);
@@ -114,7 +114,37 @@ int APIENTRY wWinMain(
{
const auto button = Button::Create();
button->GetLayoutParams()->padding = Thickness(20, 5);
- button->AddChild(TextBlock::Create(L"button"));
+ button->AddChild(TextBlock::Create(L"Show popup window parenting this."));
+ button->mouse_click_event.AddHandler([window](auto)
+ {
+ Window::CreatePopup(window)->Show();
+ });
+ layout->AddChild(button);
+ }
+
+ {
+ const auto button = Button::Create();
+ button->GetLayoutParams()->padding = Thickness(20, 5);
+ button->AddChild(TextBlock::Create(L"Show popup window parenting null."));
+ button->mouse_click_event.AddHandler([](auto)
+ {
+ auto popup = Window::CreatePopup(nullptr);
+ popup->SetWindowRect(Rect(100, 100, 300, 300));
+ popup->Show();
+ });
+ layout->AddChild(button);
+ }
+
+ {
+ const auto button = Button::Create();
+ button->GetLayoutParams()->padding = Thickness(20, 5);
+ button->AddChild(TextBlock::Create(L"Show popup window with caption."));
+ button->mouse_click_event.AddHandler([](auto)
+ {
+ auto popup = Window::CreatePopup(nullptr, true);
+ popup->SetWindowRect(Rect(100, 100, 300, 300));
+ popup->Show();
+ });
layout->AddChild(button);
}
@@ -146,7 +176,7 @@ int APIENTRY wWinMain(
layout->AddChild(CreateWithLayout<TextBlock>(LayoutSideParams::Content(Alignment::End), LayoutSideParams::Stretch(), L"By crupest!!!"));
- window.AddChild(layout);
+ window->AddChild(layout);
/*
window.AddChild(
@@ -170,7 +200,8 @@ int APIENTRY wWinMain(
window.AddChild(linear_layout);
*/
- window.Show();
+
+ window->Show();
return application.Run();
}