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.
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 ui_material : Material @auto
val drawable = Drawable
mesh = Mesh.from_memory memory@atom
material = ui_material
maybe_drawable = drawable
ui_material
field obtains its value automatically due to the @auto
attribute.
let ui_material @publish = app.drawer.materials.ui
let rectangle = Rectangle.new
ui_material
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 ui_material
binding would be required to call it.