scrollbar: Use paint_layer for scrollbar paint. (#448)
And increase scrollbar thumb color in normal mode. But, it looks like no difference for performance.
This commit is contained in:
parent
5468d034da
commit
9d476f9517
1 changed files with 279 additions and 288 deletions
|
|
@ -314,12 +314,9 @@ impl Element for Scrollbar {
|
||||||
let hitbox_bounds = hitbox.bounds;
|
let hitbox_bounds = hitbox.bounds;
|
||||||
let mut has_both = self.axis.is_both();
|
let mut has_both = self.axis.is_both();
|
||||||
|
|
||||||
cx.with_content_mask(
|
|
||||||
Some(ContentMask {
|
|
||||||
bounds: hitbox_bounds,
|
|
||||||
}),
|
|
||||||
|cx| {
|
|
||||||
for axis in self.axis.all().into_iter() {
|
for axis in self.axis.all().into_iter() {
|
||||||
|
const NORMAL_OPACITY: f32 = 0.6;
|
||||||
|
|
||||||
let is_vertical = axis.is_vertical();
|
let is_vertical = axis.is_vertical();
|
||||||
let (scroll_area_size, container_size, scroll_position) = if is_vertical {
|
let (scroll_area_size, container_size, scroll_position) = if is_vertical {
|
||||||
(
|
(
|
||||||
|
|
@ -348,10 +345,8 @@ impl Element for Scrollbar {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NORMAL_OPACITY: f32 = 0.35;
|
let thumb_length =
|
||||||
|
(container_size / scroll_area_size * container_size).max(px(MIN_THUMB_SIZE));
|
||||||
let thumb_length = (container_size / scroll_area_size * container_size)
|
|
||||||
.max(px(MIN_THUMB_SIZE));
|
|
||||||
let thumb_start = -(scroll_position / (scroll_area_size - container_size)
|
let thumb_start = -(scroll_position / (scroll_area_size - container_size)
|
||||||
* (container_size - margin_end - thumb_length));
|
* (container_size - margin_end - thumb_length));
|
||||||
let thumb_end = (thumb_start + thumb_length).min(container_size - margin_end);
|
let thumb_end = (thumb_start + thumb_length).min(container_size - margin_end);
|
||||||
|
|
@ -383,9 +378,8 @@ impl Element for Scrollbar {
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
let (thumb_bg, bar_bg, bar_border, inset, radius) = if state.get().dragged_axis
|
let (thumb_bg, bar_bg, bar_border, inset, radius) =
|
||||||
== Some(axis)
|
if state.get().dragged_axis == Some(axis) {
|
||||||
{
|
|
||||||
(
|
(
|
||||||
cx.theme().scrollbar_thumb,
|
cx.theme().scrollbar_thumb,
|
||||||
cx.theme().scrollbar,
|
cx.theme().scrollbar,
|
||||||
|
|
@ -455,6 +449,7 @@ impl Element for Scrollbar {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cx.paint_layer(hitbox_bounds, |cx| {
|
||||||
cx.paint_quad(fill(bounds, bar_bg));
|
cx.paint_quad(fill(bounds, bar_bg));
|
||||||
|
|
||||||
cx.paint_quad(PaintQuad {
|
cx.paint_quad(PaintQuad {
|
||||||
|
|
@ -480,6 +475,7 @@ impl Element for Scrollbar {
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.paint_quad(fill(thumb_bounds, thumb_bg).corner_radii(radius));
|
cx.paint_quad(fill(thumb_bounds, thumb_bg).corner_radii(radius));
|
||||||
|
});
|
||||||
|
|
||||||
cx.on_mouse_event({
|
cx.on_mouse_event({
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
|
|
@ -489,10 +485,11 @@ impl Element for Scrollbar {
|
||||||
move |event: &ScrollWheelEvent, phase, cx| {
|
move |event: &ScrollWheelEvent, phase, cx| {
|
||||||
if phase.bubble() && hitbox_bounds.contains(&event.position) {
|
if phase.bubble() && hitbox_bounds.contains(&event.position) {
|
||||||
if scroll_handle.offset() != state.get().last_scroll_offset {
|
if scroll_handle.offset() != state.get().last_scroll_offset {
|
||||||
state.set(state.get().with_last_scroll(
|
state.set(
|
||||||
scroll_handle.offset(),
|
state
|
||||||
Some(Instant::now()),
|
.get()
|
||||||
));
|
.with_last_scroll(scroll_handle.offset(), Some(Instant::now())),
|
||||||
|
);
|
||||||
cx.notify(Some(view_id));
|
cx.notify(Some(view_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -529,15 +526,11 @@ impl Element for Scrollbar {
|
||||||
.min(1.);
|
.min(1.);
|
||||||
|
|
||||||
if is_vertical {
|
if is_vertical {
|
||||||
scroll_handle.set_offset(point(
|
scroll_handle
|
||||||
offset.x,
|
.set_offset(point(offset.x, -scroll_area_size * percentage));
|
||||||
-scroll_area_size * percentage,
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
scroll_handle.set_offset(point(
|
scroll_handle
|
||||||
-scroll_area_size * percentage,
|
.set_offset(point(-scroll_area_size * percentage, offset.y));
|
||||||
offset.y,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -623,7 +616,5 @@ impl Element for Scrollbar {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue