Rectangle
type Rectangle =
inherit Control
val memory@atom = (width@atom, height@atom)
|> to_atom
|> map { w, h ->
let quad = Quad.create
up_left = Vector3.new
up_right = Vector3 w.as<f32> 0 0
down_left = Vector3 0 h.as<f32> 0
down_right = Vector3 w.as<f32> h.as<f32> 0
MeshMemory.from_quad quad }
Rectangle contains a mesh, created according to its width and height.
type Control
var maybe_drawable : Option<Drawable> = None
A unit of code packaging is called crate.
Rectangle is defined in the control crate, responsible for the internal logic of controls. The last code fragment is located in the drawer crate, which displays user interface and depends on a specific renderer, part of which is Drawable.
type Rectangle
let material : ControlMaterial @auto
val drawable = Drawable
mesh = Mesh.from_memory memory@atom
material = material.unwrap
maybe_drawable = drawable
The material field obtains its value automatically due to the @auto attribute.
let material @publish = app.drawer.materials.control
let rectangle = Rectangle.new
The @publish attribute makes the value available to @auto bindings.
Automatic dependency propagation is not only a matter of reducing code complexity. Other crates may contain code that creates Rectangle, knowing nothing about the drawer. Such code will keep working, although a published material binding would be required to call it.