Rectangle
type Rectangle =
inherit Control
val memory@atom = (width@atom, height@atom)
|> to_atom
|> map { w, h ->
let quad = Quad.create
up_left = Vector3 0 0 0
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.
to_atom
transforms a tuple of atoms into an atom of tuples.
@atom
modifier makes memory
binding have type MeshMemory
and not Atom<MeshMemory>
.
type Control
var maybe_drawable : Option<Drawable> @mut = 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 materials : Materials @auto
val drawable = Drawable
material = materials.ui
mesh = Mesh.from_memory memory@atom
maybe_drawable = drawable
materials
field obtains its value automatically due to the @auto
attribute. Later it is used to create the Drawable
object.
let materials @publish = app.drawer.materials
let rectangle = Rectangle.new
materials
is published to be passed into dependent objects and functions.
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 materials
object would be required to call it.