Add porting plan and first pure slice: geometry, color, scene
docs/PORTING.md maps GPUI's architecture onto MoonBit packages, separates pure logic from platform code, surveys mooncakes packages and their backends, recommends a js + Canvas2D first backend behind a small Platform trait, lists the Rust idioms that need a different design, and gives an ordered roadmap. First slice (pure, tested on wasm, wasm-gc, js and native): - geometry: Pixels/ScaledPixels/DevicePixels/Rems, Absolute/Definite/Length with parsing, Point/Size/Bounds/Edges/Corners, Anchor, Axis, ContentMask - color: Rgba/Hsla with conversions, hex parsing, blending, Background (solid, linear gradient, patterns) - scene: primitives (Quad, Shadow, Path, Underline, sprites), transformation matrix, BoundsTree draw ordering, layers, finish/batches, replay Derived from Zed's GPUI (Apache-2.0); see LICENSE and NOTICE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9d1949688
commit
8c0685fe01
24 files changed
+5856
-1
No files matched your search
@@ -0,0 +1,358 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "experiments/gpui/geometry"
|
||||
|
||||
import {
|
||||
"moonbitlang/core/debug",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn auto() -> Length
|
||||
|
||||
pub fn[T] bounds(Point[T], Size[T]) -> Bounds[T]
|
||||
|
||||
pub fn percentage(Double) -> Percentage
|
||||
|
||||
pub fn phi() -> DefiniteLength
|
||||
|
||||
pub let pixels_max : Pixels
|
||||
|
||||
pub let pixels_min : Pixels
|
||||
|
||||
pub let pixels_zero : Pixels
|
||||
|
||||
pub fn[T] point(T, T) -> Point[T]
|
||||
|
||||
pub fn px(Double) -> Pixels
|
||||
|
||||
pub fn radians(Double) -> Radians
|
||||
|
||||
pub fn relative(Double) -> DefiniteLength
|
||||
|
||||
pub fn rems(Double) -> Rems
|
||||
|
||||
pub fn[T] size(T, T) -> Size[T]
|
||||
|
||||
// Errors
|
||||
#derive(@debug.Debug)
|
||||
pub suberror LengthParseError {
|
||||
LengthParseError(input~ : String, expected~ : String)
|
||||
}
|
||||
|
||||
// Types and methods
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) enum AbsoluteLength {
|
||||
Pixels(Pixels)
|
||||
Rems(Rems)
|
||||
}
|
||||
pub fn AbsoluteLength::is_zero(Self) -> Bool
|
||||
pub fn AbsoluteLength::parse(String) -> Self raise LengthParseError
|
||||
pub fn AbsoluteLength::to_definite(Self) -> DefiniteLength
|
||||
pub fn AbsoluteLength::to_pixels(Self, Pixels) -> Pixels
|
||||
pub fn AbsoluteLength::to_rems(Self, Pixels) -> Rems
|
||||
pub impl IsZero for AbsoluteLength
|
||||
pub impl Default for AbsoluteLength
|
||||
pub impl Show for AbsoluteLength
|
||||
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) enum Anchor {
|
||||
TopLeft
|
||||
TopRight
|
||||
BottomLeft
|
||||
BottomRight
|
||||
TopCenter
|
||||
BottomCenter
|
||||
LeftCenter
|
||||
RightCenter
|
||||
}
|
||||
pub fn Anchor::is_bottom(Self) -> Bool
|
||||
pub fn Anchor::is_center(Self) -> Bool
|
||||
pub fn Anchor::opposite(Self) -> Self
|
||||
pub fn Anchor::other_side_along(Self, Axis) -> Self
|
||||
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) enum Axis {
|
||||
Vertical
|
||||
Horizontal
|
||||
}
|
||||
pub fn Axis::invert(Self) -> Self
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Bounds[T] {
|
||||
origin : Point[T]
|
||||
size : Size[T]
|
||||
}
|
||||
pub fn[T : Add] Bounds::bottom(Self[T]) -> T
|
||||
pub fn[T : Add + Half] Bounds::bottom_center(Self[T]) -> Point[T]
|
||||
pub fn[T : Add] Bounds::bottom_left(Self[T]) -> Point[T]
|
||||
pub fn[T : Add] Bounds::bottom_right(Self[T]) -> Point[T]
|
||||
pub fn[T : Add + Half] Bounds::center(Self[T]) -> Point[T]
|
||||
pub fn[T : Sub + Half] Bounds::centered_at(Point[T], Size[T]) -> Self[T]
|
||||
pub fn[T : Add + Compare] Bounds::contains(Self[T], Point[T]) -> Bool
|
||||
pub fn[T : Add + Half] Bounds::corner(Self[T], Anchor) -> Point[T]
|
||||
pub fn[T : Add + Sub] Bounds::dilate(Self[T], T) -> Self[T]
|
||||
pub fn[T : Add + Sub] Bounds::extend_by(Self[T], Edges[T]) -> Self[T]
|
||||
pub fn[T : Sub + Half] Bounds::from_anchor_and_size(Anchor, Point[T], Size[T]) -> Self[T]
|
||||
pub fn[T : Sub] Bounds::from_corners(Point[T], Point[T]) -> Self[T]
|
||||
pub fn[T : Add] Bounds::half_perimeter(Self[T]) -> T
|
||||
pub fn[T : Add + Sub + Neg] Bounds::inset(Self[T], T) -> Self[T]
|
||||
pub fn[T : Add + Sub + Compare] Bounds::intersect(Self[T], Self[T]) -> Self[T]
|
||||
pub fn[T : Add + Compare] Bounds::intersects(Self[T], Self[T]) -> Bool
|
||||
pub fn[T : Add + Compare] Bounds::is_contained_within(Self[T], Self[T]) -> Bool
|
||||
pub fn[T : Compare + Default] Bounds::is_empty(Self[T]) -> Bool
|
||||
pub fn[T : Add + Sub + Compare + Default] Bounds::join(Self[T], Self[T]) -> Self[T]
|
||||
pub fn[T] Bounds::left(Self[T]) -> T
|
||||
pub fn[T : Add + Half] Bounds::left_center(Self[T]) -> Point[T]
|
||||
pub fn[T : Add + Sub + Compare] Bounds::localize(Self[T], Point[T]) -> Point[T]?
|
||||
pub fn[T, U] Bounds::map(Self[T], (T) -> U) -> Self[U]
|
||||
pub fn[T] Bounds::map_origin(Self[T], (T) -> T) -> Self[T]
|
||||
pub fn[T] Bounds::map_size(Self[T], (T) -> T) -> Self[T]
|
||||
pub fn[T : MulScalar] Bounds::mul_scalar(Self[T], Double) -> Self[T]
|
||||
pub fn[T] Bounds::new(Point[T], Size[T]) -> Self[T]
|
||||
pub fn[T : Add] Bounds::right(Self[T]) -> T
|
||||
pub fn[T : Add + Half] Bounds::right_center(Self[T]) -> Point[T]
|
||||
pub fn Bounds::scale(Self[Pixels], Double) -> Self[ScaledPixels]
|
||||
pub fn[T : Add + Sub] Bounds::space_within(Self[T], Self[T]) -> Edges[T]
|
||||
pub fn Bounds::to_device_pixels(Self[Pixels], Double) -> Self[DevicePixels]
|
||||
pub fn Bounds::to_pixels(Self[DevicePixels], Double) -> Self[Pixels]
|
||||
pub fn[T] Bounds::top(Self[T]) -> T
|
||||
pub fn[T : Add + Half] Bounds::top_center(Self[T]) -> Point[T]
|
||||
pub fn[T : Add] Bounds::top_right(Self[T]) -> Point[T]
|
||||
pub fn[T : Add] Bounds::translate(Self[T], Point[T]) -> Self[T]
|
||||
pub fn[T : Add + Sub + Compare] Bounds::union(Self[T], Self[T]) -> Self[T]
|
||||
pub impl[T : IsZero] IsZero for Bounds[T]
|
||||
pub impl[T : Show + Add] Show for Bounds[T]
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct ContentMask[T] {
|
||||
bounds : Bounds[T]
|
||||
}
|
||||
pub fn[T : Add + Sub + Compare] ContentMask::intersect(Self[T], Self[T]) -> Self[T]
|
||||
pub fn ContentMask::scale(Self[Pixels], Double) -> Self[ScaledPixels]
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Corners[T] {
|
||||
top_left : T
|
||||
top_right : T
|
||||
bottom_right : T
|
||||
bottom_left : T
|
||||
}
|
||||
pub fn Corners::absolute_to_pixels(Self[AbsoluteLength], Pixels) -> Self[Pixels]
|
||||
pub fn[T] Corners::all(T) -> Self[T]
|
||||
pub fn[T : Compare + Half] Corners::clamp_radii_for_quad_size(Self[T], Size[T]) -> Self[T]
|
||||
pub fn[T] Corners::corner(Self[T], Anchor) -> T
|
||||
pub fn[T, U] Corners::map(Self[T], (T) -> U) -> Self[U]
|
||||
pub fn Corners::max(Self[Pixels]) -> Pixels
|
||||
pub fn[T : MulScalar] Corners::mul_scalar(Self[T], Double) -> Self[T]
|
||||
pub fn[T] Corners::new(top_left~ : T, top_right~ : T, bottom_right~ : T, bottom_left~ : T) -> Self[T]
|
||||
pub fn Corners::scale(Self[Pixels], Double) -> Self[ScaledPixels]
|
||||
pub impl[T : IsZero] IsZero for Corners[T]
|
||||
pub impl[T : Mul] Mul for Corners[T]
|
||||
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) enum DefiniteLength {
|
||||
Absolute(AbsoluteLength)
|
||||
Fraction(Double)
|
||||
}
|
||||
pub fn DefiniteLength::is_zero(Self) -> Bool
|
||||
pub fn DefiniteLength::parse(String) -> Self raise LengthParseError
|
||||
pub fn DefiniteLength::to_length(Self) -> Length
|
||||
pub fn DefiniteLength::to_pixels(Self, AbsoluteLength, Pixels) -> Pixels
|
||||
pub impl IsZero for DefiniteLength
|
||||
pub impl Default for DefiniteLength
|
||||
pub impl Show for DefiniteLength
|
||||
|
||||
#derive(Compare, Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct DevicePixels(Int32)
|
||||
pub fn DevicePixels::half(Self) -> Self
|
||||
pub fn DevicePixels::is_zero(Self) -> Bool
|
||||
pub fn DevicePixels::to_bytes(Self, Int32) -> Int32
|
||||
pub fn DevicePixels::to_int(Self) -> Int32
|
||||
pub fn DevicePixels::to_scaled_pixels(Self) -> ScaledPixels
|
||||
pub impl Half for DevicePixels
|
||||
pub impl IsZero for DevicePixels
|
||||
pub impl Add for DevicePixels
|
||||
pub impl Mul for DevicePixels
|
||||
pub impl Neg for DevicePixels
|
||||
pub impl Show for DevicePixels
|
||||
pub impl Sub for DevicePixels
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Edges[T] {
|
||||
top : T
|
||||
right : T
|
||||
bottom : T
|
||||
left : T
|
||||
}
|
||||
pub fn Edges::absolute_to_pixels(Self[AbsoluteLength], Pixels) -> Self[Pixels]
|
||||
pub fn[T] Edges::all(T) -> Self[T]
|
||||
pub fn[T] Edges::along(Self[T], Axis) -> (T, T)
|
||||
pub fn[T] Edges::any(Self[T], (T) -> Bool) -> Bool
|
||||
pub fn[T] Edges::apply_along(Self[T], Axis, ((T, T)) -> (T, T)) -> Self[T]
|
||||
pub fn Edges::auto() -> Self[Length]
|
||||
pub fn Edges::definite_to_pixels(Self[DefiniteLength], Size[AbsoluteLength], Pixels) -> Self[Pixels]
|
||||
pub fn[T, U] Edges::map(Self[T], (T) -> U) -> Self[U]
|
||||
pub fn Edges::max(Self[Pixels]) -> Pixels
|
||||
pub fn[T : MulScalar] Edges::mul_scalar(Self[T], Double) -> Self[T]
|
||||
pub fn[T] Edges::new(top~ : T, right~ : T, bottom~ : T, left~ : T) -> Self[T]
|
||||
pub fn Edges::scale(Self[Pixels], Double) -> Self[ScaledPixels]
|
||||
pub fn Edges::zero_absolute() -> Self[AbsoluteLength]
|
||||
pub fn Edges::zero_definite() -> Self[DefiniteLength]
|
||||
pub fn Edges::zero_length() -> Self[Length]
|
||||
pub impl[T : IsZero] IsZero for Edges[T]
|
||||
pub impl[T : Add] Add for Edges[T]
|
||||
pub impl[T : Mul] Mul for Edges[T]
|
||||
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) enum Length {
|
||||
Definite(DefiniteLength)
|
||||
Auto
|
||||
}
|
||||
pub fn Length::is_zero(Self) -> Bool
|
||||
pub fn Length::parse(String) -> Self raise LengthParseError
|
||||
pub impl IsZero for Length
|
||||
pub impl Default for Length
|
||||
pub impl Show for Length
|
||||
|
||||
#derive(Compare, Default, Eq, @debug.Debug)
|
||||
pub(all) struct Percentage(Double)
|
||||
pub fn Percentage::to_radians(Self) -> Radians
|
||||
|
||||
#derive(Compare, Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Pixels(Double)
|
||||
pub fn Pixels::abs(Self) -> Self
|
||||
pub fn Pixels::ceil(Self) -> Self
|
||||
pub fn Pixels::floor(Self) -> Self
|
||||
pub fn Pixels::half(Self) -> Self
|
||||
pub fn Pixels::is_zero(Self) -> Bool
|
||||
pub fn Pixels::mul_scalar(Self, Double) -> Self
|
||||
pub fn Pixels::parse(String) -> Self raise LengthParseError
|
||||
pub fn Pixels::pow(Self, Double) -> Self
|
||||
pub fn Pixels::ratio(Self, Self) -> Double
|
||||
pub fn Pixels::round(Self) -> Self
|
||||
pub fn Pixels::scale(Self, Double) -> ScaledPixels
|
||||
pub fn Pixels::signum(Self) -> Double
|
||||
pub fn Pixels::sum(Array[Self]) -> Self
|
||||
pub fn Pixels::to_absolute(Self) -> AbsoluteLength
|
||||
pub fn Pixels::to_definite(Self) -> DefiniteLength
|
||||
pub fn Pixels::to_double(Self) -> Double
|
||||
pub fn Pixels::to_int(Self) -> Int32
|
||||
pub fn Pixels::to_length(Self) -> Length
|
||||
pub impl Half for Pixels
|
||||
pub impl IsZero for Pixels
|
||||
pub impl MulScalar for Pixels
|
||||
pub impl Add for Pixels
|
||||
pub impl Div for Pixels
|
||||
pub impl Mod for Pixels
|
||||
pub impl Mul for Pixels
|
||||
pub impl Neg for Pixels
|
||||
pub impl Show for Pixels
|
||||
pub impl Sub for Pixels
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Point[T] {
|
||||
x : T
|
||||
y : T
|
||||
}
|
||||
pub fn[T] Point::along(Self[T], Axis) -> T
|
||||
pub fn[T] Point::apply_along(Self[T], Axis, (T) -> T) -> Self[T]
|
||||
pub fn[T : Compare] Point::clamp(Self[T], Self[T], Self[T]) -> Self[T]
|
||||
pub fn Point::magnitude(Self[Pixels]) -> Double
|
||||
pub fn[T, U] Point::map(Self[T], (T) -> U) -> Self[U]
|
||||
pub fn[T : Compare] Point::max(Self[T], Self[T]) -> Self[T]
|
||||
pub fn[T : Compare] Point::min(Self[T], Self[T]) -> Self[T]
|
||||
pub fn[T : MulScalar] Point::mul_scalar(Self[T], Double) -> Self[T]
|
||||
pub fn[T] Point::new(T, T) -> Self[T]
|
||||
pub fn[T : Sub] Point::relative_to(Self[T], Self[T]) -> Self[T]
|
||||
pub fn Point::scale(Self[Pixels], Double) -> Self[ScaledPixels]
|
||||
pub fn[T] Point::to_size(Self[T]) -> Size[T]
|
||||
pub impl[T : IsZero] IsZero for Point[T]
|
||||
pub impl[T : Add] Add for Point[T]
|
||||
pub impl[T : Neg] Neg for Point[T]
|
||||
pub impl[T : Show] Show for Point[T]
|
||||
pub impl[T : Sub] Sub for Point[T]
|
||||
|
||||
#derive(Compare, Default, Eq, @debug.Debug)
|
||||
pub(all) struct Radians(Double)
|
||||
|
||||
#derive(Compare, Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Rems(Double)
|
||||
pub fn Rems::from_pixels(Pixels, Pixels) -> Self
|
||||
pub fn Rems::half(Self) -> Self
|
||||
pub fn Rems::is_zero(Self) -> Bool
|
||||
pub fn Rems::mul_scalar(Self, Double) -> Self
|
||||
pub fn Rems::parse(String) -> Self raise LengthParseError
|
||||
pub fn Rems::to_absolute(Self) -> AbsoluteLength
|
||||
pub fn Rems::to_definite(Self) -> DefiniteLength
|
||||
pub fn Rems::to_length(Self) -> Length
|
||||
pub fn Rems::to_pixels(Self, Pixels) -> Pixels
|
||||
pub impl Half for Rems
|
||||
pub impl IsZero for Rems
|
||||
pub impl MulScalar for Rems
|
||||
pub impl Add for Rems
|
||||
pub impl Neg for Rems
|
||||
pub impl Show for Rems
|
||||
pub impl Sub for Rems
|
||||
|
||||
#derive(Compare, Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct ScaledPixels(Double)
|
||||
pub fn ScaledPixels::ceil(Self) -> Self
|
||||
pub fn ScaledPixels::floor(Self) -> Self
|
||||
pub fn ScaledPixels::half(Self) -> Self
|
||||
pub fn ScaledPixels::is_zero(Self) -> Bool
|
||||
pub fn ScaledPixels::mul_scalar(Self, Double) -> Self
|
||||
pub fn ScaledPixels::round(Self) -> Self
|
||||
pub fn ScaledPixels::to_device_pixels(Self) -> DevicePixels
|
||||
pub fn ScaledPixels::to_double(Self) -> Double
|
||||
pub impl Half for ScaledPixels
|
||||
pub impl IsZero for ScaledPixels
|
||||
pub impl MulScalar for ScaledPixels
|
||||
pub impl Add for ScaledPixels
|
||||
pub impl Div for ScaledPixels
|
||||
pub impl Mul for ScaledPixels
|
||||
pub impl Neg for ScaledPixels
|
||||
pub impl Show for ScaledPixels
|
||||
pub impl Sub for ScaledPixels
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Size[T] {
|
||||
width : T
|
||||
height : T
|
||||
}
|
||||
pub fn[T] Size::along(Self[T], Axis) -> T
|
||||
pub fn[T] Size::apply_along(Self[T], Axis, (T) -> T) -> Self[T]
|
||||
pub fn Size::auto() -> Self[Length]
|
||||
pub fn[T : Half] Size::center(Self[T]) -> Point[T]
|
||||
pub fn Size::full() -> Self[Length]
|
||||
pub fn[T, U] Size::map(Self[T], (T) -> U) -> Self[U]
|
||||
pub fn[T : Compare] Size::max(Self[T], Self[T]) -> Self[T]
|
||||
pub fn[T : Compare] Size::min(Self[T], Self[T]) -> Self[T]
|
||||
pub fn[T : MulScalar] Size::mul_scalar(Self[T], Double) -> Self[T]
|
||||
pub fn[T] Size::new(T, T) -> Self[T]
|
||||
pub fn Size::scale(Self[Pixels], Double) -> Self[ScaledPixels]
|
||||
pub fn Size::to_device_pixels(Self[Pixels], Double) -> Self[DevicePixels]
|
||||
pub fn Size::to_pixels(Self[DevicePixels], Double) -> Self[Pixels]
|
||||
pub fn[T] Size::to_point(Self[T]) -> Point[T]
|
||||
pub impl[T : IsZero] IsZero for Size[T]
|
||||
pub impl[T : Add] Add for Size[T]
|
||||
pub impl[T : Show] Show for Size[T]
|
||||
pub impl[T : Sub] Sub for Size[T]
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
pub trait Half {
|
||||
fn half(Self) -> Self
|
||||
}
|
||||
pub impl Half for Int32
|
||||
pub impl Half for Double
|
||||
|
||||
pub trait IsZero {
|
||||
fn is_zero(Self) -> Bool
|
||||
}
|
||||
pub impl IsZero for Int32
|
||||
pub impl IsZero for Double
|
||||
|
||||
pub trait MulScalar {
|
||||
fn mul_scalar(Self, Double) -> Self
|
||||
}
|
||||
pub impl MulScalar for Double
|
||||
Reference in new issue
Block a user