aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-30 00:37:57 +0800
committercrupest <crupest@outlook.com>2020-10-30 00:37:57 +0800
commit624552fb112f29b91dd96f9543e813b5ee16e87b (patch)
tree68384d9ef640a3e99f82b81330a79079cb83218d
parent72d801f9b2a41ab2bcd9023c65422e089d885107 (diff)
downloadcru-624552fb112f29b91dd96f9543e813b5ee16e87b.tar.gz
cru-624552fb112f29b91dd96f9543e813b5ee16e87b.tar.bz2
cru-624552fb112f29b91dd96f9543e813b5ee16e87b.zip
...
-rw-r--r--include/cru/ui/WindowHost.hpp1
-rw-r--r--src/ui/WindowHost.cpp21
2 files changed, 8 insertions, 14 deletions
diff --git a/include/cru/ui/WindowHost.hpp b/include/cru/ui/WindowHost.hpp
index 97acf72e..7f7d62f0 100644
--- a/include/cru/ui/WindowHost.hpp
+++ b/include/cru/ui/WindowHost.hpp
@@ -126,7 +126,6 @@ class WindowHost : public Object {
platform::gui::INativeWindow* native_window_ = nullptr;
bool need_layout_ = false;
- platform::gui::TimerAutoCanceler relayout_timer_canceler_;
Event<AfterLayoutEventArgs> after_layout_event_;
std::vector<std::function<void()> > after_layout_stable_action_;
diff --git a/src/ui/WindowHost.cpp b/src/ui/WindowHost.cpp
index 4b32467b..b0908e4f 100644
--- a/src/ui/WindowHost.cpp
+++ b/src/ui/WindowHost.cpp
@@ -146,16 +146,8 @@ void WindowHost::InvalidatePaint() {
}
void WindowHost::InvalidateLayout() {
- if constexpr (debug_flags::layout)
- log::TagDebug(log_tag, u"A relayout is requested.");
- if (!need_layout_) {
- platform::gui::IUiApplication::GetInstance()->SetImmediate([this] {
- Relayout();
- need_layout_ = false;
- InvalidatePaint();
- });
- need_layout_ = true;
- }
+ need_layout_ = true;
+ this->InvalidatePaint();
}
bool WindowHost::IsLayoutPreferToFillWindow() const {
@@ -253,11 +245,14 @@ void WindowHost::RunAfterLayoutStable(std::function<void()> action) {
void WindowHost::OnNativeDestroy(INativeWindow* window, std::nullptr_t) {
CRU_UNUSED(window)
- this->relayout_timer_canceler_.Reset();
this->native_window_ = nullptr;
}
void WindowHost::OnNativePaint(INativeWindow* window, std::nullptr_t) {
+ if (need_layout_) {
+ Relayout();
+ need_layout_ = false;
+ }
auto painter = window->BeginPaint();
painter->Clear(colors::white);
root_render_object_->Draw(painter.get());
@@ -356,8 +351,8 @@ void WindowHost::OnNativeKeyDown(
nullptr, args.key, args.modifier);
}
-void WindowHost::OnNativeKeyUp(
- INativeWindow* window, const platform::gui::NativeKeyEventArgs& args) {
+void WindowHost::OnNativeKeyUp(INativeWindow* window,
+ const platform::gui::NativeKeyEventArgs& args) {
CRU_UNUSED(window)
DispatchEvent(event_names::KeyUp, focus_control_, &Control::KeyUpEvent,