dymokomi/luce-ui
Source of release 0.19.1
0.19.1 / src / widgets / vstack.lucb
## The VStack container widget.
from luce_gpu import gpu
from theme import default_spacing
import interop
from luce_std import math
import ownership
import layout
import result
from layout import Widget, Layout, Size, Constraints, Event
from painter import Painter
## Children laid out in a column, `spacing` points apart inside `padding`, and
## aligned across the column by `alignment`. It draws nothing itself.
pub struct VStack: Widget:
let box: interop.Reference[Layout]
pub func init(children: const interop.Interface[Widget][], spacing: f64 = default_spacing,
padding: f64 = 0.0, alignment: layout.Alignment = layout.Alignment.stretch) -> !:
let box = try layout.make_layout(layout.Axis.vertical, spacing, padding, alignment)
errdefer box.release()
try box.value().set_children(children)
self.box = box
pub func layout() -> interop.Reference[Layout]:
return self.box.clone()
## Replace the children; see `Layout.set_children`.
pub func set_children(children: const interop.Interface[Widget][]) -> !:
try self.box.value().set_children(children)
pub func measure(available: Constraints) -> interop.Outcome[Size]:
let size = self.box.value().content_size(available) catch failure:
return result.failure[Size](failure.code, failure.message)
return result.success[Size](size)
pub func draw(target: interop.View[gpu.RenderTarget]) -> interop.Outcome[unit]:
return result.success[unit](())
pub func event(event: Event) -> interop.Outcome[unit]:
return result.success[unit](())
pub func close():
self.box.release()
func trace(visit: func(ownership.Object*, void*) -> unit, context: void*):
self.box.trace(visit, context)
pub let vstack_type: interop.Type[VStack] = interop.Type[VStack]("VStack", VStack.close, VStack.trace, closeable = true, main_thread = true)