@@ -22,7 +22,7 @@ namespace ui {
2222 Node::doResize ();
2323 }
2424
25- std::shared_ptr<ui::Node> Window::getFocused () {
25+ std::shared_ptr<ui::Node> Window::getFocus () {
2626 if (focusTarget.expired ()) {
2727 focus (findChildByPredicate ([](ui::Node* node){
2828 return *node->stealFocus ;
@@ -117,10 +117,9 @@ namespace ui {
117117 if (!guiEvent.target )
118118 return ;
119119
120- focus (guiEvent.target ->shared_from_this ());
121-
122- if (guiEvent.target )
123- guiEvent.target ->processEvent (guiEvent);
120+ auto target = guiEvent.target ->shared_from_this ();
121+ focus (target);
122+ target->processEvent (guiEvent);
124123 }
125124 }
126125
@@ -147,7 +146,7 @@ namespace ui {
147146
148147 auto shared = guiEvent.target ->shared_from_this ();
149148
150- if (auto focus = getFocused ()) {
149+ if (auto focus = getFocus ()) {
151150 if (focus.get () == guiEvent.target ) {
152151 guiEvent.target ->processEvent (ui::Click{focus.get (), eventX, eventY, event.buttons });
153152 }
@@ -162,13 +161,15 @@ namespace ui {
162161 hoverWindow = this ;
163162 ui::MouseWheel guiEvent{nullptr , mouseX, mouseY, mouseButtons, event.wheelX , event.wheelY };
164163 guiEvent.target = findEventTarget (guiEvent);
165- if (guiEvent.target )
166- guiEvent.target ->processEvent (guiEvent);
164+ if (guiEvent.target ) {
165+ auto shared = guiEvent.target ->shared_from_this ();
166+ shared->processEvent (guiEvent);
167+ }
167168 }
168169 }
169170
170171 void Window::on (msg::TextEvent& event) {
171- if (auto focus = getFocused ()) {
172+ if (auto focus = getFocus ()) {
172173 focus->processEvent (ui::TextEvent{
173174 focus.get (),
174175 event.text ,
@@ -178,7 +179,7 @@ namespace ui {
178179 }
179180
180181 void Window::on (msg::KeyDown& event) {
181- if (auto focus = getFocused ()) {
182+ if (auto focus = getFocus ()) {
182183 focus->processEvent (ui::KeyDown{
183184 focus.get (),
184185 event.scancode ,
@@ -190,7 +191,7 @@ namespace ui {
190191 }
191192
192193 void Window::on (msg::KeyUp& event) {
193- if (auto focus = getFocused ()) {
194+ if (auto focus = getFocus ()) {
194195 focus->processEvent (ui::KeyUp{
195196 focus.get (),
196197 event.scancode ,
0 commit comments