chore: Upgrade to GPUI3 (#6)
* wip: gpui3 * wip: gpui3 * chore: fix clippy
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use gpui::{
|
||||
px, relative, Axis, Bounds, ContentMask, Corners, Edges, Element, ElementId, EntityId,
|
||||
px, relative, App, Axis, Bounds, ContentMask, Corners, Edges, Element, ElementId, EntityId,
|
||||
GlobalElementId, Hitbox, Hsla, IntoElement, IsZero as _, LayoutId, PaintQuad, Pixels, Point,
|
||||
Position, ScrollHandle, ScrollWheelEvent, Size, Style, WindowContext,
|
||||
Position, ScrollHandle, ScrollWheelEvent, Size, Style, Window,
|
||||
};
|
||||
|
||||
use crate::AxisExt;
|
||||
@@ -56,9 +56,9 @@ impl Element for ScrollableMask {
|
||||
fn request_layout(
|
||||
&mut self,
|
||||
_: Option<&GlobalElementId>,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> (LayoutId, Self::RequestLayoutState) {
|
||||
// Set the layout style relative to the table view to get same size.
|
||||
let style = Style {
|
||||
position: Position::Absolute,
|
||||
flex_grow: 1.0,
|
||||
@@ -70,7 +70,7 @@ impl Element for ScrollableMask {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
(cx.request_layout(style, None), ())
|
||||
(window.request_layout(style, None, cx), ())
|
||||
}
|
||||
|
||||
fn prepaint(
|
||||
@@ -78,7 +78,8 @@ impl Element for ScrollableMask {
|
||||
_: Option<&GlobalElementId>,
|
||||
bounds: Bounds<Pixels>,
|
||||
_: &mut Self::RequestLayoutState,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
_: &mut App,
|
||||
) -> Self::PrepaintState {
|
||||
// Move y to bounds height to cover the parent view.
|
||||
let cover_bounds = Bounds {
|
||||
@@ -89,7 +90,7 @@ impl Element for ScrollableMask {
|
||||
size: bounds.size,
|
||||
};
|
||||
|
||||
cx.insert_hitbox(cover_bounds, false)
|
||||
window.insert_hitbox(cover_bounds, false)
|
||||
}
|
||||
|
||||
fn paint(
|
||||
@@ -98,14 +99,15 @@ impl Element for ScrollableMask {
|
||||
_: Bounds<Pixels>,
|
||||
_: &mut Self::RequestLayoutState,
|
||||
hitbox: &mut Self::PrepaintState,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
_: &mut App,
|
||||
) {
|
||||
let line_height = cx.line_height();
|
||||
let line_height = window.line_height();
|
||||
let bounds = hitbox.bounds;
|
||||
|
||||
cx.with_content_mask(Some(ContentMask { bounds }), |cx| {
|
||||
window.with_content_mask(Some(ContentMask { bounds }), |window| {
|
||||
if let Some(color) = self.debug {
|
||||
cx.paint_quad(PaintQuad {
|
||||
window.paint_quad(PaintQuad {
|
||||
bounds,
|
||||
border_widths: Edges::all(px(1.0)),
|
||||
border_color: color,
|
||||
@@ -114,16 +116,19 @@ impl Element for ScrollableMask {
|
||||
});
|
||||
}
|
||||
|
||||
cx.on_mouse_event({
|
||||
window.on_mouse_event({
|
||||
let view_id = self.view_id;
|
||||
let is_horizontal = self.axis.is_horizontal();
|
||||
let scroll_handle = self.scroll_handle.clone();
|
||||
let hitbox = hitbox.clone();
|
||||
let mouse_position = cx.mouse_position();
|
||||
let mouse_position = window.mouse_position();
|
||||
let last_offset = scroll_handle.offset();
|
||||
|
||||
move |event: &ScrollWheelEvent, phase, cx| {
|
||||
if bounds.contains(&mouse_position) && phase.bubble() && hitbox.is_hovered(cx) {
|
||||
move |event: &ScrollWheelEvent, phase, window, cx| {
|
||||
if bounds.contains(&mouse_position)
|
||||
&& phase.bubble()
|
||||
&& hitbox.is_hovered(window)
|
||||
{
|
||||
let mut offset = scroll_handle.offset();
|
||||
let mut delta = event.delta.pixel_delta(line_height);
|
||||
|
||||
@@ -146,7 +151,7 @@ impl Element for ScrollableMask {
|
||||
|
||||
if last_offset != offset {
|
||||
scroll_handle.set_offset(offset);
|
||||
cx.notify(Some(view_id));
|
||||
cx.notify(view_id);
|
||||
cx.stop_propagation();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user