Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Nov 25, 2025

Objective

Add helper functions to ComputedNode to compute the scrollbar areas of a UI node.

Solution

Add horizontal_scrollbar and vertical_scrollbar functions to ComputedNode. If a scrollbar is present, these return an option wrapping a tuple of the node-centered bounding Rect for the scrollbar, and the start and end points of the thumb.

Testing

Includes a couple of tests in the uinode module.

@ickshonpe ickshonpe added A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 26, 2025
Copy link
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor, non blocking comments, LGTM

))
}

/// Compute the bounds of the horizontal scrollbar and the thumb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Compute the bounds of the horizontal scrollbar and the thumb
/// Compute the bounds of the vertical scrollbar and the thumb

}
let thumb_len = gutter_length * gutter_length / content_length;
let thumb_min = gutter_min
+ scroll_position / (content_length - gutter_length) * (gutter_length - thumb_len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the option to simplify this to:

Suggested change
+ scroll_position / (content_length - gutter_length) * (gutter_length - thumb_len);
+ scroll_position * gutter_length / content_length;

If you find it too verbose
Screenshot 2025-11-28 at 6 25 32 PM
I understand if you want to keep it written the way you have it since they’re equivalent / you may find it clearer the way you wrote it.

At the very least, I think it’s easier to read the line was changed to have the multiplicative term first i.e.

Suggested change
+ scroll_position / (content_length - gutter_length) * (gutter_length - thumb_len);
+ scroll_position * (gutter_length - thumb_len) / (content_length - gutter_length);

so it can be seen as multiplying by the ratio of “scrollable length in scrollbar” to “original hidden content length"

The new tests you wrote pass for me when I replace with the first suggested line.

let content_inset = self.content_inset();
let half_size = 0.5 * self.size;
let min_x = -half_size.x + content_inset.left;
let max_x = half_size.x - content_inset.right - self.scrollbar_size.x;
Copy link
Contributor

@kfc35 kfc35 Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will probably have to be changed dependent on the timing of your PR titled "UI scrollbars clipping fix" being merged #21910 , so that these subtractions of scrollbar_size can be removed when applicable

let max_x = half_size.x - content_inset.right;
let min_x = max_x - self.scrollbar_size.x;
let min_y = -half_size.y + content_inset.top;
let max_y = half_size.y - content_inset.bottom - self.scrollbar_size.y;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about your other PR and the timing of merges for the removal of - self.scrollbar_size.y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants