Custom scroll bar implementation - #982
Open
stavrosfa wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to solve some issues with the built-in Godot scroll bar.
Issues with the native scrollbar and screenshots with the corresponding affected need:
img 1
img 2
I had tried to tackle this problem again some time in the past, with some minor success, but the grabber issue streching had remained unsolved. Now, this is partly a new a solution that I will try to explain as clearly as possible.
We want to have a scroll container that contains many items.
We create a regular scroll container, we give it a VBoxContainer or a HBoxContainer, and spawn items inside it.
This will automatically create the scrollbar controls we need.
We hide these controls (not hide in the sense of nodes, more like using a style to make them "invisible") and we create our custom scroll bar controls.
These are just visual controls, nothing more. When we move our custom scrollbar grabber or press the increment/decrement buttons, we actually control the "hidden" native scroll bar controls. So we just translate the custom controls movement and position to the the scroll bar that's actually scrolling.
The godot node hierarchy looks something like this
Control
│
├── ScrollContainer
│ └── VBoxContainer
│ ├── Item (HBoxContainer or whatever)
│ ├── Item
│ ├── Item
│ └── Item
│
├──Civ3ScrollBarControl
│ ├── ScrollBar (Civ3VScrollBar or Civ3HScrollBar)
│ └── Civ3ScrollHandle
I tried to export the Civ3ScrollBarControl as a scene to make it easier to add to other scenes, but we are losing some customization control like size, etc. I am no Godot expert, so for now or untill some improvement suggestions come in, I 'll leave it like this.
In this commimt I have intentionally left a horizontal scroll container with a few color rect items in the domestic advisor scene so it's easier to verify that it's working for both directions and sizes and also see that we can have stepped but also free scrolling. This container will be removed after testing.
To test this, open a game that has more than 10 cities or so, open the domestic advisor and the scroll bar will be available.
I have also opened a PR for the standalone art here C7-Game/Assets#13
Once again, I have to disclose I used a lot of chat gpt on this one, especially for debugging, and I had to also fight it a lot to get it to implement some things the way I wanted it to and not some stupid way it was suggesting to me.