Repository: bevyengine/bevy
File: crates/bevy_ui/src/ui_node.rs (Rust)

Code before:
    }

    const fn compute_thumb(
        gutter_min: f32,
        content_length: f32,
        gutter_length: f32,
        scroll_position: f32,
    ) -> [f32; 2] {
        if content_length <= gutter_length {
            return [gutter_min, gutter_min + gutter_length];
        }
        let thumb_len = gutter_length * gutter_length / content_length;
        let thumb_min = gutter_min
            + scroll_position / (content_length - gutter_length) * (gutter_length - thumb_len);
        [thumb_min, thumb_min + thumb_len]
    }

    /// Compute the bounds of the horizontal scrollbar and the thumb
    /// in object-centered coordinates.
    pub fn horizontal_scrollbar(&self) -> Option<(Rect, [f32; 2])> {
        if self.scrollbar_size.y <= 0. {
            return None;
        }
        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;
        let max_y = half_size.y - content_inset.bottom;
        let min_y = max_y - self.scrollbar_size.y;
        let gutter = Rect {
            min: Vec2::new(min_x, min_y),
            max: Vec2::new(max_x, max_y),
        };
        Some((
            gutter,
            Self::compute_thumb(
                gutter.min.x,
                self.content_size.x,
                gutter.size().x,
                self.scroll_position.x,
            ),
        ))
    }

    /// Compute the bounds of the horizontal scrollbar and the thumb
    /// in object-centered coordinates.
    pub fn vertical_scrollbar(&self) -> Option<(Rect, [f32; 2])> {
        if self.scrollbar_size.x <= 0. {
            return None;
        }
        let content_inset = self.content_inset();

Review comment (suggestion):
These will probably have to be changed dependent on the timing of your [PR titled "UI scrollbars clipping fix"  being merged](https://github.com/bevyengine/bevy/pull/21910/files) #21910 , so that these subtractions of `scrollbar_size` can be removed when applicable

Code after:
    }

    const fn compute_thumb(
        gutter_min: f32,
        content_length: f32,
        gutter_length: f32,
        scroll_position: f32,
    ) -> [f32; 2] {
        if content_length <= gutter_length {
            return [gutter_min, gutter_min + gutter_length];
        }
        let thumb_len = gutter_length * gutter_length / content_length;
        let thumb_min = gutter_min + scroll_position * gutter_length / content_length;
        [thumb_min, thumb_min + thumb_len]
    }

    /// Compute the bounds of the horizontal scrollbar and the thumb
    /// in object-centered coordinates.
    pub fn horizontal_scrollbar(&self) -> Option<(Rect, [f32; 2])> {
        if self.scrollbar_size.y <= 0. {
            return None;
        }
        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;
        let max_y = half_size.y - content_inset.bottom;
        let min_y = max_y - self.scrollbar_size.y;
        let gutter = Rect {
            min: Vec2::new(min_x, min_y),
            max: Vec2::new(max_x, max_y),
        };
        Some((
            gutter,
            Self::compute_thumb(
                gutter.min.x,
                self.content_size.x,
                gutter.size().x,
                self.scroll_position.x,
            ),
        ))
    }

    /// Compute the bounds of the vertical scrollbar and the thumb
    /// in object-centered coordinates.
    pub fn vertical_scrollbar(&self) -> Option<(Rect, [f32; 2])> {
        if self.scrollbar_size.x <= 0. {
            return None;
        }
        let content_inset = self.content_inset();
        let half_size = 0.5 * self.size;