aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/TextControlService.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-10 15:52:15 +0800
committercrupest <crupest@outlook.com>2020-11-10 15:52:15 +0800
commit2d4a5df468f8bc13fbb657e010c393365ef79bda (patch)
tree4ee7865663348ede1a961209c980fd614d727859 /src/ui/controls/TextControlService.hpp
parent02ed6999e9db0c20c3f55ab9c695f939aacb110c (diff)
downloadcru-2d4a5df468f8bc13fbb657e010c393365ef79bda.tar.gz
cru-2d4a5df468f8bc13fbb657e010c393365ef79bda.tar.bz2
cru-2d4a5df468f8bc13fbb657e010c393365ef79bda.zip
...
Diffstat (limited to 'src/ui/controls/TextControlService.hpp')
-rw-r--r--src/ui/controls/TextControlService.hpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp
index 92a66f5e..d50621ea 100644
--- a/src/ui/controls/TextControlService.hpp
+++ b/src/ui/controls/TextControlService.hpp
@@ -298,6 +298,24 @@ class TextControlService : public Object {
selection.GetStart(), selection.GetEnd());
}
+ void UpdateInputMethodPosition() {
+ if (auto input_method_context = this->GetInputMethodContext()) {
+ Point right_bottom =
+ this->GetTextRenderObject()->GetTotalOffset() +
+ this->GetTextRenderObject()->GetCaretRect().GetRightBottom();
+ right_bottom.x += 5;
+ right_bottom.y += 5;
+
+ if constexpr (debug_flags::text_service) {
+ log::TagDebug(log_tag,
+ u"Calculate input method candidate window position: {}.",
+ right_bottom.ToDebugString());
+ }
+
+ input_method_context->SetCandidateWindowPosition(right_bottom);
+ }
+ }
+
template <typename TArgs>
void SetupOneHandler(event::RoutedEvent<TArgs>* (Control::*event)(),
void (TextControlService::*handler)(
@@ -449,6 +467,12 @@ class TextControlService : public Object {
if (text == u"\b") return;
this->ReplaceSelectedText(text);
});
+
+ host::WindowHost* window_host = control_->GetWindowHost();
+ if (window_host)
+ input_method_context_event_guard_ +=
+ window_host->AfterLayoutEvent()->AddHandler(
+ [this](auto) { this->UpdateInputMethodPosition(); });
}
}
@@ -481,5 +505,5 @@ class TextControlService : public Object {
// nullopt means not selecting
std::optional<MouseButton> select_down_button_;
-}; // namespace cru::ui::controls
+};
} // namespace cru::ui::controls