From 977c766e2337fea238804b8d8b97659361391ed0 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 24 Sep 2018 00:16:53 +0800 Subject: Develop basic function of textbox. --- CruUI/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'CruUI/main.cpp') diff --git a/CruUI/main.cpp b/CruUI/main.cpp index 56d42894..3d801964 100644 --- a/CruUI/main.cpp +++ b/CruUI/main.cpp @@ -6,6 +6,7 @@ #include "ui/controls/button.h" #include "ui/controls/margin_container.h" #include "ui/events/ui_event.h" +#include "ui/controls/text_box.h" using cru::String; @@ -20,6 +21,7 @@ using cru::ui::controls::TextBlock; using cru::ui::controls::ToggleButton; using cru::ui::controls::Button; using cru::ui::controls::MarginContainer; +using cru::ui::controls::TextBox; int APIENTRY wWinMain( HINSTANCE hInstance, @@ -84,8 +86,9 @@ int APIENTRY wWinMain( }); */ + /* //test 2 - + const auto layout = CreateWithLayout(LayoutSideParams::Exactly(500), LayoutSideParams::Content()); layout->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args) @@ -137,6 +140,9 @@ int APIENTRY wWinMain( window.AddChild(layout); + */ + + window.AddChild(CreateWithLayout(LayoutSideParams::Stretch(), LayoutSideParams::Stretch())); window.Show(); -- cgit v1.2.3 From 9049f7674e0808cc3676543e0a95330a1657d10e Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 24 Sep 2018 00:22:04 +0800 Subject: Add left and right support. --- CruUI/main.cpp | 6 +++--- CruUI/ui/controls/text_box.cpp | 16 ++++++++++++++++ CruUI/ui/controls/text_box.h | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'CruUI/main.cpp') diff --git a/CruUI/main.cpp b/CruUI/main.cpp index 3d801964..67b35406 100644 --- a/CruUI/main.cpp +++ b/CruUI/main.cpp @@ -31,7 +31,7 @@ int APIENTRY wWinMain( Application application(hInstance); Window window; - + /* window.native_message_event.AddHandler([](cru::ui::events::WindowNativeMessageEventArgs& args) { if (args.GetWindowMessage().msg == WM_PAINT) @@ -40,7 +40,7 @@ int APIENTRY wWinMain( //args.SetResult(0); } }); - + */ /* // test1 cru::ui::controls::TextBlock text_block; @@ -88,7 +88,7 @@ int APIENTRY wWinMain( /* //test 2 - + const auto layout = CreateWithLayout(LayoutSideParams::Exactly(500), LayoutSideParams::Content()); layout->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args) diff --git a/CruUI/ui/controls/text_box.cpp b/CruUI/ui/controls/text_box.cpp index 53417d40..a8d78398 100644 --- a/CruUI/ui/controls/text_box.cpp +++ b/CruUI/ui/controls/text_box.cpp @@ -125,6 +125,22 @@ namespace cru::ui::controls is_caret_show_ = false; } + void TextBox::OnKeyDownCore(events::KeyEventArgs& args) + { + Control::OnKeyDownCore(args); + if (args.GetVirtualCode() == VK_LEFT && position_ > 0) + { + position_--; + Repaint(); + } + + if (args.GetVirtualCode() == VK_RIGHT && position_ < GetText().size()) + { + position_++; + Repaint(); + } + } + void TextBox::OnCharCore(events::CharEventArgs& args) { Control::OnCharCore(args); diff --git a/CruUI/ui/controls/text_box.h b/CruUI/ui/controls/text_box.h index 5fe14782..b815ed1f 100644 --- a/CruUI/ui/controls/text_box.h +++ b/CruUI/ui/controls/text_box.h @@ -57,6 +57,7 @@ namespace cru::ui::controls void OnGetFocusCore(events::FocusChangeEventArgs& args) override final; void OnLoseFocusCore(events::FocusChangeEventArgs& args) override final; + void OnKeyDownCore(events::KeyEventArgs& args) override final; void OnCharCore(events::CharEventArgs& args) override final; Size OnMeasure(const Size& available_size) override final; -- cgit v1.2.3