aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/control.cpp14
-rw-r--r--src/ui/controls/text_box.cpp22
-rw-r--r--src/ui/render/border_render_object.cpp9
-rw-r--r--src/ui/window.cpp9
4 files changed, 48 insertions, 6 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 04d89b5f..e3b7b967 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -16,11 +16,15 @@ using platform::native::IUiApplication;
using platform::native::SystemCursorType;
Control::Control() {
- MouseEnterEvent()->Direct()->AddHandler(
- [this](event::MouseEventArgs&) { this->is_mouse_over_ = true; });
-
- MouseLeaveEvent()->Direct()->AddHandler(
- [this](event::MouseEventArgs&) { this->is_mouse_over_ = false; });
+ MouseEnterEvent()->Direct()->AddHandler([this](event::MouseEventArgs&) {
+ this->is_mouse_over_ = true;
+ this->OnMouseHoverChange(true);
+ });
+
+ MouseLeaveEvent()->Direct()->AddHandler([this](event::MouseEventArgs&) {
+ this->is_mouse_over_ = false;
+ this->OnMouseHoverChange(true);
+ });
}
void Control::_SetParent(Control* parent) {
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp
index 1e0890b8..99164b9b 100644
--- a/src/ui/controls/text_box.cpp
+++ b/src/ui/controls/text_box.cpp
@@ -36,6 +36,16 @@ TextBox::TextBox()
stack_layout_render_object_->SetAttachedControl(this);
text_render_object_->SetAttachedControl(this);
caret_render_object_->SetAttachedControl(this);
+
+ GainFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) {
+ this->service_->SetEnabled(true);
+ this->UpdateBorderStyle();
+ });
+
+ LoseFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) {
+ this->service_->SetEnabled(false);
+ this->UpdateBorderStyle();
+ });
}
TextBox::~TextBox() {}
@@ -55,6 +65,16 @@ std::shared_ptr<platform::graph::IBrush> TextBox::GetCaretBrush() {
const TextBoxBorderStyle& TextBox::GetBorderStyle() { return border_style_; }
void TextBox::SetBorderStyle(TextBoxBorderStyle border_style) {
- border_style_ = std::move(border_style_);
+ border_style_ = std::move(border_style);
+}
+
+void TextBox::OnMouseHoverChange(bool) { UpdateBorderStyle(); }
+
+void TextBox::UpdateBorderStyle() {
+ const auto focus = HasFocus();
+ const auto hover = IsMouseOver();
+ border_render_object_->SetBorderStyle(
+ focus ? (hover ? border_style_.focus_hover : border_style_.focus)
+ : (hover ? border_style_.hover : border_style_.normal));
}
} // namespace cru::ui::controls
diff --git a/src/ui/render/border_render_object.cpp b/src/ui/render/border_render_object.cpp
index 16f2828a..5b6cdb3c 100644
--- a/src/ui/render/border_render_object.cpp
+++ b/src/ui/render/border_render_object.cpp
@@ -39,6 +39,15 @@ void BorderRenderObject::Draw(platform::graph::IPainter* painter) {
foreground_brush_.get());
}
+void BorderRenderObject::SetBorderStyle(const BorderStyle& style) {
+ border_brush_ = style.border_brush;
+ border_thickness_ = style.border_thickness;
+ border_radius_ = style.border_radius;
+ foreground_brush_ = style.foreground_brush;
+ background_brush_ = style.background_brush;
+ InvalidateLayout();
+}
+
RenderObject* BorderRenderObject::HitTest(const Point& point) {
if (const auto child = GetChild()) {
auto offset = child->GetOffset();
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index bf2e24ca..03c33cf3 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -32,6 +32,7 @@ CRU_DEFINE_EVENT_NAME(MouseDown)
CRU_DEFINE_EVENT_NAME(MouseUp)
CRU_DEFINE_EVENT_NAME(KeyDown)
CRU_DEFINE_EVENT_NAME(KeyUp)
+CRU_DEFINE_EVENT_NAME(Char)
#undef CRU_DEFINE_EVENT_NAME
} // namespace event_names
@@ -316,6 +317,14 @@ void Window::OnNativeKeyUp(INativeWindow* window, int virtual_code) {
nullptr, virtual_code);
}
+void Window::OnNativeChar(platform::native::INativeWindow* window,
+ std::string c) {
+ CRU_UNUSED(window)
+
+ DispatchEvent(event_names::Char, focus_control_, &Control::CharEvent, nullptr,
+ std::move(c));
+}
+
void Window::DispatchMouseHoverControlChangeEvent(Control* old_control,
Control* new_control,
const Point& point,