aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-09-11 11:39:19 +0800
committercrupest <crupest@outlook.com>2020-09-11 11:39:19 +0800
commitf357d11518796b0e0c2c5f23d8eafeda48226af9 (patch)
tree503c2a8e23fb2fcf35aaea054120ee1402337b0a
parent93b8a62d28f9427f0979d62b71f12fb2858064ee (diff)
downloadcru-f357d11518796b0e0c2c5f23d8eafeda48226af9.tar.gz
cru-f357d11518796b0e0c2c5f23d8eafeda48226af9.tar.bz2
cru-f357d11518796b0e0c2c5f23d8eafeda48226af9.zip
...
-rw-r--r--src/ui/UiHost.cpp6
-rw-r--r--src/ui/UiManager.cpp8
-rw-r--r--src/ui/controls/TextBox.cpp9
-rw-r--r--src/ui/controls/TextControlService.hpp1
4 files changed, 15 insertions, 9 deletions
diff --git a/src/ui/UiHost.cpp b/src/ui/UiHost.cpp
index 5eee3925..5db113bf 100644
--- a/src/ui/UiHost.cpp
+++ b/src/ui/UiHost.cpp
@@ -182,11 +182,13 @@ bool UiHost::RequestFocusFor(Control* control) {
if (focus_control_ == control) return true;
- DispatchEvent(event_names::LoseFocus, focus_control_,
- &Control::LoseFocusEvent, nullptr, false);
+ const auto old_focus_control = focus_control_;
focus_control_ = control;
+ DispatchEvent(event_names::LoseFocus, old_focus_control,
+ &Control::LoseFocusEvent, nullptr, false);
+
DispatchEvent(event_names::GainFocus, control, &Control::GainFocusEvent,
nullptr, false);
diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp
index b50a9775..4cd38efa 100644
--- a/src/ui/UiManager.cpp
+++ b/src/ui/UiManager.cpp
@@ -1,10 +1,10 @@
#include "cru/ui/UiManager.hpp"
+#include "Helper.hpp"
#include "cru/platform/graph/Brush.hpp"
#include "cru/platform/graph/Factory.hpp"
#include "cru/platform/graph/Font.hpp"
#include "cru/platform/native/UiApplication.hpp"
-#include "Helper.hpp"
namespace cru::ui {
using namespace cru::platform::graph;
@@ -68,10 +68,10 @@ UiManager::UiManager() {
theme_resource_.text_box_border_style.hover =
theme_resource_.text_box_border_style.normal;
- theme_resource_.text_box_border_style.normal.border_brush =
+ theme_resource_.text_box_border_style.focus.border_brush =
CreateSolidColorBrush(factory, Color::FromHex(0x495057));
- theme_resource_.text_box_border_style.normal.border_radius = CornerRadius(5);
- theme_resource_.text_box_border_style.normal.border_thickness = Thickness(1);
+ theme_resource_.text_box_border_style.focus.border_radius = CornerRadius(5);
+ theme_resource_.text_box_border_style.focus.border_thickness = Thickness(1);
theme_resource_.text_box_border_style.focus_hover =
theme_resource_.text_box_border_style.focus;
diff --git a/src/ui/controls/TextBox.cpp b/src/ui/controls/TextBox.cpp
index 2bc4cf95..4a8d6658 100644
--- a/src/ui/controls/TextBox.cpp
+++ b/src/ui/controls/TextBox.cpp
@@ -32,20 +32,23 @@ TextBox::TextBox()
border_render_object_->SetAttachedControl(this);
scroll_render_object_->SetAttachedControl(this);
text_render_object_->SetAttachedControl(this);
- text_render_object_->SetMinSize(Size{50, 20});
+ text_render_object_->SetMinSize(Size{100, 24});
service_ = std::make_unique<TextControlService<TextBox>>(this);
service_->SetEnabled(true);
service_->SetCaretVisible(true);
service_->SetEditable(true);
+ border_render_object_->SetBorderEnabled(true);
+ border_render_object_->SetBorderStyle(border_style_.normal);
+
GainFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) {
- this->service_->SetEnabled(true);
+ this->service_->SetCaretVisible(true);
this->UpdateBorderStyle();
});
LoseFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) {
- this->service_->SetEnabled(false);
+ this->service_->SetCaretVisible(false);
this->UpdateBorderStyle();
});
}
diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp
index 0d05f2c3..2a7ad0c7 100644
--- a/src/ui/controls/TextControlService.hpp
+++ b/src/ui/controls/TextControlService.hpp
@@ -202,6 +202,7 @@ class TextControlService : public Object {
}
void MouseDownHandler(event::MouseButtonEventArgs& args) {
+ this->control_->RequestFocus();
if (this->select_down_button_.has_value()) {
return;
} else {