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

Panel scrollbar improvements #990

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ynzenu
Copy link

@ynzenu ynzenu commented Sep 29, 2024

This PR contains three changes related to the panel scrollbar:

  • Add a ScrollDistance property to panel
  • Add a ScrollToChild method to panel
  • Automatically update the scrollbar position

ScrollDistance

There is currently no way easily access the scrollbar position. This new property will make it easier to get and set the scrollbar distance.

Usage:

panel.ScrollDistance = 0.5f;

ScrollToChild

New method that will update the scrollbar distance based on the location of a child control inside the panel.

Usage:

var panel = new FlowPanel()
{
    Parent = buildPanel,
    Width = 100,
    Height = 100,
    CanScroll = true,
};

var row1 = new ViewContainer()
{
    Parent = panel,
    Size = new Point(100, 100)
};

var row2 = new ViewContainer()
{
    Parent = panel,
    Size = new Point(100, 100)
};

panel.ScrollToChild(row2)

Automatically update the scrollbar position

The scrollbar will reset when the content inside the panel is resized. That means the scroll position resets when opening menu items. With the changes in this PR, the panel will now correctly calculate the scrollbar position after resizing.

Before:
https://github.com/user-attachments/assets/578d4a2f-e938-45f6-a7f8-7e0cb4846c42

After:
https://github.com/user-attachments/assets/4e6820ec-22da-477b-9d3d-5a44e15071bc

Discussion Reference

All new features must be discussed prior to code review. This is to ensure that the implementation aligns with other design considerations. Please link to the Discord discussion:

https://discord.com/channels/531175899588984842/599270434642460753/1289759568175431721

Is this a breaking change?

Breaking changes require additional review prior to merging. If you answer yes, please explain what breaking changes have been made.

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant