Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUIopedia links bug out when you scroll before clicking #614

Open
NFB418 opened this issue Jul 4, 2024 · 1 comment
Open

GUIopedia links bug out when you scroll before clicking #614

NFB418 opened this issue Jul 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@NFB418
Copy link

NFB418 commented Jul 4, 2024

Describe the bug
This is based on the guiopedia example found in the pygame_gui_examples repository here: https://github.com/MyreMylar/pygame_gui_examples/blob/master/guiopedia.py

When you start on a page with a reference link. If the page has enough text that you need to scroll down first before you can click the link, clicking that link will not take you to the linked page but instead to the top of the page you are on. Subsequent scrolling and clicking does take you to the reference page.

To Reproduce
Steps to reproduce the behaviour:

  1. Download the pygame_gui_examples repository.
  2. Change the index.html file to the following, which is simply adding enough break statements to push the reference links low enough to requiring scrolling to click:
<font size="6"><b>Welcome to GUI-opedia!</b></font>
<br><br>
This is a little test of creating a few hyperlink connected pages that we can display to
the user to give them more information. Maybe it'll have a search bar as well? Oh, hey now it does.
<br><br>
The point is we have multiple pages of text that we load in from files, and then we can navigate between them via links
all inside of a window. Here are a few of them to try clicking on:
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
 - <a href="cats">Cats</a> - A page all about cats.<br>
 - <a href="gravel">Gravel</a> - Gravel: What is the deal.<br>
  1. Scroll down and attempt to click the links to either Cats or Gravel. You will be taken to the top of the index page first. Scrolling again and clicking again does take you to the referenced page.

Expected behaviour
Scrolling should not affect behavior when links are clicked.

Screenshots
guiopedia bug report

Platform and software (please complete the following information):

  • OS: Windows
  • Pygame GUI version 0.6.12
  • Pygame version 2.5.0

Additional context
I was planning to make pretty extensive use of the Guiopedia feature for my project, so this is a bit of a bummer. It is probably above my skill to bug fix, so any help would be greatly appreciated!!! :)

@NFB418 NFB418 added the bug Something isn't working label Jul 4, 2024
@NFB418
Copy link
Author

NFB418 commented Jul 17, 2024

I have successfully tracked down the bug!

First, I ascertained that the bug I describe above only happened if you used the MOUSEWHEEL to scroll. Or at least, it did not happen when moving the scrollbar by clicking.

Second, I tracked down the issue to involving the UITextBox's update method. The following bit of code from this event was firing, resetting the scrollbar and overwriting mouse click events:

        if self.cursor_has_moved_recently:
            self.cursor_has_moved_recently = False

            self.text_box_layout.set_cursor_position(self.edit_position)
            if not self.vertical_cursor_movement:
                if self.text_box_layout.cursor_text_row is not None:
                    self.last_horiz_cursor_index = self.text_box_layout.cursor_text_row.get_cursor_index()
            self.vertical_cursor_movement = False
            self._handle_cursor_visibility()
            if self.scroll_bar is not None:
                cursor_y_pos_top, cursor_y_pos_bottom = self.text_box_layout.get_cursor_y_pos()
                current_height_adjustment = int(self.scroll_bar.start_percentage *
                                                self.text_box_layout.layout_rect.height)
                visible_bottom = current_height_adjustment + self.text_box_layout.view_rect.height
                # handle cursor moving above current scroll position
                if cursor_y_pos_top < current_height_adjustment:
                    new_start_percentage = cursor_y_pos_top / self.text_box_layout.layout_rect.height
                    self.scroll_bar.set_scroll_from_start_percentage(new_start_percentage)
                # handle cursor moving below visible area
                if cursor_y_pos_bottom > visible_bottom:
                    new_top = cursor_y_pos_bottom - self.text_box_layout.view_rect.height
                    new_start_percentage = new_top / self.text_box_layout.layout_rect.height
                    self.scroll_bar.set_scroll_from_start_percentage(new_start_percentage)

            self.redraw_from_text_block()

Third, I tracked down where self.cursor_has_moved_recently was being set prior this bug occuring, and I discovered that it was in the following method, also of the UITextBox class:

    def focus(self):
        """
        Called when we 'select focus' on this element.
        """
        super().focus()
        self.cursor_has_moved_recently = True

        if self.placeholder_text is not None:
            self.rebuild()

I was able to apply a quick fix for myself by simply commenting out the line setting self.cursor_has_moved_recently. This resolved the bug, and as far as I can tell did not change behavior otherwise.

Why this interaction between mouse wheel scrolling and the focus method caused this bug, I lack the skill to determine. As such, I'm leaving this issue open till a developer comes along with a comment/explanation and a proper fix. Hopefully though this can help people running into the same issue as me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant