aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-19 19:45:26 +0800
committercrupest <crupest@outlook.com>2020-03-19 19:45:26 +0800
commit507de8c6a931d0784c8f740d41db610d3ed8db68 (patch)
tree9f77d8e2b1b0955ff669677b4d5913a08075946a /src
parent5da4f511e85de9e79bee40e3c5e04f899a48723c (diff)
downloadcru-507de8c6a931d0784c8f740d41db610d3ed8db68.tar.gz
cru-507de8c6a931d0784c8f740d41db610d3ed8db68.tar.bz2
cru-507de8c6a931d0784c8f740d41db610d3ed8db68.zip
...
Diffstat (limited to 'src')
-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
-rw-r--r--src/win/native/window.cpp6
5 files changed, 53 insertions, 7 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,
diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp
index 2e99a5cb..c7bb1b9d 100644
--- a/src/win/native/window.cpp
+++ b/src/win/native/window.cpp
@@ -8,6 +8,7 @@
#include "cru/win/native/ui_application.hpp"
#include "cru/win/native/window_class.hpp"
#include "cru/win/native/window_render_target.hpp"
+#include "cru/win/string.hpp"
#include "dpi_util.hpp"
#include "window_d2d_painter.hpp"
#include "window_manager.hpp"
@@ -404,7 +405,10 @@ void WinNativeWindow::OnKeyUpInternal(int virtual_code) {
key_up_event_.Raise(virtual_code);
}
-void WinNativeWindow::OnCharInternal(wchar_t c) { CRU_UNUSED(c) }
+void WinNativeWindow::OnCharInternal(wchar_t c) {
+ wchar_t s[2] = {c, 0};
+ char_event_.Raise(platform::win::ToUtf8String(s));
+}
void WinNativeWindow::OnActivatedInternal() {}