Checkpoint

This commit is contained in:
Nathan Sobo 2023-09-08 16:08:31 -06:00
parent 362b1a44be
commit ebf8b32811
49 changed files with 491 additions and 627 deletions

View File

@ -2434,14 +2434,14 @@ fn render_tree_branch(
let cap_height = row_style.cap_height(font_cache); let cap_height = row_style.cap_height(font_cache);
let baseline_offset = row_style.baseline_offset(font_cache) + (size.y() - line_height) / 2.; let baseline_offset = row_style.baseline_offset(font_cache) + (size.y() - line_height) / 2.;
Canvas::new(move |scene, bounds, _, _, _| { Canvas::new(move |bounds, _, _, cx| {
scene.paint_layer(None, |scene| { cx.paint_layer(None, |cx| {
let start_x = bounds.min_x() + (bounds.width() / 2.) - (branch_style.width / 2.); let start_x = bounds.min_x() + (bounds.width() / 2.) - (branch_style.width / 2.);
let end_x = bounds.max_x(); let end_x = bounds.max_x();
let start_y = bounds.min_y(); let start_y = bounds.min_y();
let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.); let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.);
scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds: RectF::from_points( bounds: RectF::from_points(
vec2f(start_x, start_y), vec2f(start_x, start_y),
vec2f( vec2f(
@ -2453,7 +2453,7 @@ fn render_tree_branch(
border: gpui::Border::default(), border: gpui::Border::default(),
corner_radii: (0.).into(), corner_radii: (0.).into(),
}); });
scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds: RectF::from_points( bounds: RectF::from_points(
vec2f(start_x, end_y), vec2f(start_x, end_y),
vec2f(end_x, end_y + branch_style.width), vec2f(end_x, end_y + branch_style.width),

View File

@ -13,8 +13,8 @@ use gpui::{
geometry::{rect::RectF, vector::vec2f, PathBuilder}, geometry::{rect::RectF, vector::vec2f, PathBuilder},
json::{self, ToJson}, json::{self, ToJson},
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AppContext, Entity, ImageData, LayoutContext, ModelHandle, PaintContext, SceneBuilder, AppContext, Entity, ImageData, LayoutContext, ModelHandle, PaintContext, Subscription, View,
Subscription, View, ViewContext, ViewHandle, WeakViewHandle, ViewContext, ViewHandle, WeakViewHandle,
}; };
use picker::PickerEvent; use picker::PickerEvent;
use project::{Project, RepositoryEntry}; use project::{Project, RepositoryEntry};
@ -1172,12 +1172,11 @@ impl Element<CollabTitlebarItem> for AvatarRibbon {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
_: RectF, _: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
_: &mut CollabTitlebarItem, _: &mut CollabTitlebarItem,
_: &mut PaintContext<CollabTitlebarItem>, cx: &mut PaintContext<CollabTitlebarItem>,
) -> Self::PaintState { ) -> Self::PaintState {
let mut path = PathBuilder::new(); let mut path = PathBuilder::new();
path.reset(bounds.lower_left()); path.reset(bounds.lower_left());
@ -1188,7 +1187,7 @@ impl Element<CollabTitlebarItem> for AvatarRibbon {
path.line_to(bounds.upper_right() - vec2f(bounds.height(), 0.)); path.line_to(bounds.upper_right() - vec2f(bounds.height(), 0.));
path.curve_to(bounds.lower_right(), bounds.upper_right()); path.curve_to(bounds.lower_right(), bounds.upper_right());
path.line_to(bounds.lower_left()); path.line_to(bounds.lower_left());
scene.push_path(path.build(self.color, None)); cx.scene().push_path(path.build(self.color, None));
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -7,7 +7,7 @@ use gpui::{
}, },
json::ToJson, json::ToJson,
serde_json::{self, json}, serde_json::{self, json},
AnyElement, Axis, Element, LayoutContext, PaintContext, SceneBuilder, View, ViewContext, AnyElement, Axis, Element, LayoutContext, PaintContext, View, ViewContext,
}; };
pub(crate) struct FacePile<V: View> { pub(crate) struct FacePile<V: View> {
@ -53,7 +53,6 @@ impl<V: View> Element<V> for FacePile<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_layout: &mut Self::LayoutState, _layout: &mut Self::LayoutState,
@ -69,9 +68,10 @@ impl<V: View> Element<V> for FacePile<V> {
let size = face.size(); let size = face.size();
origin_x -= size.x(); origin_x -= size.x();
let origin_y = origin_y + (bounds.height() - size.y()) / 2.0; let origin_y = origin_y + (bounds.height() - size.y()) / 2.0;
scene.paint_layer(None, |scene| {
face.paint(scene, vec2f(origin_x, origin_y), visible_bounds, view, cx); cx.scene().push_layer(None);
}); face.paint(vec2f(origin_x, origin_y), visible_bounds, view, cx);
cx.scene().pop_layer();
origin_x += self.overlap; origin_x += self.overlap;
} }

View File

@ -33,7 +33,7 @@ use gpui::{
platform::{CursorStyle, Modifiers, MouseButton, MouseButtonEvent, MouseMovedEvent}, platform::{CursorStyle, Modifiers, MouseButton, MouseButtonEvent, MouseMovedEvent},
text_layout::{self, Line, RunStyle, TextLayoutCache}, text_layout::{self, Line, RunStyle, TextLayoutCache},
AnyElement, Axis, CursorRegion, Element, EventContext, FontCache, LayoutContext, MouseRegion, AnyElement, Axis, CursorRegion, Element, EventContext, FontCache, LayoutContext, MouseRegion,
PaintContext, Quad, SceneBuilder, SizeConstraint, ViewContext, WindowContext, PaintContext, Quad, SizeConstraint, ViewContext, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use json::json; use json::json;
@ -131,7 +131,6 @@ impl EditorElement {
} }
fn attach_mouse_handlers( fn attach_mouse_handlers(
scene: &mut SceneBuilder,
position_map: &Arc<PositionMap>, position_map: &Arc<PositionMap>,
has_popovers: bool, has_popovers: bool,
visible_bounds: RectF, visible_bounds: RectF,
@ -141,12 +140,9 @@ impl EditorElement {
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) { ) {
enum EditorElementMouseHandlers {} enum EditorElementMouseHandlers {}
scene.push_mouse_region( let view_id = cx.view_id();
MouseRegion::new::<EditorElementMouseHandlers>( cx.scene().push_mouse_region(
cx.view_id(), MouseRegion::new::<EditorElementMouseHandlers>(view_id, view_id, visible_bounds)
cx.view_id(),
visible_bounds,
)
.on_down(MouseButton::Left, { .on_down(MouseButton::Left, {
let position_map = position_map.clone(); let position_map = position_map.clone();
move |event, editor, cx| { move |event, editor, cx| {
@ -249,16 +245,19 @@ impl EditorElement {
); );
enum GutterHandlers {} enum GutterHandlers {}
scene.push_mouse_region( let view_id = cx.view_id();
MouseRegion::new::<GutterHandlers>(cx.view_id(), cx.view_id() + 1, gutter_bounds) let region_id = cx.view_id() + 1;
.on_hover(|hover, editor: &mut Editor, cx| { cx.scene().push_mouse_region(
MouseRegion::new::<GutterHandlers>(view_id, region_id, gutter_bounds).on_hover(
|hover, editor: &mut Editor, cx| {
editor.gutter_hover( editor.gutter_hover(
&GutterHover { &GutterHover {
hovered: hover.started, hovered: hover.started,
}, },
cx, cx,
); );
}), },
),
) )
} }
@ -528,21 +527,21 @@ impl EditorElement {
fn paint_background( fn paint_background(
&self, &self,
scene: &mut SceneBuilder,
gutter_bounds: RectF, gutter_bounds: RectF,
text_bounds: RectF, text_bounds: RectF,
layout: &LayoutState, layout: &LayoutState,
cx: &mut ViewContext<Editor>,
) { ) {
let bounds = gutter_bounds.union_rect(text_bounds); let bounds = gutter_bounds.union_rect(text_bounds);
let scroll_top = let scroll_top =
layout.position_map.snapshot.scroll_position().y() * layout.position_map.line_height; layout.position_map.snapshot.scroll_position().y() * layout.position_map.line_height;
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: gutter_bounds, bounds: gutter_bounds,
background: Some(self.style.gutter_background), background: Some(self.style.gutter_background),
border: Border::new(0., Color::transparent_black()).into(), border: Border::new(0., Color::transparent_black()).into(),
corner_radii: Default::default(), corner_radii: Default::default(),
}); });
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: text_bounds, bounds: text_bounds,
background: Some(self.style.background), background: Some(self.style.background),
border: Border::new(0., Color::transparent_black()).into(), border: Border::new(0., Color::transparent_black()).into(),
@ -570,7 +569,7 @@ impl EditorElement {
bounds.width(), bounds.width(),
layout.position_map.line_height * (end_row - start_row + 1) as f32, layout.position_map.line_height * (end_row - start_row + 1) as f32,
); );
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(origin, size), bounds: RectF::new(origin, size),
background: Some(self.style.active_line_background), background: Some(self.style.active_line_background),
border: Border::default().into(), border: Border::default().into(),
@ -590,7 +589,7 @@ impl EditorElement {
bounds.width(), bounds.width(),
layout.position_map.line_height * highlighted_rows.len() as f32, layout.position_map.line_height * highlighted_rows.len() as f32,
); );
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(origin, size), bounds: RectF::new(origin, size),
background: Some(self.style.highlighted_line_background), background: Some(self.style.highlighted_line_background),
border: Border::default().into(), border: Border::default().into(),
@ -617,7 +616,7 @@ impl EditorElement {
} else { } else {
self.style.wrap_guide self.style.wrap_guide
}; };
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new( bounds: RectF::new(
vec2f(x, text_bounds.origin_y()), vec2f(x, text_bounds.origin_y()),
vec2f(1., text_bounds.height()), vec2f(1., text_bounds.height()),
@ -632,7 +631,6 @@ impl EditorElement {
fn paint_gutter( fn paint_gutter(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut LayoutState, layout: &mut LayoutState,
@ -650,7 +648,7 @@ impl EditorElement {
); );
if show_gutter { if show_gutter {
Self::paint_diff_hunks(scene, bounds, layout, cx); Self::paint_diff_hunks(bounds, layout, cx);
} }
for (ix, line) in layout.line_number_layouts.iter().enumerate() { for (ix, line) in layout.line_number_layouts.iter().enumerate() {
@ -661,7 +659,7 @@ impl EditorElement {
ix as f32 * line_height - (scroll_top % line_height), ix as f32 * line_height - (scroll_top % line_height),
); );
line.paint(scene, line_origin, visible_bounds, line_height, cx); line.paint(line_origin, visible_bounds, line_height, cx);
} }
} }
@ -678,7 +676,7 @@ impl EditorElement {
let indicator_origin = bounds.origin() + position + centering_offset; let indicator_origin = bounds.origin() + position + centering_offset;
indicator.paint(scene, indicator_origin, visible_bounds, editor, cx); indicator.paint(indicator_origin, visible_bounds, editor, cx);
} }
} }
@ -687,22 +685,11 @@ impl EditorElement {
let mut y = *row as f32 * line_height - scroll_top; let mut y = *row as f32 * line_height - scroll_top;
x += ((layout.gutter_padding + layout.gutter_margin) - indicator.size().x()) / 2.; x += ((layout.gutter_padding + layout.gutter_margin) - indicator.size().x()) / 2.;
y += (line_height - indicator.size().y()) / 2.; y += (line_height - indicator.size().y()) / 2.;
indicator.paint( indicator.paint(bounds.origin() + vec2f(x, y), visible_bounds, editor, cx);
scene,
bounds.origin() + vec2f(x, y),
visible_bounds,
editor,
cx,
);
} }
} }
fn paint_diff_hunks( fn paint_diff_hunks(bounds: RectF, layout: &mut LayoutState, cx: &mut ViewContext<Editor>) {
scene: &mut SceneBuilder,
bounds: RectF,
layout: &mut LayoutState,
cx: &mut ViewContext<Editor>,
) {
let diff_style = &theme::current(cx).editor.diff.clone(); let diff_style = &theme::current(cx).editor.diff.clone();
let line_height = layout.position_map.line_height; let line_height = layout.position_map.line_height;
@ -721,7 +708,7 @@ impl EditorElement {
let highlight_size = vec2f(width * 2., end_y - start_y); let highlight_size = vec2f(width * 2., end_y - start_y);
let highlight_bounds = RectF::new(highlight_origin, highlight_size); let highlight_bounds = RectF::new(highlight_origin, highlight_size);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: highlight_bounds, bounds: highlight_bounds,
background: Some(diff_style.modified), background: Some(diff_style.modified),
border: Border::new(0., Color::transparent_black()).into(), border: Border::new(0., Color::transparent_black()).into(),
@ -754,7 +741,7 @@ impl EditorElement {
let highlight_size = vec2f(width * 2., end_y - start_y); let highlight_size = vec2f(width * 2., end_y - start_y);
let highlight_bounds = RectF::new(highlight_origin, highlight_size); let highlight_bounds = RectF::new(highlight_origin, highlight_size);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: highlight_bounds, bounds: highlight_bounds,
background: Some(diff_style.deleted), background: Some(diff_style.deleted),
border: Border::new(0., Color::transparent_black()).into(), border: Border::new(0., Color::transparent_black()).into(),
@ -776,7 +763,7 @@ impl EditorElement {
let highlight_size = vec2f(width * 2., end_y - start_y); let highlight_size = vec2f(width * 2., end_y - start_y);
let highlight_bounds = RectF::new(highlight_origin, highlight_size); let highlight_bounds = RectF::new(highlight_origin, highlight_size);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: highlight_bounds, bounds: highlight_bounds,
background: Some(color), background: Some(color),
border: Border::new(0., Color::transparent_black()).into(), border: Border::new(0., Color::transparent_black()).into(),
@ -787,7 +774,6 @@ impl EditorElement {
fn paint_text( fn paint_text(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut LayoutState, layout: &mut LayoutState,
@ -804,9 +790,9 @@ impl EditorElement {
let line_end_overshoot = 0.15 * layout.position_map.line_height; let line_end_overshoot = 0.15 * layout.position_map.line_height;
let whitespace_setting = editor.buffer.read(cx).settings_at(0, cx).show_whitespaces; let whitespace_setting = editor.buffer.read(cx).settings_at(0, cx).show_whitespaces;
scene.push_layer(Some(bounds)); cx.scene().push_layer(Some(bounds));
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds, bounds,
style: if !editor.link_go_to_definition_state.definitions.is_empty() { style: if !editor.link_go_to_definition_state.definitions.is_empty() {
CursorStyle::PointingHand CursorStyle::PointingHand
@ -819,7 +805,6 @@ impl EditorElement {
self.style.folds.ellipses.corner_radius_factor * layout.position_map.line_height; self.style.folds.ellipses.corner_radius_factor * layout.position_map.line_height;
for (id, range, color) in layout.fold_ranges.iter() { for (id, range, color) in layout.fold_ranges.iter() {
self.paint_highlighted_range( self.paint_highlighted_range(
scene,
range.clone(), range.clone(),
*color, *color,
fold_corner_radius, fold_corner_radius,
@ -829,6 +814,7 @@ impl EditorElement {
scroll_top, scroll_top,
scroll_left, scroll_left,
bounds, bounds,
cx,
); );
for bound in range_to_bounds( for bound in range_to_bounds(
@ -840,7 +826,7 @@ impl EditorElement {
line_end_overshoot, line_end_overshoot,
&layout.position_map, &layout.position_map,
) { ) {
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds: bound, bounds: bound,
style: CursorStyle::PointingHand, style: CursorStyle::PointingHand,
}); });
@ -851,8 +837,9 @@ impl EditorElement {
.to_point(&layout.position_map.snapshot.display_snapshot) .to_point(&layout.position_map.snapshot.display_snapshot)
.row; .row;
scene.push_mouse_region( let view_id = cx.view_id();
MouseRegion::new::<FoldMarkers>(cx.view_id(), *id as usize, bound) cx.scene().push_mouse_region(
MouseRegion::new::<FoldMarkers>(view_id, *id as usize, bound)
.on_click(MouseButton::Left, move |_, editor: &mut Editor, cx| { .on_click(MouseButton::Left, move |_, editor: &mut Editor, cx| {
editor.unfold_at(&UnfoldAt { buffer_row }, cx) editor.unfold_at(&UnfoldAt { buffer_row }, cx)
}) })
@ -864,7 +851,6 @@ impl EditorElement {
for (range, color) in &layout.highlighted_ranges { for (range, color) in &layout.highlighted_ranges {
self.paint_highlighted_range( self.paint_highlighted_range(
scene,
range.clone(), range.clone(),
*color, *color,
0., 0.,
@ -874,6 +860,7 @@ impl EditorElement {
scroll_top, scroll_top,
scroll_left, scroll_left,
bounds, bounds,
cx,
); );
} }
@ -891,7 +878,6 @@ impl EditorElement {
for selection in selections { for selection in selections {
self.paint_highlighted_range( self.paint_highlighted_range(
scene,
selection.range.clone(), selection.range.clone(),
selection_style.selection, selection_style.selection,
corner_radius, corner_radius,
@ -901,6 +887,7 @@ impl EditorElement {
scroll_top, scroll_top,
scroll_left, scroll_left,
bounds, bounds,
cx,
); );
if selection.is_local && !selection.range.is_empty() { if selection.is_local && !selection.range.is_empty() {
@ -980,7 +967,6 @@ impl EditorElement {
layout, layout,
row, row,
scroll_top, scroll_top,
scene,
content_origin, content_origin,
scroll_left, scroll_left,
visible_text_bounds, visible_text_bounds,
@ -992,14 +978,14 @@ impl EditorElement {
} }
} }
scene.paint_layer(Some(bounds), |scene| { cx.scene().push_layer(Some(bounds));
for cursor in cursors { for cursor in cursors {
cursor.paint(scene, content_origin, cx); cursor.paint(content_origin, cx);
} }
}); cx.scene().pop_layer();
if let Some((position, context_menu)) = layout.context_menu.as_mut() { if let Some((position, context_menu)) = layout.context_menu.as_mut() {
scene.push_stacking_context(None, None); cx.scene().push_stacking_context(None, None);
let cursor_row_layout = let cursor_row_layout =
&layout.position_map.line_layouts[(position.row() - start_row) as usize].line; &layout.position_map.line_layouts[(position.row() - start_row) as usize].line;
let x = cursor_row_layout.x_for_index(position.column() as usize) - scroll_left; let x = cursor_row_layout.x_for_index(position.column() as usize) - scroll_left;
@ -1019,18 +1005,17 @@ impl EditorElement {
} }
context_menu.paint( context_menu.paint(
scene,
list_origin, list_origin,
RectF::from_points(Vector2F::zero(), vec2f(f32::MAX, f32::MAX)), // Let content bleed outside of editor RectF::from_points(Vector2F::zero(), vec2f(f32::MAX, f32::MAX)), // Let content bleed outside of editor
editor, editor,
cx, cx,
); );
scene.pop_stacking_context(); cx.scene().pop_stacking_context();
} }
if let Some((position, hover_popovers)) = layout.hover_popovers.as_mut() { if let Some((position, hover_popovers)) = layout.hover_popovers.as_mut() {
scene.push_stacking_context(None, None); cx.scene().push_stacking_context(None, None);
// This is safe because we check on layout whether the required row is available // This is safe because we check on layout whether the required row is available
let hovered_row_layout = let hovered_row_layout =
@ -1061,7 +1046,6 @@ impl EditorElement {
} }
hover_popover.paint( hover_popover.paint(
scene,
popover_origin, popover_origin,
RectF::from_points(Vector2F::zero(), vec2f(f32::MAX, f32::MAX)), // Let content bleed outside of editor RectF::from_points(Vector2F::zero(), vec2f(f32::MAX, f32::MAX)), // Let content bleed outside of editor
editor, editor,
@ -1083,7 +1067,6 @@ impl EditorElement {
} }
hover_popover.paint( hover_popover.paint(
scene,
popover_origin, popover_origin,
RectF::from_points(Vector2F::zero(), vec2f(f32::MAX, f32::MAX)), // Let content bleed outside of editor RectF::from_points(Vector2F::zero(), vec2f(f32::MAX, f32::MAX)), // Let content bleed outside of editor
editor, editor,
@ -1094,10 +1077,10 @@ impl EditorElement {
} }
} }
scene.pop_stacking_context(); cx.scene().pop_stacking_context();
} }
scene.pop_layer(); cx.scene().pop_layer();
} }
fn scrollbar_left(&self, bounds: &RectF) -> f32 { fn scrollbar_left(&self, bounds: &RectF) -> f32 {
@ -1106,11 +1089,10 @@ impl EditorElement {
fn paint_scrollbar( fn paint_scrollbar(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
layout: &mut LayoutState, layout: &mut LayoutState,
cx: &mut ViewContext<Editor>,
editor: &Editor, editor: &Editor,
cx: &mut ViewContext<Editor>,
) { ) {
enum ScrollbarMouseHandlers {} enum ScrollbarMouseHandlers {}
if layout.mode != EditorMode::Full { if layout.mode != EditorMode::Full {
@ -1147,7 +1129,7 @@ impl EditorElement {
let thumb_bounds = RectF::from_points(vec2f(left, thumb_top), vec2f(right, thumb_bottom)); let thumb_bounds = RectF::from_points(vec2f(left, thumb_top), vec2f(right, thumb_bottom));
if layout.show_scrollbars { if layout.show_scrollbars {
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: track_bounds, bounds: track_bounds,
border: style.track.border.into(), border: style.track.border.into(),
background: style.track.background_color, background: style.track.background_color,
@ -1177,7 +1159,7 @@ impl EditorElement {
} }
let bounds = RectF::from_points(vec2f(left, start_y), vec2f(right, end_y)); let bounds = RectF::from_points(vec2f(left, start_y), vec2f(right, end_y));
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds, bounds,
background: Some(color), background: Some(color),
border: border.into(), border: border.into(),
@ -1237,7 +1219,7 @@ impl EditorElement {
left: true, left: true,
}; };
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds, bounds,
background: Some(color), background: Some(color),
border: border.into(), border: border.into(),
@ -1246,7 +1228,7 @@ impl EditorElement {
} }
} }
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: thumb_bounds, bounds: thumb_bounds,
border: style.thumb.border.into(), border: style.thumb.border.into(),
background: style.thumb.background_color, background: style.thumb.background_color,
@ -1254,12 +1236,13 @@ impl EditorElement {
}); });
} }
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds: track_bounds, bounds: track_bounds,
style: CursorStyle::Arrow, style: CursorStyle::Arrow,
}); });
scene.push_mouse_region( let region_id = cx.view_id();
MouseRegion::new::<ScrollbarMouseHandlers>(cx.view_id(), cx.view_id(), track_bounds) cx.scene().push_mouse_region(
MouseRegion::new::<ScrollbarMouseHandlers>(region_id, region_id, track_bounds)
.on_move(move |event, editor: &mut Editor, cx| { .on_move(move |event, editor: &mut Editor, cx| {
if event.pressed_button.is_none() { if event.pressed_button.is_none() {
editor.scroll_manager.show_scrollbar(cx); editor.scroll_manager.show_scrollbar(cx);
@ -1305,7 +1288,6 @@ impl EditorElement {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn paint_highlighted_range( fn paint_highlighted_range(
&self, &self,
scene: &mut SceneBuilder,
range: Range<DisplayPoint>, range: Range<DisplayPoint>,
color: Color, color: Color,
corner_radius: f32, corner_radius: f32,
@ -1315,6 +1297,7 @@ impl EditorElement {
scroll_top: f32, scroll_top: f32,
scroll_left: f32, scroll_left: f32,
bounds: RectF, bounds: RectF,
cx: &mut ViewContext<Editor>,
) { ) {
let start_row = layout.visible_display_row_range.start; let start_row = layout.visible_display_row_range.start;
let end_row = layout.visible_display_row_range.end; let end_row = layout.visible_display_row_range.end;
@ -1358,13 +1341,12 @@ impl EditorElement {
.collect(), .collect(),
}; };
highlighted_range.paint(bounds, scene); highlighted_range.paint(bounds, cx);
} }
} }
fn paint_blocks( fn paint_blocks(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut LayoutState, layout: &mut LayoutState,
@ -1384,9 +1366,7 @@ impl EditorElement {
if !matches!(block.style, BlockStyle::Sticky) { if !matches!(block.style, BlockStyle::Sticky) {
origin += vec2f(-scroll_left, 0.); origin += vec2f(-scroll_left, 0.);
} }
block block.element.paint(origin, visible_bounds, editor, cx);
.element
.paint(scene, origin, visible_bounds, editor, cx);
} }
} }
@ -2022,7 +2002,6 @@ impl LineWithInvisibles {
layout: &LayoutState, layout: &LayoutState,
row: u32, row: u32,
scroll_top: f32, scroll_top: f32,
scene: &mut SceneBuilder,
content_origin: Vector2F, content_origin: Vector2F,
scroll_left: f32, scroll_left: f32,
visible_text_bounds: RectF, visible_text_bounds: RectF,
@ -2035,7 +2014,6 @@ impl LineWithInvisibles {
let line_y = row as f32 * line_height - scroll_top; let line_y = row as f32 * line_height - scroll_top;
self.line.paint( self.line.paint(
scene,
content_origin + vec2f(-scroll_left, line_y), content_origin + vec2f(-scroll_left, line_y),
visible_text_bounds, visible_text_bounds,
line_height, line_height,
@ -2049,7 +2027,6 @@ impl LineWithInvisibles {
scroll_left, scroll_left,
line_y, line_y,
row, row,
scene,
visible_bounds, visible_bounds,
line_height, line_height,
whitespace_setting, whitespace_setting,
@ -2065,7 +2042,6 @@ impl LineWithInvisibles {
scroll_left: f32, scroll_left: f32,
line_y: f32, line_y: f32,
row: u32, row: u32,
scene: &mut SceneBuilder,
visible_bounds: RectF, visible_bounds: RectF,
line_height: f32, line_height: f32,
whitespace_setting: ShowWhitespaceSetting, whitespace_setting: ShowWhitespaceSetting,
@ -2097,7 +2073,7 @@ impl LineWithInvisibles {
continue; continue;
} }
} }
invisible_symbol.paint(scene, origin, visible_bounds, line_height, cx); invisible_symbol.paint(origin, visible_bounds, line_height, cx);
} }
} }
} }
@ -2590,7 +2566,6 @@ impl Element<Editor> for EditorElement {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut Self::LayoutState, layout: &mut Self::LayoutState,
@ -2598,7 +2573,7 @@ impl Element<Editor> for EditorElement {
cx: &mut PaintContext<Editor>, cx: &mut PaintContext<Editor>,
) -> Self::PaintState { ) -> Self::PaintState {
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
scene.push_layer(Some(visible_bounds)); cx.scene().push_layer(Some(visible_bounds));
let gutter_bounds = RectF::new(bounds.origin(), layout.gutter_size); let gutter_bounds = RectF::new(bounds.origin(), layout.gutter_size);
let text_bounds = RectF::new( let text_bounds = RectF::new(
@ -2607,7 +2582,6 @@ impl Element<Editor> for EditorElement {
); );
Self::attach_mouse_handlers( Self::attach_mouse_handlers(
scene,
&layout.position_map, &layout.position_map,
layout.hover_popovers.is_some(), layout.hover_popovers.is_some(),
visible_bounds, visible_bounds,
@ -2617,20 +2591,19 @@ impl Element<Editor> for EditorElement {
cx, cx,
); );
self.paint_background(scene, gutter_bounds, text_bounds, layout); self.paint_background(gutter_bounds, text_bounds, layout, cx);
if layout.gutter_size.x() > 0. { if layout.gutter_size.x() > 0. {
self.paint_gutter(scene, gutter_bounds, visible_bounds, layout, editor, cx); self.paint_gutter(gutter_bounds, visible_bounds, layout, editor, cx);
} }
self.paint_text(scene, text_bounds, visible_bounds, layout, editor, cx); self.paint_text(text_bounds, visible_bounds, layout, editor, cx);
scene.push_layer(Some(bounds)); cx.scene().push_layer(Some(bounds));
if !layout.blocks.is_empty() { if !layout.blocks.is_empty() {
self.paint_blocks(scene, bounds, visible_bounds, layout, editor, cx); self.paint_blocks(bounds, visible_bounds, layout, editor, cx);
} }
self.paint_scrollbar(scene, bounds, layout, cx, &editor); self.paint_scrollbar(bounds, layout, &editor, cx);
scene.pop_layer(); cx.scene().pop_layer();
cx.scene().pop_layer();
scene.pop_layer();
} }
fn rect_for_text_range( fn rect_for_text_range(
@ -2873,7 +2846,7 @@ impl Cursor {
) )
} }
pub fn paint(&self, scene: &mut SceneBuilder, origin: Vector2F, cx: &mut WindowContext) { pub fn paint(&self, origin: Vector2F, cx: &mut WindowContext) {
let bounds = match self.shape { let bounds = match self.shape {
CursorShape::Bar => RectF::new(self.origin + origin, vec2f(2.0, self.line_height)), CursorShape::Bar => RectF::new(self.origin + origin, vec2f(2.0, self.line_height)),
CursorShape::Block | CursorShape::Hollow => RectF::new( CursorShape::Block | CursorShape::Hollow => RectF::new(
@ -2888,14 +2861,14 @@ impl Cursor {
//Draw background or border quad //Draw background or border quad
if matches!(self.shape, CursorShape::Hollow) { if matches!(self.shape, CursorShape::Hollow) {
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds, bounds,
background: None, background: None,
border: Border::all(1., self.color).into(), border: Border::all(1., self.color).into(),
corner_radii: Default::default(), corner_radii: Default::default(),
}); });
} else { } else {
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds, bounds,
background: Some(self.color), background: Some(self.color),
border: Default::default(), border: Default::default(),
@ -2904,7 +2877,7 @@ impl Cursor {
} }
if let Some(block_text) = &self.block_text { if let Some(block_text) = &self.block_text {
block_text.paint(scene, self.origin + origin, bounds, self.line_height, cx); block_text.paint(self.origin + origin, bounds, self.line_height, cx);
} }
} }
@ -2929,17 +2902,17 @@ pub struct HighlightedRangeLine {
} }
impl HighlightedRange { impl HighlightedRange {
pub fn paint(&self, bounds: RectF, scene: &mut SceneBuilder) { pub fn paint(&self, bounds: RectF, cx: &mut WindowContext) {
if self.lines.len() >= 2 && self.lines[0].start_x > self.lines[1].end_x { if self.lines.len() >= 2 && self.lines[0].start_x > self.lines[1].end_x {
self.paint_lines(self.start_y, &self.lines[0..1], bounds, scene); self.paint_lines(self.start_y, &self.lines[0..1], bounds, cx);
self.paint_lines( self.paint_lines(
self.start_y + self.line_height, self.start_y + self.line_height,
&self.lines[1..], &self.lines[1..],
bounds, bounds,
scene, cx,
); );
} else { } else {
self.paint_lines(self.start_y, &self.lines, bounds, scene); self.paint_lines(self.start_y, &self.lines, bounds, cx);
} }
} }
@ -2948,7 +2921,7 @@ impl HighlightedRange {
start_y: f32, start_y: f32,
lines: &[HighlightedRangeLine], lines: &[HighlightedRangeLine],
bounds: RectF, bounds: RectF,
scene: &mut SceneBuilder, cx: &mut WindowContext,
) { ) {
if lines.is_empty() { if lines.is_empty() {
return; return;
@ -3046,7 +3019,7 @@ impl HighlightedRange {
} }
path.line_to(first_top_right - top_curve_width); path.line_to(first_top_right - top_curve_width);
scene.push_path(path.build(self.color, Some(bounds))); cx.scene().push_path(path.build(self.color, Some(bounds)));
} }
} }
@ -3368,11 +3341,9 @@ mod tests {
); );
// Don't panic. // Don't panic.
let mut scene = SceneBuilder::new(1.0);
let bounds = RectF::new(Default::default(), size); let bounds = RectF::new(Default::default(), size);
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
element.paint( element.paint(
&mut scene,
bounds, bounds,
bounds, bounds,
&mut state, &mut state,

View File

@ -691,15 +691,15 @@ impl InfoPopover {
.with_highlights(rendered_content.highlights.clone()) .with_highlights(rendered_content.highlights.clone())
.with_custom_runs( .with_custom_runs(
rendered_content.region_ranges.clone(), rendered_content.region_ranges.clone(),
move |ix, bounds, scene, _| { move |ix, bounds, cx| {
region_id += 1; region_id += 1;
let region = regions[ix].clone(); let region = regions[ix].clone();
if let Some(url) = region.link_url { if let Some(url) = region.link_url {
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds, bounds,
style: CursorStyle::PointingHand, style: CursorStyle::PointingHand,
}); });
scene.push_mouse_region( cx.scene().push_mouse_region(
MouseRegion::new::<Self>(view_id, region_id, bounds) MouseRegion::new::<Self>(view_id, region_id, bounds)
.on_click::<Editor, _>( .on_click::<Editor, _>(
MouseButton::Left, MouseButton::Left,
@ -708,7 +708,7 @@ impl InfoPopover {
); );
} }
if region.code { if region.code {
scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds, bounds,
background: Some(code_span_background_color), background: Some(code_span_background_color),
border: Default::default(), border: Default::default(),

View File

@ -49,22 +49,21 @@ impl<V: View> gpui::Element<V> for CornersElement {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut gpui::SceneBuilder,
bounds: pathfinder_geometry::rect::RectF, bounds: pathfinder_geometry::rect::RectF,
_: pathfinder_geometry::rect::RectF, _: pathfinder_geometry::rect::RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
_: &mut V, _: &mut V,
_: &mut gpui::PaintContext<V>, cx: &mut gpui::PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds, bounds,
background: Some(Color::white()), background: Some(Color::white()),
..Default::default() ..Default::default()
}); });
scene.push_layer(None); cx.scene().push_layer(None);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(vec2f(100., 100.), vec2f(100., 100.)), bounds: RectF::new(vec2f(100., 100.), vec2f(100., 100.)),
background: Some(Color::red()), background: Some(Color::red()),
border: Default::default(), border: Default::default(),
@ -74,7 +73,7 @@ impl<V: View> gpui::Element<V> for CornersElement {
}, },
}); });
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(vec2f(200., 100.), vec2f(100., 100.)), bounds: RectF::new(vec2f(200., 100.), vec2f(100., 100.)),
background: Some(Color::green()), background: Some(Color::green()),
border: Default::default(), border: Default::default(),
@ -84,7 +83,7 @@ impl<V: View> gpui::Element<V> for CornersElement {
}, },
}); });
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(vec2f(100., 200.), vec2f(100., 100.)), bounds: RectF::new(vec2f(100., 200.), vec2f(100., 100.)),
background: Some(Color::blue()), background: Some(Color::blue()),
border: Default::default(), border: Default::default(),
@ -94,7 +93,7 @@ impl<V: View> gpui::Element<V> for CornersElement {
}, },
}); });
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(vec2f(200., 200.), vec2f(100., 100.)), bounds: RectF::new(vec2f(200., 200.), vec2f(100., 100.)),
background: Some(Color::yellow()), background: Some(Color::yellow()),
border: Default::default(), border: Default::default(),
@ -104,7 +103,7 @@ impl<V: View> gpui::Element<V> for CornersElement {
}, },
}); });
scene.push_shadow(Shadow { cx.scene().push_shadow(Shadow {
bounds: RectF::new(vec2f(400., 100.), vec2f(100., 100.)), bounds: RectF::new(vec2f(400., 100.), vec2f(100., 100.)),
corner_radii: gpui::scene::CornerRadii { corner_radii: gpui::scene::CornerRadii {
bottom_right: 20., bottom_right: 20.,
@ -114,8 +113,8 @@ impl<V: View> gpui::Element<V> for CornersElement {
color: Color::black(), color: Color::black(),
}); });
scene.push_layer(None); cx.scene().push_layer(None);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(vec2f(400., 100.), vec2f(100., 100.)), bounds: RectF::new(vec2f(400., 100.), vec2f(100., 100.)),
background: Some(Color::red()), background: Some(Color::red()),
border: Default::default(), border: Default::default(),
@ -125,8 +124,8 @@ impl<V: View> gpui::Element<V> for CornersElement {
}, },
}); });
scene.pop_layer(); cx.scene().pop_layer();
scene.pop_layer(); cx.scene().pop_layer();
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -62,12 +62,12 @@ impl gpui::View for TextView {
}, },
) )
.with_highlights(vec![(17..26, underline), (34..40, underline)]) .with_highlights(vec![(17..26, underline), (34..40, underline)])
.with_custom_runs(vec![(17..26), (34..40)], move |ix, bounds, scene, _| { .with_custom_runs(vec![(17..26), (34..40)], move |ix, bounds, cx| {
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds, bounds,
style: CursorStyle::PointingHand, style: CursorStyle::PointingHand,
}); });
scene.push_mouse_region( cx.scene().push_mouse_region(
MouseRegion::new::<Self>(view_id, ix, bounds).on_click::<Self, _>( MouseRegion::new::<Self>(view_id, ix, bounds).on_click::<Self, _>(
MouseButton::Left, MouseButton::Left,
move |_, _, _| { move |_, _, _| {

View File

@ -28,6 +28,7 @@ use collections::{hash_map::Entry, BTreeMap, HashMap, HashSet, VecDeque};
use derive_more::Deref; use derive_more::Deref;
pub use menu::*; pub use menu::*;
use parking_lot::Mutex; use parking_lot::Mutex;
use pathfinder_geometry::rect::RectF;
use platform::Event; use platform::Event;
use postage::oneshot; use postage::oneshot;
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
@ -3571,6 +3572,16 @@ impl<'a, 'b, 'c, V> PaintContext<'a, 'b, 'c, V> {
pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self { pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self {
Self { view_context } Self { view_context }
} }
pub fn paint_layer<F, R>(&mut self, clip_bounds: Option<RectF>, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
{
self.scene().push_layer(clip_bounds);
let result = f(self);
self.scene().pop_layer();
result
}
} }
impl<'a, 'b, 'c, V> Deref for PaintContext<'a, 'b, 'c, V> { impl<'a, 'b, 'c, V> Deref for PaintContext<'a, 'b, 'c, V> {

View File

@ -55,6 +55,7 @@ pub struct Window {
pub(crate) invalidation: Option<WindowInvalidation>, pub(crate) invalidation: Option<WindowInvalidation>,
pub(crate) platform_window: Box<dyn platform::Window>, pub(crate) platform_window: Box<dyn platform::Window>,
pub(crate) rendered_views: HashMap<usize, Box<dyn AnyRootElement>>, pub(crate) rendered_views: HashMap<usize, Box<dyn AnyRootElement>>,
scene: SceneBuilder,
pub(crate) text_style_stack: Vec<TextStyle>, pub(crate) text_style_stack: Vec<TextStyle>,
pub(crate) theme_stack: Vec<Box<dyn Any>>, pub(crate) theme_stack: Vec<Box<dyn Any>>,
pub(crate) new_parents: HashMap<usize, usize>, pub(crate) new_parents: HashMap<usize, usize>,
@ -98,6 +99,7 @@ impl Window {
inspector_enabled: false, inspector_enabled: false,
platform_window, platform_window,
rendered_views: Default::default(), rendered_views: Default::default(),
scene: SceneBuilder::new(),
text_style_stack: Vec::new(), text_style_stack: Vec::new(),
theme_stack: Vec::new(), theme_stack: Vec::new(),
new_parents: HashMap::default(), new_parents: HashMap::default(),
@ -241,6 +243,10 @@ impl<'a> WindowContext<'a> {
.push_back(Effect::RepaintWindow { window }); .push_back(Effect::RepaintWindow { window });
} }
pub fn scene(&mut self) -> &mut SceneBuilder {
&mut self.window.scene
}
pub fn enable_inspector(&mut self) { pub fn enable_inspector(&mut self) {
self.window.inspector_enabled = true; self.window.inspector_enabled = true;
} }
@ -1080,9 +1086,7 @@ impl<'a> WindowContext<'a> {
let root_view_id = self.window.root_view().id(); let root_view_id = self.window.root_view().id();
let mut rendered_root = self.window.rendered_views.remove(&root_view_id).unwrap(); let mut rendered_root = self.window.rendered_views.remove(&root_view_id).unwrap();
let mut scene_builder = SceneBuilder::new(scale_factor);
rendered_root.paint( rendered_root.paint(
&mut scene_builder,
Vector2F::zero(), Vector2F::zero(),
RectF::from_points(Vector2F::zero(), window_size), RectF::from_points(Vector2F::zero(), window_size),
self, self,
@ -1092,7 +1096,7 @@ impl<'a> WindowContext<'a> {
.insert(root_view_id, rendered_root); .insert(root_view_id, rendered_root);
self.window.text_layout_cache.finish_frame(); self.window.text_layout_cache.finish_frame();
let mut scene = scene_builder.build(); let mut scene = self.window.scene.build(scale_factor);
self.window.cursor_regions = scene.cursor_regions(); self.window.cursor_regions = scene.cursor_regions();
self.window.mouse_regions = scene.mouse_regions(); self.window.mouse_regions = scene.mouse_regions();
self.window.event_handlers = scene.take_event_handlers(); self.window.event_handlers = scene.take_event_handlers();
@ -1696,7 +1700,6 @@ impl<V: 'static> Element<V> for ChildView {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -1705,7 +1708,7 @@ impl<V: 'static> Element<V> for ChildView {
) { ) {
if let Some(mut rendered_view) = cx.window.rendered_views.remove(&self.view_id) { if let Some(mut rendered_view) = cx.window.rendered_views.remove(&self.view_id) {
rendered_view rendered_view
.paint(scene, bounds.origin(), visible_bounds, cx) .paint(bounds.origin(), visible_bounds, cx)
.log_err(); .log_err();
cx.window.rendered_views.insert(self.view_id, rendered_view); cx.window.rendered_views.insert(self.view_id, rendered_view);
} else { } else {

View File

@ -34,8 +34,8 @@ use crate::{
rect::RectF, rect::RectF,
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json, Action, Entity, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, TypeTag, View, json, Action, Entity, LayoutContext, PaintContext, SizeConstraint, TypeTag, View, ViewContext,
ViewContext, WeakViewHandle, WindowContext, WeakViewHandle, WindowContext,
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use core::panic; use core::panic;
@ -64,7 +64,6 @@ pub trait Element<V: 'static>: 'static {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut Self::LayoutState, layout: &mut Self::LayoutState,
@ -265,7 +264,6 @@ trait AnyElementState<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
view: &mut V, view: &mut V,
@ -346,7 +344,6 @@ impl<V, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
view: &mut V, view: &mut V,
@ -361,7 +358,6 @@ impl<V, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
} => { } => {
let bounds = RectF::new(origin, size); let bounds = RectF::new(origin, size);
let paint = element.paint( let paint = element.paint(
scene,
bounds, bounds,
visible_bounds, visible_bounds,
&mut layout, &mut layout,
@ -386,7 +382,6 @@ impl<V, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
} => { } => {
let bounds = RectF::new(origin, bounds.size()); let bounds = RectF::new(origin, bounds.size());
let paint = element.paint( let paint = element.paint(
scene,
bounds, bounds,
visible_bounds, visible_bounds,
&mut layout, &mut layout,
@ -522,13 +517,12 @@ impl<V> AnyElement<V> {
pub fn paint( pub fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) { ) {
self.state.paint(scene, origin, visible_bounds, view, cx); self.state.paint(origin, visible_bounds, view, cx);
} }
pub fn rect_for_text_range( pub fn rect_for_text_range(
@ -584,14 +578,13 @@ impl<V: 'static> Element<V> for AnyElement<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
self.paint(scene, bounds.origin(), visible_bounds, view, cx); self.paint(bounds.origin(), visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(
@ -647,7 +640,6 @@ pub trait AnyRootElement {
fn layout(&mut self, constraint: SizeConstraint, cx: &mut WindowContext) -> Result<Vector2F>; fn layout(&mut self, constraint: SizeConstraint, cx: &mut WindowContext) -> Result<Vector2F>;
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -675,7 +667,6 @@ impl<V: View> AnyRootElement for RootElement<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -687,8 +678,7 @@ impl<V: View> AnyRootElement for RootElement<V> {
view.update(cx, |view, cx| { view.update(cx, |view, cx| {
let mut cx = PaintContext::new(cx); let mut cx = PaintContext::new(cx);
self.element self.element.paint(origin, visible_bounds, view, &mut cx);
.paint(scene, origin, visible_bounds, view, &mut cx);
Ok(()) Ok(())
}) })
} }

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, json, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
ViewContext,
}; };
use json::ToJson; use json::ToJson;
@ -65,7 +64,6 @@ impl<V: 'static> Element<V> for Align<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -79,7 +77,6 @@ impl<V: 'static> Element<V> for Align<V> {
let child_target = child_center + child_center * self.alignment; let child_target = child_center + child_center * self.alignment;
self.child.paint( self.child.paint(
scene,
bounds.origin() - (child_target - my_target), bounds.origin() - (child_target - my_target),
visible_bounds, visible_bounds,
view, view,

View File

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use super::Element; use super::Element;
use crate::{ use crate::{
json::{self, json}, json::{self, json},
PaintContext, SceneBuilder, ViewContext, PaintContext, ViewContext,
}; };
use json::ToJson; use json::ToJson;
use pathfinder_geometry::{ use pathfinder_geometry::{
@ -15,7 +15,7 @@ pub struct Canvas<V, F>(F, PhantomData<V>);
impl<V, F> Canvas<V, F> impl<V, F> Canvas<V, F>
where where
F: FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>), F: FnMut(RectF, RectF, &mut V, &mut PaintContext<V>),
{ {
pub fn new(f: F) -> Self { pub fn new(f: F) -> Self {
Self(f, PhantomData) Self(f, PhantomData)
@ -24,7 +24,7 @@ where
impl<V: 'static, F> Element<V> for Canvas<V, F> impl<V: 'static, F> Element<V> for Canvas<V, F>
where where
F: 'static + FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>), F: 'static + FnMut(RectF, RectF, &mut V, &mut PaintContext<V>),
{ {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();
@ -50,14 +50,13 @@ where
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
self.0(scene, bounds, visible_bounds, view, cx) self.0(bounds, visible_bounds, view, cx)
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -3,10 +3,7 @@ use std::ops::Range;
use pathfinder_geometry::{rect::RectF, vector::Vector2F}; use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use serde_json::json; use serde_json::json;
use crate::{ use crate::{json, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext};
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
ViewContext,
};
pub struct Clipped<V> { pub struct Clipped<V> {
child: AnyElement<V>, child: AnyElement<V>,
@ -33,17 +30,16 @@ impl<V: 'static> Element<V> for Clipped<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
scene.paint_layer(Some(bounds), |scene| { cx.scene().push_layer(Some(bounds));
self.child let state = self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx) cx.scene().pop_layer();
}) state
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -2,9 +2,7 @@ use std::{any::Any, marker::PhantomData};
use pathfinder_geometry::{rect::RectF, vector::Vector2F}; use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use crate::{ use crate::{AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext};
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
};
use super::Empty; use super::Empty;
@ -300,7 +298,6 @@ impl<V: 'static, C: StatefulComponent<V> + 'static> Element<V> for ComponentAdap
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -310,7 +307,7 @@ impl<V: 'static, C: StatefulComponent<V> + 'static> Element<V> for ComponentAdap
self.element self.element
.as_mut() .as_mut()
.expect("Layout should always be called before paint") .expect("Layout should always be called before paint")
.paint(scene, bounds.origin(), visible_bounds, view, cx) .paint(bounds.origin(), visible_bounds, view, cx)
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -5,8 +5,7 @@ use serde_json::json;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, json, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
ViewContext,
}; };
pub struct ConstrainedBox<V> { pub struct ConstrainedBox<V> {
@ -152,17 +151,15 @@ impl<V: 'static> Element<V> for ConstrainedBox<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
scene.paint_layer(Some(visible_bounds), |scene| { cx.scene().push_layer(Some(visible_bounds));
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx); cx.scene().pop_layer();
})
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -10,7 +10,7 @@ use crate::{
json::ToJson, json::ToJson,
platform::CursorStyle, platform::CursorStyle,
scene::{self, CornerRadii, CursorRegion, Quad}, scene::{self, CornerRadii, CursorRegion, Quad},
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@ -387,7 +387,6 @@ impl<V: 'static> Element<V> for Container<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -400,7 +399,7 @@ impl<V: 'static> Element<V> for Container<V> {
); );
if let Some(shadow) = self.style.shadow.as_ref() { if let Some(shadow) = self.style.shadow.as_ref() {
scene.push_shadow(scene::Shadow { cx.scene().push_shadow(scene::Shadow {
bounds: quad_bounds + shadow.offset, bounds: quad_bounds + shadow.offset,
corner_radii: self.style.corner_radii, corner_radii: self.style.corner_radii,
sigma: shadow.blur, sigma: shadow.blur,
@ -410,7 +409,7 @@ impl<V: 'static> Element<V> for Container<V> {
if let Some(hit_bounds) = quad_bounds.intersection(visible_bounds) { if let Some(hit_bounds) = quad_bounds.intersection(visible_bounds) {
if let Some(style) = self.style.cursor { if let Some(style) = self.style.cursor {
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds: hit_bounds, bounds: hit_bounds,
style, style,
}); });
@ -421,26 +420,25 @@ impl<V: 'static> Element<V> for Container<V> {
quad_bounds.origin() + vec2f(self.style.padding.left, self.style.padding.top); quad_bounds.origin() + vec2f(self.style.padding.left, self.style.padding.top);
if self.style.border.overlay { if self.style.border.overlay {
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: quad_bounds, bounds: quad_bounds,
background: self.style.background_color, background: self.style.background_color,
border: Default::default(), border: Default::default(),
corner_radii: self.style.corner_radii.into(), corner_radii: self.style.corner_radii.into(),
}); });
self.child self.child.paint(child_origin, visible_bounds, view, cx);
.paint(scene, child_origin, visible_bounds, view, cx);
scene.push_layer(None); cx.scene().push_layer(None);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: quad_bounds, bounds: quad_bounds,
background: self.style.overlay_color, background: self.style.overlay_color,
border: self.style.border.into(), border: self.style.border.into(),
corner_radii: self.style.corner_radii.into(), corner_radii: self.style.corner_radii.into(),
}); });
scene.pop_layer(); cx.scene().pop_layer();
} else { } else {
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: quad_bounds, bounds: quad_bounds,
background: self.style.background_color, background: self.style.background_color,
border: self.style.border.into(), border: self.style.border.into(),
@ -452,18 +450,17 @@ impl<V: 'static> Element<V> for Container<V> {
self.style.border.left_width(), self.style.border.left_width(),
self.style.border.top_width(), self.style.border.top_width(),
); );
self.child self.child.paint(child_origin, visible_bounds, view, cx);
.paint(scene, child_origin, visible_bounds, view, cx);
if self.style.overlay_color.is_some() { if self.style.overlay_color.is_some() {
scene.push_layer(None); cx.scene().push_layer(None);
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: quad_bounds, bounds: quad_bounds,
background: self.style.overlay_color, background: self.style.overlay_color,
border: Default::default(), border: Default::default(),
corner_radii: self.style.corner_radii.into(), corner_radii: self.style.corner_radii.into(),
}); });
scene.pop_layer(); cx.scene().pop_layer();
} }
} }
} }

View File

@ -6,7 +6,7 @@ use crate::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::{json, ToJson}, json::{json, ToJson},
LayoutContext, PaintContext, SceneBuilder, ViewContext, LayoutContext, PaintContext, ViewContext,
}; };
use crate::{Element, SizeConstraint}; use crate::{Element, SizeConstraint};
@ -52,7 +52,6 @@ impl<V: 'static> Element<V> for Empty {
fn paint( fn paint(
&mut self, &mut self,
_: &mut SceneBuilder,
_: RectF, _: RectF,
_: RectF, _: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,

View File

@ -2,8 +2,7 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, json, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
ViewContext,
}; };
use serde_json::json; use serde_json::json;
@ -57,15 +56,13 @@ impl<V: 'static> Element<V> for Expanded<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -2,8 +2,8 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
use crate::{ use crate::{
json::{self, ToJson, Value}, json::{self, ToJson, Value},
AnyElement, Axis, Element, ElementStateHandle, LayoutContext, PaintContext, SceneBuilder, AnyElement, Axis, Element, ElementStateHandle, LayoutContext, PaintContext, SizeConstraint,
SizeConstraint, Vector2FExt, ViewContext, Vector2FExt, ViewContext,
}; };
use pathfinder_geometry::{ use pathfinder_geometry::{
rect::RectF, rect::RectF,
@ -260,7 +260,6 @@ impl<V: 'static> Element<V> for Flex<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
remaining_space: &mut Self::LayoutState, remaining_space: &mut Self::LayoutState,
@ -272,14 +271,14 @@ impl<V: 'static> Element<V> for Flex<V> {
let mut remaining_space = *remaining_space; let mut remaining_space = *remaining_space;
let overflowing = remaining_space < 0.; let overflowing = remaining_space < 0.;
if overflowing { if overflowing {
scene.push_layer(Some(visible_bounds)); cx.scene().push_layer(Some(visible_bounds));
} }
if let Some(scroll_state) = &self.scroll_state { if let Some((scroll_state, id)) = &self.scroll_state {
scene.push_mouse_region( let scroll_state = scroll_state.read(cx).clone();
crate::MouseRegion::new::<Self>(scroll_state.1, 0, bounds) cx.scene().push_mouse_region(
crate::MouseRegion::new::<Self>(*id, 0, bounds)
.on_scroll({ .on_scroll({
let scroll_state = scroll_state.0.read(cx).clone();
let axis = self.axis; let axis = self.axis;
move |e, _: &mut V, cx| { move |e, _: &mut V, cx| {
if remaining_space < 0. { if remaining_space < 0. {
@ -358,7 +357,7 @@ impl<V: 'static> Element<V> for Flex<V> {
aligned_child_origin aligned_child_origin
}; };
child.paint(scene, aligned_child_origin, visible_bounds, view, cx); child.paint(aligned_child_origin, visible_bounds, view, cx);
match self.axis { match self.axis {
Axis::Horizontal => child_origin += vec2f(child.size().x() + self.spacing, 0.0), Axis::Horizontal => child_origin += vec2f(child.size().x() + self.spacing, 0.0),
@ -367,7 +366,7 @@ impl<V: 'static> Element<V> for Flex<V> {
} }
if overflowing { if overflowing {
scene.pop_layer(); cx.scene().pop_layer();
} }
} }
@ -451,15 +450,13 @@ impl<V: 'static> Element<V> for FlexItem<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx)
.paint(scene, bounds.origin(), visible_bounds, view, cx)
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -3,7 +3,7 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::json, json::json,
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
}; };
pub struct Hook<V> { pub struct Hook<V> {
@ -47,15 +47,13 @@ impl<V: 'static> Element<V> for Hook<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) { ) {
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -5,8 +5,7 @@ use crate::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::{json, ToJson}, json::{json, ToJson},
scene, Element, ImageData, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, scene, Element, ImageData, LayoutContext, PaintContext, SizeConstraint, ViewContext,
ViewContext,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@ -92,15 +91,14 @@ impl<V: 'static> Element<V> for Image {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
_: RectF, _: RectF,
layout: &mut Self::LayoutState, layout: &mut Self::LayoutState,
_: &mut V, _: &mut V,
_: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
if let Some(data) = layout { if let Some(data) = layout {
scene.push_image(scene::Image { cx.scene().push_image(scene::Image {
bounds, bounds,
border: self.style.border.into(), border: self.style.border.into(),
corner_radii: self.style.corner_radius.into(), corner_radii: self.style.corner_radius.into(),

View File

@ -61,14 +61,13 @@ impl<V: 'static> Element<V> for KeystrokeLabel {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
element: &mut AnyElement<V>, element: &mut AnyElement<V>,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) { ) {
element.paint(scene, bounds.origin(), visible_bounds, view, cx); element.paint(bounds.origin(), visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -8,7 +8,7 @@ use crate::{
}, },
json::{ToJson, Value}, json::{ToJson, Value},
text_layout::{Line, RunStyle}, text_layout::{Line, RunStyle},
Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@ -158,7 +158,6 @@ impl<V: 'static> Element<V> for Label {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
line: &mut Self::LayoutState, line: &mut Self::LayoutState,
@ -166,13 +165,7 @@ impl<V: 'static> Element<V> for Label {
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
line.paint( line.paint(bounds.origin(), visible_bounds, bounds.size().y(), cx)
scene,
bounds.origin(),
visible_bounds,
bounds.size().y(),
cx,
)
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -4,8 +4,7 @@ use crate::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::json, json::json,
AnyElement, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder, SizeConstraint, AnyElement, Element, LayoutContext, MouseRegion, PaintContext, SizeConstraint, ViewContext,
ViewContext,
}; };
use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc}; use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc};
use sum_tree::{Bias, SumTree}; use sum_tree::{Bias, SumTree};
@ -250,7 +249,6 @@ impl<V: 'static> Element<V> for List<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
scroll_top: &mut ListOffset, scroll_top: &mut ListOffset,
@ -258,9 +256,10 @@ impl<V: 'static> Element<V> for List<V> {
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) { ) {
let visible_bounds = visible_bounds.intersection(bounds).unwrap_or_default(); let visible_bounds = visible_bounds.intersection(bounds).unwrap_or_default();
scene.push_layer(Some(visible_bounds)); cx.scene().push_layer(Some(visible_bounds));
scene.push_mouse_region( let view_id = cx.view_id();
MouseRegion::new::<Self>(cx.view_id(), 0, bounds).on_scroll({ cx.scene()
.push_mouse_region(MouseRegion::new::<Self>(view_id, 0, bounds).on_scroll({
let state = self.state.clone(); let state = self.state.clone();
let height = bounds.height(); let height = bounds.height();
let scroll_top = scroll_top.clone(); let scroll_top = scroll_top.clone();
@ -274,17 +273,14 @@ impl<V: 'static> Element<V> for List<V> {
cx, cx,
) )
} }
}), }));
);
let state = &mut *self.state.0.borrow_mut(); let state = &mut *self.state.0.borrow_mut();
for (element, origin) in state.visible_elements(bounds, scroll_top) { for (element, origin) in state.visible_elements(bounds, scroll_top) {
element element.borrow_mut().paint(origin, visible_bounds, view, cx);
.borrow_mut()
.paint(scene, origin, visible_bounds, view, cx);
} }
scene.pop_layer(); cx.scene().pop_layer();
} }
fn rect_for_text_range( fn rect_for_text_range(
@ -957,15 +953,7 @@ mod tests {
(self.size, ()) (self.size, ())
} }
fn paint( fn paint(&mut self, _: RectF, _: RectF, _: &mut (), _: &mut V, _: &mut PaintContext<V>) {
&mut self,
_: &mut SceneBuilder,
_: RectF,
_: RectF,
_: &mut (),
_: &mut V,
_: &mut PaintContext<V>,
) {
unimplemented!() unimplemented!()
} }

View File

@ -11,7 +11,7 @@ use crate::{
MouseHover, MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut, MouseHover, MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
}, },
AnyElement, Element, EventContext, LayoutContext, MouseRegion, MouseState, PaintContext, AnyElement, Element, EventContext, LayoutContext, MouseRegion, MouseState, PaintContext,
SceneBuilder, SizeConstraint, TypeTag, ViewContext, SizeConstraint, TypeTag, ViewContext,
}; };
use serde_json::json; use serde_json::json;
use std::ops::Range; use std::ops::Range;
@ -236,26 +236,21 @@ impl<V: 'static> MouseEventHandler<V> {
.round_out() .round_out()
} }
fn paint_regions( fn paint_regions(&self, bounds: RectF, visible_bounds: RectF, cx: &mut ViewContext<V>) {
&self,
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
cx: &mut ViewContext<V>,
) {
let visible_bounds = visible_bounds.intersection(bounds).unwrap_or_default(); let visible_bounds = visible_bounds.intersection(bounds).unwrap_or_default();
let hit_bounds = self.hit_bounds(visible_bounds); let hit_bounds = self.hit_bounds(visible_bounds);
if let Some(style) = self.cursor_style { if let Some(style) = self.cursor_style {
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds: hit_bounds, bounds: hit_bounds,
style, style,
}); });
} }
scene.push_mouse_region( let view_id = cx.view_id();
cx.scene().push_mouse_region(
MouseRegion::from_handlers( MouseRegion::from_handlers(
self.tag, self.tag,
cx.view_id(), view_id,
self.region_id, self.region_id,
hit_bounds, hit_bounds,
self.handlers.clone(), self.handlers.clone(),
@ -282,7 +277,6 @@ impl<V: 'static> Element<V> for MouseEventHandler<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -290,16 +284,13 @@ impl<V: 'static> Element<V> for MouseEventHandler<V> {
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
if self.above { if self.above {
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx); cx.paint_layer(None, |cx| {
self.paint_regions(bounds, visible_bounds, cx);
scene.paint_layer(None, |scene| {
self.paint_regions(scene, bounds, visible_bounds, cx);
}); });
} else { } else {
self.paint_regions(scene, bounds, visible_bounds, cx); self.paint_regions(bounds, visible_bounds, cx);
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx);
} }
} }

View File

@ -3,8 +3,8 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::ToJson, json::ToJson,
AnyElement, Axis, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder, AnyElement, Axis, Element, LayoutContext, MouseRegion, PaintContext, SizeConstraint,
SizeConstraint, ViewContext, ViewContext,
}; };
use serde_json::json; use serde_json::json;
@ -138,7 +138,6 @@ impl<V: 'static> Element<V> for Overlay<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
_: RectF, _: RectF,
size: &mut Self::LayoutState, size: &mut Self::LayoutState,
@ -213,25 +212,23 @@ impl<V: 'static> Element<V> for Overlay<V> {
OverlayFitMode::None => {} OverlayFitMode::None => {}
} }
scene.paint_stacking_context(None, self.z_index, |scene| { cx.scene().push_stacking_context(None, self.z_index);
if self.hoverable { if self.hoverable {
enum OverlayHoverCapture {} enum OverlayHoverCapture {}
// Block hovers in lower stacking contexts // Block hovers in lower stacking contexts
scene.push_mouse_region(MouseRegion::new::<OverlayHoverCapture>( let view_id = cx.view_id();
cx.view_id(), cx.scene()
cx.view_id(), .push_mouse_region(MouseRegion::new::<OverlayHoverCapture>(
bounds, view_id, view_id, bounds,
)); ));
} }
self.child.paint( self.child.paint(
scene,
bounds.origin(), bounds.origin(),
RectF::new(Vector2F::zero(), cx.window_size()), RectF::new(Vector2F::zero(), cx.window_size()),
view, view,
cx, cx,
); );
}); cx.scene().pop_stacking_context();
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -7,7 +7,7 @@ use serde_json::json;
use crate::{ use crate::{
geometry::rect::RectF, geometry::rect::RectF,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AnyElement, AppContext, Axis, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder, AnyElement, AppContext, Axis, Element, LayoutContext, MouseRegion, PaintContext,
SizeConstraint, TypeTag, View, ViewContext, SizeConstraint, TypeTag, View, ViewContext,
}; };
@ -112,24 +112,20 @@ impl<V: 'static> Element<V> for Resizable<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: pathfinder_geometry::rect::RectF, bounds: pathfinder_geometry::rect::RectF,
visible_bounds: pathfinder_geometry::rect::RectF, visible_bounds: pathfinder_geometry::rect::RectF,
constraint: &mut SizeConstraint, constraint: &mut SizeConstraint,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
scene.push_stacking_context(None, None); cx.scene().push_stacking_context(None, None);
let handle_region = self.handle_side.of_rect(bounds, self.handle_size); let handle_region = self.handle_side.of_rect(bounds, self.handle_size);
enum ResizeHandle {} enum ResizeHandle {}
scene.push_mouse_region( let view_id = cx.view_id();
MouseRegion::new::<ResizeHandle>( cx.scene().push_mouse_region(
cx.view_id(), MouseRegion::new::<ResizeHandle>(view_id, self.handle_side as usize, handle_region)
self.handle_side as usize,
handle_region,
)
.on_down(MouseButton::Left, |_, _: &mut V, _| {}) // This prevents the mouse down event from being propagated elsewhere .on_down(MouseButton::Left, |_, _: &mut V, _| {}) // This prevents the mouse down event from being propagated elsewhere
.on_click(MouseButton::Left, { .on_click(MouseButton::Left, {
let on_resize = self.on_resize.clone(); let on_resize = self.on_resize.clone();
@ -158,11 +154,15 @@ impl<V: 'static> Element<V> for Resizable<V> {
let new_size_raw = match side { let new_size_raw = match side {
// Handle on top side of element => Element is on bottom // Handle on top side of element => Element is on bottom
HandleSide::Top => bounds.height() + bounds.origin_y() - event.position.y(), HandleSide::Top => {
bounds.height() + bounds.origin_y() - event.position.y()
}
// Handle on right side of element => Element is on left // Handle on right side of element => Element is on left
HandleSide::Right => event.position.x() - bounds.lower_left().x(), HandleSide::Right => event.position.x() - bounds.lower_left().x(),
// Handle on left side of element => Element is on the right // Handle on left side of element => Element is on the right
HandleSide::Left => bounds.width() + bounds.origin_x() - event.position.x(), HandleSide::Left => {
bounds.width() + bounds.origin_x() - event.position.x()
}
// Handle on bottom side of element => Element is on the top // Handle on bottom side of element => Element is on the top
HandleSide::Bottom => event.position.y() - bounds.lower_left().y(), HandleSide::Bottom => event.position.y() - bounds.lower_left().y(),
}; };
@ -175,7 +175,7 @@ impl<V: 'static> Element<V> for Resizable<V> {
}), }),
); );
scene.push_cursor_region(crate::CursorRegion { cx.scene().push_cursor_region(crate::CursorRegion {
bounds: handle_region, bounds: handle_region,
style: match self.handle_side.axis() { style: match self.handle_side.axis() {
Axis::Horizontal => CursorStyle::ResizeLeftRight, Axis::Horizontal => CursorStyle::ResizeLeftRight,
@ -183,10 +183,9 @@ impl<V: 'static> Element<V> for Resizable<V> {
}, },
}); });
scene.pop_stacking_context(); cx.scene().pop_stacking_context();
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(
@ -249,7 +248,6 @@ impl<V: View, P: 'static> Element<V> for BoundsProvider<V, P> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut crate::SceneBuilder,
bounds: pathfinder_geometry::rect::RectF, bounds: pathfinder_geometry::rect::RectF,
visible_bounds: pathfinder_geometry::rect::RectF, visible_bounds: pathfinder_geometry::rect::RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -260,8 +258,7 @@ impl<V: View, P: 'static> Element<V> for BoundsProvider<V, P> {
map.0.insert(TypeTag::new::<P>(), (bounds, visible_bounds)); map.0.insert(TypeTag::new::<P>(), (bounds, visible_bounds));
}); });
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx)
.paint(scene, bounds.origin(), visible_bounds, view, cx)
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -3,7 +3,7 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::{self, json, ToJson}, json::{self, json, ToJson},
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext, AnyElement, Element, LayoutContext, PaintContext, SizeConstraint, ViewContext,
}; };
/// Element which renders it's children in a stack on top of each other. /// Element which renders it's children in a stack on top of each other.
@ -52,7 +52,6 @@ impl<V: 'static> Element<V> for Stack<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -60,9 +59,9 @@ impl<V: 'static> Element<V> for Stack<V> {
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
for child in &mut self.children { for child in &mut self.children {
scene.paint_layer(None, |scene| { cx.scene().push_layer(None);
child.paint(scene, bounds.origin(), visible_bounds, view, cx); child.paint(bounds.origin(), visible_bounds, view, cx);
}); cx.scene().pop_layer();
} }
} }

View File

@ -7,7 +7,7 @@ use crate::{
rect::RectF, rect::RectF,
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
scene, Element, LayoutContext, SceneBuilder, SizeConstraint, ViewContext, scene, Element, LayoutContext, SizeConstraint, ViewContext,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde_derive::Deserialize; use serde_derive::Deserialize;
@ -69,15 +69,14 @@ impl<V: 'static> Element<V> for Svg {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
_visible_bounds: RectF, _visible_bounds: RectF,
svg: &mut Self::LayoutState, svg: &mut Self::LayoutState,
_: &mut V, _: &mut V,
_: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) { ) {
if let Some(svg) = svg.clone() { if let Some(svg) = svg.clone() {
scene.push_icon(scene::Icon { cx.scene().push_icon(scene::Icon {
bounds, bounds,
svg, svg,
path: self.path.clone(), path: self.path.clone(),

View File

@ -7,8 +7,8 @@ use crate::{
}, },
json::{ToJson, Value}, json::{ToJson, Value},
text_layout::{Line, RunStyle, ShapedBoundary}, text_layout::{Line, RunStyle, ShapedBoundary},
AppContext, Element, FontCache, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, Element, FontCache, LayoutContext, PaintContext, SizeConstraint, TextLayoutCache, ViewContext,
TextLayoutCache, ViewContext, WindowContext,
}; };
use log::warn; use log::warn;
use serde_json::json; use serde_json::json;
@ -21,7 +21,7 @@ pub struct Text {
highlights: Option<Box<[(Range<usize>, HighlightStyle)]>>, highlights: Option<Box<[(Range<usize>, HighlightStyle)]>>,
custom_runs: Option<( custom_runs: Option<(
Box<[Range<usize>]>, Box<[Range<usize>]>,
Box<dyn FnMut(usize, RectF, &mut SceneBuilder, &mut AppContext)>, Box<dyn FnMut(usize, RectF, &mut WindowContext)>,
)>, )>,
} }
@ -58,7 +58,7 @@ impl Text {
pub fn with_custom_runs( pub fn with_custom_runs(
mut self, mut self,
runs: impl Into<Box<[Range<usize>]>>, runs: impl Into<Box<[Range<usize>]>>,
callback: impl 'static + FnMut(usize, RectF, &mut SceneBuilder, &mut AppContext), callback: impl 'static + FnMut(usize, RectF, &mut WindowContext),
) -> Self { ) -> Self {
self.custom_runs = Some((runs.into(), Box::new(callback))); self.custom_runs = Some((runs.into(), Box::new(callback)));
self self
@ -166,7 +166,6 @@ impl<V: 'static> Element<V> for Text {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut Self::LayoutState, layout: &mut Self::LayoutState,
@ -175,7 +174,7 @@ impl<V: 'static> Element<V> for Text {
) -> Self::PaintState { ) -> Self::PaintState {
let mut origin = bounds.origin(); let mut origin = bounds.origin();
let empty = Vec::new(); let empty = Vec::new();
let mut callback = |_, _, _: &mut SceneBuilder, _: &mut AppContext| {}; let mut callback = |_, _, _: &mut WindowContext| {};
let mouse_runs; let mouse_runs;
let custom_run_callback; let custom_run_callback;
@ -202,7 +201,6 @@ impl<V: 'static> Element<V> for Text {
if boundaries.intersects(visible_bounds) { if boundaries.intersects(visible_bounds) {
if self.soft_wrap { if self.soft_wrap {
line.paint_wrapped( line.paint_wrapped(
scene,
origin, origin,
visible_bounds, visible_bounds,
layout.line_height, layout.line_height,
@ -210,7 +208,7 @@ impl<V: 'static> Element<V> for Text {
cx, cx,
); );
} else { } else {
line.paint(scene, origin, visible_bounds, layout.line_height, cx); line.paint(origin, visible_bounds, layout.line_height, cx);
} }
} }
@ -248,7 +246,7 @@ impl<V: 'static> Element<V> for Text {
*run_origin, *run_origin,
glyph_origin + vec2f(0., layout.line_height), glyph_origin + vec2f(0., layout.line_height),
); );
custom_run_callback(*run_ix, bounds, scene, cx); custom_run_callback(*run_ix, bounds, cx);
*run_origin = *run_origin =
vec2f(origin.x(), glyph_origin.y() + layout.line_height); vec2f(origin.x(), glyph_origin.y() + layout.line_height);
} }
@ -264,7 +262,7 @@ impl<V: 'static> Element<V> for Text {
run_origin, run_origin,
glyph_origin + vec2f(0., layout.line_height), glyph_origin + vec2f(0., layout.line_height),
); );
custom_run_callback(run_ix, bounds, scene, cx); custom_run_callback(run_ix, bounds, cx);
custom_runs.next(); custom_runs.next();
} }
@ -294,7 +292,7 @@ impl<V: 'static> Element<V> for Text {
run_origin, run_origin,
line_end + vec2f(0., layout.line_height), line_end + vec2f(0., layout.line_height),
); );
custom_run_callback(run_ix, bounds, scene, cx); custom_run_callback(run_ix, bounds, cx);
if end_offset == run_end_offset { if end_offset == run_end_offset {
custom_runs.next(); custom_runs.next();
} }

View File

@ -6,8 +6,8 @@ use crate::{
fonts::TextStyle, fonts::TextStyle,
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::json, json::json,
Action, Axis, ElementStateHandle, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, Action, Axis, ElementStateHandle, LayoutContext, PaintContext, SizeConstraint, Task, TypeTag,
Task, TypeTag, ViewContext, ViewContext,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@ -204,17 +204,15 @@ impl<V: 'static> Element<V> for Tooltip<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) { ) {
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx);
if let Some(tooltip) = self.tooltip.as_mut() { if let Some(tooltip) = self.tooltip.as_mut() {
tooltip.paint(scene, bounds.origin(), visible_bounds, view, cx); tooltip.paint(bounds.origin(), visible_bounds, view, cx);
} }
} }

View File

@ -6,7 +6,7 @@ use crate::{
}, },
json::{self, json}, json::{self, json},
platform::ScrollWheelEvent, platform::ScrollWheelEvent,
AnyElement, LayoutContext, MouseRegion, PaintContext, SceneBuilder, ViewContext, AnyElement, LayoutContext, MouseRegion, PaintContext, ViewContext,
}; };
use json::ToJson; use json::ToJson;
use std::{cell::RefCell, cmp, ops::Range, rc::Rc}; use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
@ -272,7 +272,6 @@ impl<V: 'static> Element<V> for UniformList<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut Self::LayoutState, layout: &mut Self::LayoutState,
@ -281,9 +280,9 @@ impl<V: 'static> Element<V> for UniformList<V> {
) -> Self::PaintState { ) -> Self::PaintState {
let visible_bounds = visible_bounds.intersection(bounds).unwrap_or_default(); let visible_bounds = visible_bounds.intersection(bounds).unwrap_or_default();
scene.push_layer(Some(visible_bounds)); cx.scene().push_layer(Some(visible_bounds));
scene.push_mouse_region( cx.scene().push_mouse_region(
MouseRegion::new::<Self>(self.view_id, 0, visible_bounds).on_scroll({ MouseRegion::new::<Self>(self.view_id, 0, visible_bounds).on_scroll({
let scroll_max = layout.scroll_max; let scroll_max = layout.scroll_max;
let state = self.state.clone(); let state = self.state.clone();
@ -312,11 +311,11 @@ impl<V: 'static> Element<V> for UniformList<V> {
); );
for item in &mut layout.items { for item in &mut layout.items {
item.paint(scene, item_origin, visible_bounds, view, cx); item.paint(item_origin, visible_bounds, view, cx);
item_origin += vec2f(0.0, layout.item_height); item_origin += vec2f(0.0, layout.item_height);
} }
scene.pop_layer(); cx.scene().pop_layer();
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -26,7 +26,6 @@ pub use mouse_event::*;
pub use mouse_region::*; pub use mouse_region::*;
pub struct SceneBuilder { pub struct SceneBuilder {
scale_factor: f32,
stacking_contexts: Vec<StackingContext>, stacking_contexts: Vec<StackingContext>,
active_stacking_context_stack: Vec<usize>, active_stacking_context_stack: Vec<usize>,
/// Used by the gpui2 crate. /// Used by the gpui2 crate.
@ -245,45 +244,40 @@ impl Scene {
} }
impl SceneBuilder { impl SceneBuilder {
pub fn new(scale_factor: f32) -> Self { pub fn new() -> Self {
let stacking_context = StackingContext::new(None, 0); let mut this = SceneBuilder {
SceneBuilder { stacking_contexts: Vec::new(),
scale_factor, active_stacking_context_stack: Vec::new(),
stacking_contexts: vec![stacking_context],
active_stacking_context_stack: vec![0],
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
mouse_region_ids: Default::default(), mouse_region_ids: HashSet::default(),
event_handlers: Vec::new(), event_handlers: Vec::new(),
} };
this.clear();
this
} }
pub fn build(mut self) -> Scene { pub fn clear(&mut self) {
self.stacking_contexts self.stacking_contexts.clear();
.sort_by_key(|context| context.z_index); self.stacking_contexts.push(StackingContext::new(None, 0));
self.active_stacking_context_stack.clear();
self.active_stacking_context_stack.push(0);
#[cfg(debug_assertions)]
self.mouse_region_ids.clear();
}
pub fn build(&mut self, scale_factor: f32) -> Scene {
let mut stacking_contexts = std::mem::take(&mut self.stacking_contexts);
stacking_contexts.sort_by_key(|context| context.z_index);
let event_handlers = std::mem::take(&mut self.event_handlers);
self.clear();
Scene { Scene {
scale_factor: self.scale_factor, scale_factor,
stacking_contexts: self.stacking_contexts, stacking_contexts,
event_handlers: self.event_handlers, event_handlers,
} }
} }
pub fn scale_factor(&self) -> f32 {
self.scale_factor
}
pub fn paint_stacking_context<F>(
&mut self,
clip_bounds: Option<RectF>,
z_index: Option<usize>,
f: F,
) where
F: FnOnce(&mut Self),
{
self.push_stacking_context(clip_bounds, z_index);
f(self);
self.pop_stacking_context();
}
pub fn push_stacking_context(&mut self, clip_bounds: Option<RectF>, z_index: Option<usize>) { pub fn push_stacking_context(&mut self, clip_bounds: Option<RectF>, z_index: Option<usize>) {
let z_index = z_index.unwrap_or_else(|| self.active_stacking_context().z_index + 1); let z_index = z_index.unwrap_or_else(|| self.active_stacking_context().z_index + 1);
self.active_stacking_context_stack self.active_stacking_context_stack
@ -297,15 +291,6 @@ impl SceneBuilder {
assert!(!self.active_stacking_context_stack.is_empty()); assert!(!self.active_stacking_context_stack.is_empty());
} }
pub fn paint_layer<F>(&mut self, clip_bounds: Option<RectF>, f: F)
where
F: FnOnce(&mut Self),
{
self.push_layer(clip_bounds);
f(self);
self.pop_layer();
}
pub fn push_layer(&mut self, clip_bounds: Option<RectF>) { pub fn push_layer(&mut self, clip_bounds: Option<RectF>) {
self.active_stacking_context().push_layer(clip_bounds); self.active_stacking_context().push_layer(clip_bounds);
} }

View File

@ -9,7 +9,6 @@ use crate::{
platform::FontSystem, platform::FontSystem,
scene, scene,
window::WindowContext, window::WindowContext,
SceneBuilder,
}; };
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
@ -284,7 +283,6 @@ impl Line {
pub fn paint( pub fn paint(
&self, &self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
line_height: f32, line_height: f32,
@ -347,7 +345,7 @@ impl Line {
} }
if let Some((underline_origin, underline_style)) = finished_underline { if let Some((underline_origin, underline_style)) = finished_underline {
scene.push_underline(scene::Underline { cx.scene().push_underline(scene::Underline {
origin: underline_origin, origin: underline_origin,
width: glyph_origin.x() - underline_origin.x(), width: glyph_origin.x() - underline_origin.x(),
thickness: underline_style.thickness.into(), thickness: underline_style.thickness.into(),
@ -357,14 +355,14 @@ impl Line {
} }
if glyph.is_emoji { if glyph.is_emoji {
scene.push_image_glyph(scene::ImageGlyph { cx.scene().push_image_glyph(scene::ImageGlyph {
font_id: run.font_id, font_id: run.font_id,
font_size: self.layout.font_size, font_size: self.layout.font_size,
id: glyph.id, id: glyph.id,
origin: glyph_origin, origin: glyph_origin,
}); });
} else { } else {
scene.push_glyph(scene::Glyph { cx.scene().push_glyph(scene::Glyph {
font_id: run.font_id, font_id: run.font_id,
font_size: self.layout.font_size, font_size: self.layout.font_size,
id: glyph.id, id: glyph.id,
@ -377,7 +375,7 @@ impl Line {
if let Some((underline_start, underline_style)) = underline.take() { if let Some((underline_start, underline_style)) = underline.take() {
let line_end_x = origin.x() + self.layout.width; let line_end_x = origin.x() + self.layout.width;
scene.push_underline(scene::Underline { cx.scene().push_underline(scene::Underline {
origin: underline_start, origin: underline_start,
width: line_end_x - underline_start.x(), width: line_end_x - underline_start.x(),
color: underline_style.color.unwrap(), color: underline_style.color.unwrap(),
@ -389,7 +387,6 @@ impl Line {
pub fn paint_wrapped( pub fn paint_wrapped(
&self, &self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
line_height: f32, line_height: f32,
@ -417,7 +414,7 @@ impl Line {
{ {
boundaries.next(); boundaries.next();
if let Some((underline_origin, underline_style)) = underline { if let Some((underline_origin, underline_style)) = underline {
scene.push_underline(scene::Underline { cx.scene().push_underline(scene::Underline {
origin: underline_origin, origin: underline_origin,
width: glyph_origin.x() - underline_origin.x(), width: glyph_origin.x() - underline_origin.x(),
thickness: underline_style.thickness.into(), thickness: underline_style.thickness.into(),
@ -461,7 +458,7 @@ impl Line {
} }
if let Some((underline_origin, underline_style)) = finished_underline { if let Some((underline_origin, underline_style)) = finished_underline {
scene.push_underline(scene::Underline { cx.scene().push_underline(scene::Underline {
origin: underline_origin, origin: underline_origin,
width: glyph_origin.x() - underline_origin.x(), width: glyph_origin.x() - underline_origin.x(),
thickness: underline_style.thickness.into(), thickness: underline_style.thickness.into(),
@ -477,14 +474,14 @@ impl Line {
); );
if glyph_bounds.intersects(visible_bounds) { if glyph_bounds.intersects(visible_bounds) {
if glyph.is_emoji { if glyph.is_emoji {
scene.push_image_glyph(scene::ImageGlyph { cx.scene().push_image_glyph(scene::ImageGlyph {
font_id: run.font_id, font_id: run.font_id,
font_size: self.layout.font_size, font_size: self.layout.font_size,
id: glyph.id, id: glyph.id,
origin: glyph_bounds.origin() + baseline_offset, origin: glyph_bounds.origin() + baseline_offset,
}); });
} else { } else {
scene.push_glyph(scene::Glyph { cx.scene().push_glyph(scene::Glyph {
font_id: run.font_id, font_id: run.font_id,
font_size: self.layout.font_size, font_size: self.layout.font_size,
id: glyph.id, id: glyph.id,
@ -498,7 +495,7 @@ impl Line {
if let Some((underline_origin, underline_style)) = underline.take() { if let Some((underline_origin, underline_style)) = underline.take() {
let line_end_x = glyph_origin.x() + self.layout.width - prev_position; let line_end_x = glyph_origin.x() + self.layout.width - prev_position;
scene.push_underline(scene::Underline { cx.scene().push_underline(scene::Underline {
origin: underline_origin, origin: underline_origin,
width: line_end_x - underline_origin.x(), width: line_end_x - underline_origin.x(),
thickness: underline_style.thickness.into(), thickness: underline_style.thickness.into(),

View File

@ -36,7 +36,6 @@ impl<V: 'static> gpui::Element<V> for AdapterElement<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut gpui::SceneBuilder,
bounds: RectF, bounds: RectF,
_visible_bounds: RectF, _visible_bounds: RectF,
layout_data: &mut Option<(LayoutEngine, LayoutId)>, layout_data: &mut Option<(LayoutEngine, LayoutId)>,
@ -45,7 +44,7 @@ impl<V: 'static> gpui::Element<V> for AdapterElement<V> {
) -> Self::PaintState { ) -> Self::PaintState {
let (layout_engine, layout_id) = layout_data.take().unwrap(); let (layout_engine, layout_id) = layout_data.take().unwrap();
legacy_cx.push_layout_engine(layout_engine); legacy_cx.push_layout_engine(layout_engine);
let mut cx = PaintContext::new(legacy_cx, scene); let mut cx = PaintContext::new(legacy_cx);
self.0.paint(view, bounds.origin(), &mut cx); self.0.paint(view, bounds.origin(), &mut cx);
*layout_data = legacy_cx.pop_layout_engine().zip(Some(layout_id)); *layout_data = legacy_cx.pop_layout_engine().zip(Some(layout_id));
debug_assert!(layout_data.is_some()); debug_assert!(layout_data.is_some());

View File

@ -88,7 +88,7 @@ impl<V: 'static> Element<V> for Div<V> {
// TODO: Support only one dimension being hidden // TODO: Support only one dimension being hidden
let mut pop_layer = false; let mut pop_layer = false;
if style.overflow.y != Overflow::Visible || style.overflow.x != Overflow::Visible { if style.overflow.y != Overflow::Visible || style.overflow.x != Overflow::Visible {
cx.scene.push_layer(Some(bounds)); cx.scene().push_layer(Some(bounds));
pop_layer = true; pop_layer = true;
} }
@ -97,7 +97,7 @@ impl<V: 'static> Element<V> for Div<V> {
} }
if pop_layer { if pop_layer {
cx.scene.pop_layer(); cx.scene().pop_layer();
} }
style.paint_foreground(bounds, cx); style.paint_foreground(bounds, cx);
@ -221,7 +221,7 @@ impl<V: 'static> Div<V> {
let hovered = bounds.contains_point(cx.mouse_position()); let hovered = bounds.contains_point(cx.mouse_position());
if hovered { if hovered {
let rem_size = cx.rem_size(); let rem_size = cx.rem_size();
cx.scene.push_quad(scene::Quad { cx.scene().push_quad(scene::Quad {
bounds, bounds,
background: Some(hsla(0., 0., 1., 0.05).into()), background: Some(hsla(0., 0., 1., 0.05).into()),
border: gpui::Border { border: gpui::Border {

View File

@ -70,7 +70,7 @@ impl<V: 'static> Element<V> for Img {
.and_then(ResultExt::log_err) .and_then(ResultExt::log_err)
{ {
let rem_size = cx.rem_size(); let rem_size = cx.rem_size();
cx.scene.push_image(scene::Image { cx.scene().push_image(scene::Image {
bounds, bounds,
border: gpui::Border { border: gpui::Border {
color: style.border_color.unwrap_or_default().into(), color: style.border_color.unwrap_or_default().into(),

View File

@ -63,7 +63,7 @@ impl<V: 'static> Element<V> for Svg {
color: Rgba::from(fill_color).into(), color: Rgba::from(fill_color).into(),
}; };
cx.scene.push_icon(icon); cx.scene().push_icon(icon);
} }
} }
} }

View File

@ -92,13 +92,7 @@ impl<V: 'static> Element<V> for Text {
// TODO: We haven't added visible bounds to the new element system yet, so this is a placeholder. // TODO: We haven't added visible bounds to the new element system yet, so this is a placeholder.
let visible_bounds = bounds; let visible_bounds = bounds;
line.paint( line.paint(bounds.origin(), visible_bounds, line_height, cx.legacy_cx);
cx.scene,
bounds.origin(),
visible_bounds,
line_height,
cx.legacy_cx,
);
} }
} }

View File

@ -11,15 +11,11 @@ pub struct PaintContext<'a, 'b, 'c, 'd, V> {
#[deref] #[deref]
#[deref_mut] #[deref_mut]
pub(crate) legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>, pub(crate) legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>,
pub(crate) scene: &'d mut gpui::SceneBuilder,
} }
impl<'a, 'b, 'c, 'd, V: 'static> PaintContext<'a, 'b, 'c, 'd, V> { impl<'a, 'b, 'c, 'd, V: 'static> PaintContext<'a, 'b, 'c, 'd, V> {
pub fn new( pub fn new(legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>) -> Self {
legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>, Self { legacy_cx }
scene: &'d mut gpui::SceneBuilder,
) -> Self {
Self { legacy_cx, scene }
} }
pub fn on_event<E: 'static>( pub fn on_event<E: 'static>(
@ -29,7 +25,7 @@ impl<'a, 'b, 'c, 'd, V: 'static> PaintContext<'a, 'b, 'c, 'd, V> {
) { ) {
let view = self.weak_handle(); let view = self.weak_handle();
self.scene.event_handlers.push(EventHandler { self.scene().event_handlers.push(EventHandler {
order, order,
handler: Rc::new(move |event, window_cx| { handler: Rc::new(move |event, window_cx| {
if let Some(view) = view.upgrade(window_cx) { if let Some(view) = view.upgrade(window_cx) {

View File

@ -167,7 +167,7 @@ impl Style {
pub fn paint_background<V: 'static>(&self, bounds: RectF, cx: &mut PaintContext<V>) { pub fn paint_background<V: 'static>(&self, bounds: RectF, cx: &mut PaintContext<V>) {
let rem_size = cx.rem_size(); let rem_size = cx.rem_size();
if let Some(color) = self.fill.as_ref().and_then(Fill::color) { if let Some(color) = self.fill.as_ref().and_then(Fill::color) {
cx.scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds, bounds,
background: Some(color.into()), background: Some(color.into()),
corner_radii: self.corner_radii.to_gpui(bounds.size(), rem_size), corner_radii: self.corner_radii.to_gpui(bounds.size(), rem_size),
@ -183,7 +183,7 @@ impl Style {
if let Some(color) = self.border_color { if let Some(color) = self.border_color {
let border = self.border_widths.to_pixels(rem_size); let border = self.border_widths.to_pixels(rem_size);
if !border.is_empty() { if !border.is_empty() {
cx.scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds, bounds,
background: None, background: None,
corner_radii: self.corner_radii.to_gpui(bounds.size(), rem_size), corner_radii: self.corner_radii.to_gpui(bounds.size(), rem_size),

View File

@ -338,14 +338,13 @@ pub fn element_derive(input: TokenStream) -> TokenStream {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut gpui::SceneBuilder,
bounds: gpui::geometry::rect::RectF, bounds: gpui::geometry::rect::RectF,
visible_bounds: gpui::geometry::rect::RectF, visible_bounds: gpui::geometry::rect::RectF,
element: &mut gpui::elements::AnyElement<V>, element: &mut gpui::elements::AnyElement<V>,
view: &mut V, view: &mut V,
cx: &mut gpui::PaintContext<V>, cx: &mut gpui::PaintContext<V>,
) { ) {
element.paint(scene, bounds.origin(), visible_bounds, view, cx); element.paint(bounds.origin(), visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -11,8 +11,8 @@ use gpui::{
serde_json::json, serde_json::json,
text_layout::{Line, RunStyle}, text_layout::{Line, RunStyle},
AnyElement, Element, EventContext, FontCache, LayoutContext, ModelContext, MouseRegion, AnyElement, Element, EventContext, FontCache, LayoutContext, ModelContext, MouseRegion,
PaintContext, Quad, SceneBuilder, SizeConstraint, TextLayoutCache, ViewContext, PaintContext, Quad, SizeConstraint, TextLayoutCache, ViewContext, WeakModelHandle,
WeakModelHandle, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use language::CursorShape; use language::CursorShape;
@ -86,12 +86,11 @@ impl LayoutCell {
fn paint( fn paint(
&self, &self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
layout: &LayoutState, layout: &LayoutState,
visible_bounds: RectF, visible_bounds: RectF,
_view: &mut TerminalView, _view: &mut TerminalView,
cx: &mut ViewContext<TerminalView>, cx: &mut WindowContext,
) { ) {
let pos = { let pos = {
let point = self.point; let point = self.point;
@ -102,7 +101,7 @@ impl LayoutCell {
}; };
self.text self.text
.paint(scene, pos, visible_bounds, layout.size.line_height, cx); .paint(pos, visible_bounds, layout.size.line_height, cx);
} }
} }
@ -132,11 +131,10 @@ impl LayoutRect {
fn paint( fn paint(
&self, &self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
layout: &LayoutState, layout: &LayoutState,
_view: &mut TerminalView, _view: &mut TerminalView,
_cx: &mut ViewContext<TerminalView>, cx: &mut ViewContext<TerminalView>,
) { ) {
let position = { let position = {
let point = self.point; let point = self.point;
@ -150,7 +148,7 @@ impl LayoutRect {
layout.size.line_height, layout.size.line_height,
); );
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(position, size), bounds: RectF::new(position, size),
background: Some(self.color), background: Some(self.color),
border: Default::default(), border: Default::default(),
@ -387,7 +385,6 @@ impl TerminalElement {
fn attach_mouse_handlers( fn attach_mouse_handlers(
&self, &self,
scene: &mut SceneBuilder,
origin: Vector2F, origin: Vector2F,
visible_bounds: RectF, visible_bounds: RectF,
mode: TermMode, mode: TermMode,
@ -518,7 +515,7 @@ impl TerminalElement {
) )
} }
scene.push_mouse_region(region); cx.scene().push_mouse_region(region);
} }
} }
@ -733,7 +730,6 @@ impl Element<TerminalView> for TerminalElement {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut Self::LayoutState, layout: &mut Self::LayoutState,
@ -745,13 +741,13 @@ impl Element<TerminalView> for TerminalElement {
//Setup element stuff //Setup element stuff
let clip_bounds = Some(visible_bounds); let clip_bounds = Some(visible_bounds);
scene.paint_layer(clip_bounds, |scene| { cx.paint_layer(clip_bounds, |cx| {
let origin = bounds.origin() + vec2f(layout.gutter, 0.); let origin = bounds.origin() + vec2f(layout.gutter, 0.);
// Elements are ephemeral, only at paint time do we know what could be clicked by a mouse // Elements are ephemeral, only at paint time do we know what could be clicked by a mouse
self.attach_mouse_handlers(scene, origin, visible_bounds, layout.mode, cx); self.attach_mouse_handlers(origin, visible_bounds, layout.mode, cx);
scene.push_cursor_region(gpui::CursorRegion { cx.scene().push_cursor_region(gpui::CursorRegion {
bounds, bounds,
style: if layout.hyperlink_tooltip.is_some() { style: if layout.hyperlink_tooltip.is_some() {
CursorStyle::PointingHand CursorStyle::PointingHand
@ -760,9 +756,9 @@ impl Element<TerminalView> for TerminalElement {
}, },
}); });
scene.paint_layer(clip_bounds, |scene| { cx.paint_layer(clip_bounds, |cx| {
//Start with a background color //Start with a background color
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: RectF::new(bounds.origin(), bounds.size()), bounds: RectF::new(bounds.origin(), bounds.size()),
background: Some(layout.background_color), background: Some(layout.background_color),
border: Default::default(), border: Default::default(),
@ -770,12 +766,12 @@ impl Element<TerminalView> for TerminalElement {
}); });
for rect in &layout.rects { for rect in &layout.rects {
rect.paint(scene, origin, layout, view, cx) rect.paint(origin, layout, view, cx);
} }
}); });
//Draw Highlighted Backgrounds //Draw Highlighted Backgrounds
scene.paint_layer(clip_bounds, |scene| { cx.paint_layer(clip_bounds, |cx| {
for (relative_highlighted_range, color) in layout.relative_highlighted_ranges.iter() for (relative_highlighted_range, color) in layout.relative_highlighted_ranges.iter()
{ {
if let Some((start_y, highlighted_range_lines)) = if let Some((start_y, highlighted_range_lines)) =
@ -789,29 +785,29 @@ impl Element<TerminalView> for TerminalElement {
//Copied from editor. TODO: move to theme or something //Copied from editor. TODO: move to theme or something
corner_radius: 0.15 * layout.size.line_height, corner_radius: 0.15 * layout.size.line_height,
}; };
hr.paint(bounds, scene); hr.paint(bounds, cx);
} }
} }
}); });
//Draw the text cells //Draw the text cells
scene.paint_layer(clip_bounds, |scene| { cx.paint_layer(clip_bounds, |cx| {
for cell in &layout.cells { for cell in &layout.cells {
cell.paint(scene, origin, layout, visible_bounds, view, cx); cell.paint(origin, layout, visible_bounds, view, cx);
} }
}); });
//Draw cursor //Draw cursor
if self.cursor_visible { if self.cursor_visible {
if let Some(cursor) = &layout.cursor { if let Some(cursor) = &layout.cursor {
scene.paint_layer(clip_bounds, |scene| { cx.paint_layer(clip_bounds, |cx| {
cursor.paint(scene, origin, cx); cursor.paint(origin, cx);
}) })
} }
} }
if let Some(element) = &mut layout.hyperlink_tooltip { if let Some(element) = &mut layout.hyperlink_tooltip {
element.paint(scene, origin, visible_bounds, view, cx) element.paint(origin, visible_bounds, view, cx)
} }
}); });
} }

View File

@ -1440,10 +1440,10 @@ impl Pane {
None None
}; };
Canvas::new(move |scene, bounds, _, _, _| { Canvas::new(move |bounds, _, _, cx| {
if let Some(color) = icon_color { if let Some(color) = icon_color {
let square = RectF::new(bounds.origin(), vec2f(diameter, diameter)); let square = RectF::new(bounds.origin(), vec2f(diameter, diameter));
scene.push_quad(Quad { cx.scene().push_quad(Quad {
bounds: square, bounds: square,
background: Some(color), background: Some(color),
border: Default::default(), border: Default::default(),
@ -2007,7 +2007,6 @@ impl<V: 'static> Element<V> for PaneBackdrop<V> {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut gpui::SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -2018,14 +2017,14 @@ impl<V: 'static> Element<V> for PaneBackdrop<V> {
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds: RectF::new(bounds.origin(), bounds.size()), bounds: RectF::new(bounds.origin(), bounds.size()),
background: Some(background), background: Some(background),
..Default::default() ..Default::default()
}); });
let child_view_id = self.child_view; let child_view_id = self.child_view;
scene.push_mouse_region( cx.scene().push_mouse_region(
MouseRegion::new::<Self>(child_view_id, 0, visible_bounds).on_down( MouseRegion::new::<Self>(child_view_id, 0, visible_bounds).on_down(
gpui::platform::MouseButton::Left, gpui::platform::MouseButton::Left,
move |_, _: &mut V, cx| { move |_, _: &mut V, cx| {
@ -2035,10 +2034,9 @@ impl<V: 'static> Element<V> for PaneBackdrop<V> {
), ),
); );
scene.paint_layer(Some(bounds), |scene| { cx.scene().push_layer(Some(bounds));
self.child self.child.paint(bounds.origin(), visible_bounds, view, cx);
.paint(scene, bounds.origin(), visible_bounds, view, cx) cx.scene().pop_layer();
})
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -50,7 +50,7 @@ where
Stack::new() Stack::new()
.with_child(render_child(state, cx)) .with_child(render_child(state, cx))
.with_children(drag_position.map(|drag_position| { .with_children(drag_position.map(|drag_position| {
Canvas::new(move |scene, bounds, _, _, cx| { Canvas::new(move |bounds, _, _, cx| {
if bounds.contains_point(drag_position) { if bounds.contains_point(drag_position) {
let overlay_region = split_margin let overlay_region = split_margin
.and_then(|split_margin| { .and_then(|split_margin| {
@ -60,14 +60,15 @@ where
.map(|(dir, margin)| dir.along_edge(bounds, margin)) .map(|(dir, margin)| dir.along_edge(bounds, margin))
.unwrap_or(bounds); .unwrap_or(bounds);
scene.paint_stacking_context(None, None, |scene| { cx.scene().push_stacking_context(None, None);
scene.push_quad(Quad { let background = overlay_color(cx);
cx.scene().push_quad(Quad {
bounds: overlay_region, bounds: overlay_region,
background: Some(overlay_color(cx)), background: Some(background),
border: Default::default(), border: Default::default(),
corner_radii: Default::default(), corner_radii: Default::default(),
}); });
}); cx.scene().pop_stacking_context();
} }
}) })
})) }))

View File

@ -595,7 +595,7 @@ mod element {
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
scene::MouseDrag, scene::MouseDrag,
AnyElement, Axis, CursorRegion, Element, EventContext, LayoutContext, MouseRegion, AnyElement, Axis, CursorRegion, Element, EventContext, LayoutContext, MouseRegion,
PaintContext, RectFExt, SceneBuilder, SizeConstraint, Vector2FExt, ViewContext, PaintContext, RectFExt, SizeConstraint, Vector2FExt, ViewContext,
}; };
use crate::{ use crate::{
@ -851,7 +851,6 @@ mod element {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
remaining_space: &mut Self::LayoutState, remaining_space: &mut Self::LayoutState,
@ -863,7 +862,7 @@ mod element {
let overflowing = *remaining_space < 0.; let overflowing = *remaining_space < 0.;
if overflowing { if overflowing {
scene.push_layer(Some(visible_bounds)); cx.scene().push_layer(Some(visible_bounds));
} }
let mut child_origin = bounds.origin(); let mut child_origin = bounds.origin();
@ -874,7 +873,7 @@ mod element {
let mut children_iter = self.children.iter_mut().enumerate().peekable(); let mut children_iter = self.children.iter_mut().enumerate().peekable();
while let Some((ix, child)) = children_iter.next() { while let Some((ix, child)) = children_iter.next() {
let child_start = child_origin.clone(); let child_start = child_origin.clone();
child.paint(scene, child_origin, visible_bounds, view, cx); child.paint(child_origin, visible_bounds, view, cx);
bounding_boxes.push(Some(RectF::new(child_origin, child.size()))); bounding_boxes.push(Some(RectF::new(child_origin, child.size())));
@ -884,7 +883,7 @@ mod element {
} }
if can_resize && children_iter.peek().is_some() { if can_resize && children_iter.peek().is_some() {
scene.push_stacking_context(None, None); cx.scene().push_stacking_context(None, None);
let handle_origin = match self.axis { let handle_origin = match self.axis {
Axis::Horizontal => child_origin - vec2f(HANDLE_HITBOX_SIZE / 2., 0.0), Axis::Horizontal => child_origin - vec2f(HANDLE_HITBOX_SIZE / 2., 0.0),
@ -907,7 +906,7 @@ mod element {
Axis::Vertical => CursorStyle::ResizeUpDown, Axis::Vertical => CursorStyle::ResizeUpDown,
}; };
scene.push_cursor_region(CursorRegion { cx.scene().push_cursor_region(CursorRegion {
bounds: handle_bounds, bounds: handle_bounds,
style, style,
}); });
@ -940,14 +939,14 @@ mod element {
} }
} }
}); });
scene.push_mouse_region(mouse_region); cx.scene().push_mouse_region(mouse_region);
scene.pop_stacking_context(); cx.scene().pop_stacking_context();
} }
} }
if overflowing { if overflowing {
scene.pop_layer(); cx.scene().pop_layer();
} }
} }

View File

@ -73,14 +73,14 @@ impl View for SharedScreen {
let frame = self.frame.clone(); let frame = self.frame.clone();
MouseEventHandler::new::<Focus, _>(0, cx, |_, cx| { MouseEventHandler::new::<Focus, _>(0, cx, |_, cx| {
Canvas::new(move |scene, bounds, _, _, _| { Canvas::new(move |bounds, _, _, cx| {
if let Some(frame) = frame.clone() { if let Some(frame) = frame.clone() {
let size = constrain_size_preserving_aspect_ratio( let size = constrain_size_preserving_aspect_ratio(
bounds.size(), bounds.size(),
vec2f(frame.width() as f32, frame.height() as f32), vec2f(frame.width() as f32, frame.height() as f32),
); );
let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.; let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.;
scene.push_surface(gpui::platform::mac::Surface { cx.scene().push_surface(gpui::platform::mac::Surface {
bounds: RectF::new(origin, size), bounds: RectF::new(origin, size),
image_buffer: frame.image(), image_buffer: frame.image(),
}); });

View File

@ -8,8 +8,8 @@ use gpui::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::{json, ToJson}, json::{json, ToJson},
AnyElement, AnyViewHandle, Entity, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, AnyElement, AnyViewHandle, Entity, LayoutContext, PaintContext, SizeConstraint, Subscription,
Subscription, View, ViewContext, ViewHandle, WindowContext, View, ViewContext, ViewHandle, WindowContext,
}; };
pub trait StatusItemView: View { pub trait StatusItemView: View {
@ -226,7 +226,6 @@ impl Element<StatusBar> for StatusBarElement {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
@ -237,12 +236,10 @@ impl Element<StatusBar> for StatusBarElement {
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
let left_origin = vec2f(bounds.lower_left().x(), origin_y); let left_origin = vec2f(bounds.lower_left().x(), origin_y);
self.left self.left.paint(left_origin, visible_bounds, view, cx);
.paint(scene, left_origin, visible_bounds, view, cx);
let right_origin = vec2f(bounds.upper_right().x() - self.right.size().x(), origin_y); let right_origin = vec2f(bounds.upper_right().x() - self.right.size().x(), origin_y);
self.right self.right.paint(right_origin, visible_bounds, view, cx);
.paint(scene, right_origin, visible_bounds, view, cx);
} }
fn rect_for_text_range( fn rect_for_text_range(

View File

@ -3626,13 +3626,13 @@ fn notify_of_new_dock(workspace: &WeakViewHandle<Workspace>, cx: &mut AsyncAppCo
"Looking for the dock? Try ctrl-`!\nshift-escape now zooms your pane.", "Looking for the dock? Try ctrl-`!\nshift-escape now zooms your pane.",
text, text,
) )
.with_custom_runs(vec![26..32, 34..46], |_, bounds, scene, cx| { .with_custom_runs(vec![26..32, 34..46], |_, bounds, cx| {
let code_span_background_color = settings::get::<ThemeSettings>(cx) let code_span_background_color = settings::get::<ThemeSettings>(cx)
.theme .theme
.editor .editor
.document_highlight_read_background; .document_highlight_read_background;
scene.push_quad(gpui::Quad { cx.scene().push_quad(gpui::Quad {
bounds, bounds,
background: Some(code_span_background_color), background: Some(code_span_background_color),
border: Default::default(), border: Default::default(),