DEV Community

Kyle Homen
Kyle Homen

Posted on

Hacktoberfest Week 4

This week I decided to try contributing to godot, the game engine I used last week to contribute to the ShooterCarnival project, and a game engine I'm very interested in using for my own projects in the future.

This felt like a very natural progression from where we started, and after I identified in Week 2 that I would like to work on gaming related projects, I took it a step further and contributed to a game engine.

The issue was that when the RichTextLabel gui item added a scrollbar for when the text content overflowed, it wasn't properly removing it when that text content was subsequently removed and shouldn't need the scrollbar anymore.

I looked at the code for a while, tried modifying how the _resize_line and _shape_line functions worked, but nothing was actually changing. I tried removing the scroll_w variable from the equations which -did- make changes in how the text area was being sized, but still did not function correctly. The text area would start with space for the scroll bar, add the scroll bar when needed, then when the scrollbar was removed it would remove that blank space as well.

Finally, I noticed this section of _update_scroll_exceeds:

    if (exceeds != scroll_visible) {
        if (exceeds) {
            scroll_visible = true;
            _prepare_scroll_anchor();
            vscroll->show();
        } else {
            scroll_visible = false;
            scroll_w = 0; // Why are we making this 0?
        }
Enter fullscreen mode Exit fullscreen mode

Whenever we set scroll_visible to false to remove the scroll bar, we're setting the scroll width to 0, which is used to calculate the size of the box. Removing this line resulted in this:

I could be wrong, but compared to the video in the issue and what I was experiencing when I recreated the bug, this looks a lot cleaner and updates correctly when scroll bar is added and removed.

Now.. this ended up being an easy one line fix (unless otherwise stated as my PR is under review), which was not my intention. But it still felt good to pour over the code, work with C++ instead of Python, and contribute something to such a large and respected project.

Top comments (0)