M6 elements and window: Element/Render/views, headless Window, div, canvas

- input: mouse events, modifiers, dispatch phases.
- window: Element / AnyElement / IntoElement, Render / AnyView (entities
  render as elements), listener(), empty(); Window with the draw cycle
  (render, layout to fill the viewport, prepaint, paint, finish) and phase
  checks; content-mask / element-offset / opacity / element-id stacks;
  element state across frames (ElementStateKey); hitboxes, hit testing,
  occlusion; mouse dispatch (capture + bubble, stop_propagation); hover-
  and notify-driven invalidation of rendered views; painting: paint_quad
  with device-pixel snapping, drop/inset shadows, paint_path, paint_style
  (port of Style::paint).
- elements: div() (Styled, children, hover, mouse down/up/move/scroll,
  clicks with element state, occlude, overflow clipping, opacity) and
  canvas(); Styled extend lists generated by tools/gen_style.py.
- app: observe_notifications hook used by windows.
- Tests: end-to-end views -> scene, clicks, hover, invalidation, nested
  views, bubbling, occlusion, shadows/borders/clipping, canvas, resize,
  and aborts on misuse. The card example now renders a real view and
  simulates hover and click.
- Docs: PORTING.md M6 status and deviations; README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Opus 5.5 committed 2026-11-24 22:55:17 +00:00
1 parent eeab51348e
commit fbe4c081e6
24 files changed
+15532 -204

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
// `canvas()`, ported from gpui/src/elements/canvas.rs: an element laid out by
// its style that paints with a closure.
///|
/// An element that paints itself with a closure (GPUI: `Canvas`).
pub struct Canvas {
priv base_style : @style.StyleRefinement
priv prepaint_fn : (
@geometry.Bounds[@geometry.Pixels],
@window.Window,
@app.App,
) -> Unit
priv paint_fn : (@geometry.Bounds[@geometry.Pixels], @window.Window, @app.App) -> Unit
priv mut layout_style : @style.Style?
}
///|
/// A canvas that runs `paint` with its bounds during the paint phase, and
/// `prepaint` (if given) during prepaint. Size it with style methods, e.g.
/// `canvas(paint).size_full()`.
pub fn canvas(
paint : (@geometry.Bounds[@geometry.Pixels], @window.Window, @app.App) -> Unit,
prepaint~ : (@geometry.Bounds[@geometry.Pixels], @window.Window, @app.App) -> Unit = fn(
_,
_,
_,
) {
},
) -> Canvas {
{
base_style: @style.StyleRefinement::new(),
prepaint_fn: prepaint,
paint_fn: paint,
layout_style: None,
}
}
///|
pub impl @style.Styled for Canvas with fn style(self) {
self.base_style
}
///|
pub impl @window.IntoElement for Canvas with fn into_any_element(self) {
@window.AnyElement::new(self)
}
///|
pub extend Canvas with @window.IntoElement::{into_any_element}
///|
impl @window.Element for Canvas with fn request_layout(self, window, _app) {
let style = (Default::default() : @style.Style).refined(self.base_style)
self.layout_style = Some(style)
window.request_layout(style, [])
}
///|
impl @window.Element for Canvas with fn prepaint(self, bounds, window, app) {
(self.prepaint_fn)(bounds, window, app)
}
///|
impl @window.Element for Canvas with fn paint(self, bounds, window, app) {
guard self.layout_style is Some(style) else {
abort("canvas painted before layout")
}
window.paint_style(style, bounds, fn() {
(self.paint_fn)(bounds, window, app)
})
}