Skip to content

Commit

Permalink
Fix issue where an invalid element can take focus if mouse movement h…
Browse files Browse the repository at this point in the history
…appens immediately
  • Loading branch information
Mr-Wiseguy committed Apr 27, 2024
1 parent fab4f66 commit 8a70b23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ui/ui_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "nfd.h"
#include <filesystem>

std::string version_number = "v0.9.1";
std::string version_number = "v1.0.0-rc1";

Rml::DataModelHandle model_handle;
bool mm_rom_valid = false;
Expand Down
22 changes: 19 additions & 3 deletions src/ui/ui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,19 @@ void recomp::register_event(UiEventListenerInstancer& listener, const std::strin
listener.register_event(name, handler);
}

Rml::Element* find_autofocus_element(Rml::Element* start) {
Rml::Element* cur_element = start;

while (cur_element) {
if (cur_element->HasAttribute("autofocus")) {
break;
}
cur_element = RecompRml::FindNextTabElement(cur_element, true);
}

return cur_element;
}

struct UIContext {
struct UIRenderContext render;
class {
Expand Down Expand Up @@ -938,9 +951,12 @@ struct UIContext {
}

if (!mouse_is_active) {
if (!prev_focused) {
// get current focus and set to prev
prev_focused = current_document->GetFocusLeafNode();
if (!prev_focused || !can_focus(prev_focused)) {
// Find the autofocus element in the tab chain
Rml::Element* element = find_autofocus_element(current_document);
if (element && can_focus(element)) {
prev_focused = element;
}
}

if (mouse_is_active_changed && prev_focused && can_focus(prev_focused)) {
Expand Down

0 comments on commit 8a70b23

Please sign in to comment.