Skip to content

Commit

Permalink
Fix PageSearch scrollbar (shpaass#176)
Browse files Browse the repository at this point in the history
`gui.SetTextInputFocus` was setting `gui.mouseDownRect`, which is
heavily used by scrollbars to detect is the mouse is still inside the
scrollbar rect when dragging.

Since the `PageSearch` focus gets updated every (build) event, the
`mouseDownRect` was effectively always set to the search input, and the
scrollbar could not be dragged as it detected that the mouse was not in
the correct `Rect` anymore.

I fixes the issue by introducing a `gui.focusRect`, so these `Rect`s are
tracked independently. Both typing text, as well as dragging the
`PageSearch` scrollbar seem to be working now.

I (quickly) checked some other input fields, but did not see any
regressions.

(The other commit is a small cleanup that I encountered while debugging
this issue)

Fixes shpaass#168
  • Loading branch information
shpaass authored Jun 24, 2024
2 parents 5b02232 + cd6cf91 commit 2449322
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 24 deletions.
17 changes: 1 addition & 16 deletions Yafc.UI/ImGui/ImGuiBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,11 @@ public bool ConsumeEvent(Rect rect) {

public bool IsLastMouseDown(Rect rect) => rect == mouseDownRect;

public void ClearFocus() {
if (mouseDownRect != default) {
mouseDownRect = default;
Rebuild();
}
}

public void SetFocus(Rect rect) {
mouseDownRect = rect;
Rebuild();
}

public void SetTextInputFocus(Rect rect, string text) {
if (textInputHelper != null && inputSystem.currentKeyboardFocus != textInputHelper) {
SetFocus(rect);
Rebuild();
textInputHelper.SetFocus(rect, text);
}
}

public void SaveToImage() {
}
}
}
8 changes: 2 additions & 6 deletions Yafc/Windows/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,14 @@ private void BuildTabBar(ImGui gui) {
gui.allocator = RectAllocator.RightRow;
var spaceForDropdown = gui.AllocateRect(2.1f, 2.1f);
tabBar.Build(gui);
if (gui.isBuilding) {
gui.DrawIcon(spaceForDropdown.Expand(-0.3f), Icon.DropDown, SchemeColor.BackgroundText);
}

gui.DrawIcon(spaceForDropdown.Expand(-0.3f), Icon.DropDown, SchemeColor.BackgroundText);
if (gui.BuildButton(spaceForDropdown, SchemeColor.None, SchemeColor.Grey)) {
updatePageList();
ShowDropDown(gui, spaceForDropdown, missingPagesDropdown, new Padding(0f, 0f, 0f, 0.5f), 30f);
}
}
if (gui.isBuilding) {
gui.DrawRectangle(gui.lastRect, SchemeColor.PureBackground);
}
gui.DrawRectangle(gui.lastRect, SchemeColor.PureBackground);

void updatePageList() {
List<ProjectPage> sortedAndFilteredPageList = pageListSearch.Search(project.pages).ToList();
Expand Down
1 change: 0 additions & 1 deletion Yafc/Windows/WelcomeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ private void SetProject(ProjectDefinition? project) {
}
}
ValidateSelection();
rootGui.ClearFocus();
rootGui.Rebuild();
}

Expand Down
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
----------------------------------------------------------------------------------------------------------------------
Version 0.7.3
Date: soon

Bugfixes:
- Fix PageSearch scrollbar not working.
----------------------------------------------------------------------------------------------------------------------
Version 0.7.2
Date: June 23rd 2024
Expand Down

0 comments on commit 2449322

Please sign in to comment.