Revert unintended renaming (#25318)

Just little bit clean up from #25288

Release Notes:

- N/A
This commit is contained in:
smit 2025-02-21 18:44:23 +05:30 committed by GitHub
parent dff47a8436
commit c9235ff916
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -224,189 +224,181 @@ impl Element for Scrollbar {
fn paint( fn paint(
&mut self, &mut self,
_id: Option<&GlobalElementId>, _id: Option<&GlobalElementId>,
padded_bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState, _request_layout: &mut Self::RequestLayoutState,
_prepaint: &mut Self::PrepaintState, _prepaint: &mut Self::PrepaintState,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) { ) {
window.with_content_mask( window.with_content_mask(Some(ContentMask { bounds }), |window| {
Some(ContentMask { let colors = cx.theme().colors();
bounds: padded_bounds, let thumb_background = colors
}), .surface_background
|window| { .blend(colors.scrollbar_thumb_background);
let colors = cx.theme().colors(); let is_vertical = self.kind == ScrollbarAxis::Vertical;
let thumb_background = colors let extra_padding = px(5.0);
.surface_background let padded_bounds = if is_vertical {
.blend(colors.scrollbar_thumb_background); Bounds::from_corners(
let is_vertical = self.kind == ScrollbarAxis::Vertical; bounds.origin + point(Pixels::ZERO, extra_padding),
let extra_padding = px(5.0); bounds.bottom_right() - point(Pixels::ZERO, extra_padding * 3),
let padded_bounds = if is_vertical { )
Bounds::from_corners( } else {
padded_bounds.origin + point(Pixels::ZERO, extra_padding), Bounds::from_corners(
padded_bounds.bottom_right() - point(Pixels::ZERO, extra_padding * 3), bounds.origin + point(extra_padding, Pixels::ZERO),
) bounds.bottom_right() - point(extra_padding * 3, Pixels::ZERO),
} else { )
Bounds::from_corners( };
padded_bounds.origin + point(extra_padding, Pixels::ZERO),
padded_bounds.bottom_right() - point(extra_padding * 3, Pixels::ZERO),
)
};
let mut thumb_bounds = if is_vertical { let mut thumb_bounds = if is_vertical {
let thumb_offset = self.thumb.start * padded_bounds.size.height; let thumb_offset = self.thumb.start * padded_bounds.size.height;
let thumb_end = self.thumb.end * padded_bounds.size.height; let thumb_end = self.thumb.end * padded_bounds.size.height;
let thumb_upper_left = point( let thumb_upper_left = point(
padded_bounds.origin.x, padded_bounds.origin.x,
padded_bounds.origin.y + thumb_offset, padded_bounds.origin.y + thumb_offset,
); );
let thumb_lower_right = point( let thumb_lower_right = point(
padded_bounds.origin.x + padded_bounds.size.width, padded_bounds.origin.x + padded_bounds.size.width,
padded_bounds.origin.y + thumb_end, padded_bounds.origin.y + thumb_end,
); );
Bounds::from_corners(thumb_upper_left, thumb_lower_right) Bounds::from_corners(thumb_upper_left, thumb_lower_right)
} else { } else {
let thumb_offset = self.thumb.start * padded_bounds.size.width; let thumb_offset = self.thumb.start * padded_bounds.size.width;
let thumb_end = self.thumb.end * padded_bounds.size.width; let thumb_end = self.thumb.end * padded_bounds.size.width;
let thumb_upper_left = point( let thumb_upper_left = point(
padded_bounds.origin.x + thumb_offset, padded_bounds.origin.x + thumb_offset,
padded_bounds.origin.y, padded_bounds.origin.y,
); );
let thumb_lower_right = point( let thumb_lower_right = point(
padded_bounds.origin.x + thumb_end, padded_bounds.origin.x + thumb_end,
padded_bounds.origin.y + padded_bounds.size.height, padded_bounds.origin.y + padded_bounds.size.height,
); );
Bounds::from_corners(thumb_upper_left, thumb_lower_right) Bounds::from_corners(thumb_upper_left, thumb_lower_right)
}; };
let corners = if is_vertical { let corners = if is_vertical {
thumb_bounds.size.width /= 1.5; thumb_bounds.size.width /= 1.5;
Corners::all(thumb_bounds.size.width / 2.0) Corners::all(thumb_bounds.size.width / 2.0)
} else { } else {
thumb_bounds.size.height /= 1.5; thumb_bounds.size.height /= 1.5;
Corners::all(thumb_bounds.size.height / 2.0) Corners::all(thumb_bounds.size.height / 2.0)
}; };
window.paint_quad(quad( window.paint_quad(quad(
thumb_bounds, thumb_bounds,
corners, corners,
thumb_background, thumb_background,
Edges::default(), Edges::default(),
Hsla::transparent_black(), Hsla::transparent_black(),
)); ));
let scroll = self.state.scroll_handle.clone(); let scroll = self.state.scroll_handle.clone();
let axis = self.kind; let axis = self.kind;
window.on_mouse_event({ window.on_mouse_event({
let scroll = scroll.clone(); let scroll = scroll.clone();
let state = self.state.clone(); let state = self.state.clone();
move |event: &MouseDownEvent, phase, _, _| { move |event: &MouseDownEvent, phase, _, _| {
if !(phase.bubble() && padded_bounds.contains(&event.position)) { if !(phase.bubble() && bounds.contains(&event.position)) {
return; return;
} }
if thumb_bounds.contains(&event.position) { if thumb_bounds.contains(&event.position) {
let offset = let offset = event.position.along(axis) - thumb_bounds.origin.along(axis);
event.position.along(axis) - thumb_bounds.origin.along(axis); state.drag.set(Some(offset));
state.drag.set(Some(offset)); } else if let Some(ContentSize {
} else if let Some(ContentSize { size: item_size, ..
size: item_size, .. }) = scroll.content_size()
}) = scroll.content_size() {
{ let click_offset = {
let click_offset = { let viewport_size = padded_bounds.size.along(axis);
let viewport_size = padded_bounds.size.along(axis);
let thumb_size = thumb_bounds.size.along(axis); let thumb_size = thumb_bounds.size.along(axis);
let thumb_start = (event.position.along(axis) let thumb_start = (event.position.along(axis)
- padded_bounds.origin.along(axis) - padded_bounds.origin.along(axis)
- (thumb_size / 2.)) - (thumb_size / 2.))
.clamp(px(0.), viewport_size - thumb_size); .clamp(px(0.), viewport_size - thumb_size);
let max_offset = let max_offset = (item_size.along(axis) - viewport_size).max(px(0.));
(item_size.along(axis) - viewport_size).max(px(0.)); let percentage = if viewport_size > thumb_size {
let percentage = if viewport_size > thumb_size { thumb_start / (viewport_size - thumb_size)
thumb_start / (viewport_size - thumb_size) } else {
} else { 0.
0.
};
-max_offset * percentage
}; };
match axis {
ScrollbarAxis::Horizontal => { -max_offset * percentage
scroll.set_offset(point(click_offset, scroll.offset().y)); };
} match axis {
ScrollbarAxis::Vertical => { ScrollbarAxis::Horizontal => {
scroll.set_offset(point(scroll.offset().x, click_offset)); scroll.set_offset(point(click_offset, scroll.offset().y));
} }
ScrollbarAxis::Vertical => {
scroll.set_offset(point(scroll.offset().x, click_offset));
} }
} }
} }
}); }
window.on_mouse_event({ });
let scroll = scroll.clone(); window.on_mouse_event({
move |event: &ScrollWheelEvent, phase, window, _| { let scroll = scroll.clone();
if phase.bubble() && padded_bounds.contains(&event.position) { move |event: &ScrollWheelEvent, phase, window, _| {
let current_offset = scroll.offset(); if phase.bubble() && bounds.contains(&event.position) {
scroll.set_offset( let current_offset = scroll.offset();
current_offset + event.delta.pixel_delta(window.line_height()), scroll.set_offset(
); current_offset + event.delta.pixel_delta(window.line_height()),
} );
} }
}); }
let state = self.state.clone(); });
let axis = self.kind; let state = self.state.clone();
window.on_mouse_event(move |event: &MouseMoveEvent, _, _, cx| { let axis = self.kind;
if let Some(drag_state) = state.drag.get().filter(|_| event.dragging()) { window.on_mouse_event(move |event: &MouseMoveEvent, _, _, cx| {
if let Some(ContentSize { if let Some(drag_state) = state.drag.get().filter(|_| event.dragging()) {
size: item_size, .. if let Some(ContentSize {
}) = scroll.content_size() size: item_size, ..
{ }) = scroll.content_size()
let drag_offset = { {
let viewport_size = padded_bounds.size.along(axis); let drag_offset = {
let viewport_size = padded_bounds.size.along(axis);
let thumb_size = thumb_bounds.size.along(axis); let thumb_size = thumb_bounds.size.along(axis);
let thumb_start = (event.position.along(axis) let thumb_start = (event.position.along(axis)
- padded_bounds.origin.along(axis) - padded_bounds.origin.along(axis)
- drag_state) - drag_state)
.clamp(px(0.), viewport_size - thumb_size); .clamp(px(0.), viewport_size - thumb_size);
let max_offset = let max_offset = (item_size.along(axis) - viewport_size).max(px(0.));
(item_size.along(axis) - viewport_size).max(px(0.)); let percentage = if viewport_size > thumb_size {
let percentage = if viewport_size > thumb_size { thumb_start / (viewport_size - thumb_size)
thumb_start / (viewport_size - thumb_size) } else {
} else { 0.
0.
};
-max_offset * percentage
}; };
match axis {
ScrollbarAxis::Horizontal => { -max_offset * percentage
scroll.set_offset(point(drag_offset, scroll.offset().y)); };
} match axis {
ScrollbarAxis::Vertical => { ScrollbarAxis::Horizontal => {
scroll.set_offset(point(scroll.offset().x, drag_offset)); scroll.set_offset(point(drag_offset, scroll.offset().y));
}
};
if let Some(id) = state.parent_id {
cx.notify(id);
} }
} ScrollbarAxis::Vertical => {
} else { scroll.set_offset(point(scroll.offset().x, drag_offset));
state.drag.set(None); }
} };
});
let state = self.state.clone();
window.on_mouse_event(move |_event: &MouseUpEvent, phase, _, cx| {
if phase.bubble() {
state.drag.take();
if let Some(id) = state.parent_id { if let Some(id) = state.parent_id {
cx.notify(id); cx.notify(id);
} }
} }
}); } else {
}, state.drag.set(None);
) }
});
let state = self.state.clone();
window.on_mouse_event(move |_event: &MouseUpEvent, phase, _, cx| {
if phase.bubble() {
state.drag.take();
if let Some(id) = state.parent_id {
cx.notify(id);
}
}
});
})
} }
} }