Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-demos

Source of release 0.4.2

0.4.2 / src / ui_demo.luc

from luce_ui.ui import Application, Button, Text, VStack, HStack, Spacer
from luce_ui import ui

pub class Counter:
    let label: Text
    var count: int = 0

    pub func init(self, label: Text):
        self.label = label

    pub func increment(self) -> unit!:
        let count = self.count + 1
        self.label.set_text(f"Clicks {count}")
        self.count = count

pub func main(arguments: list[str]) -> int!:
    var smoke = false
    for argument in arguments:
        if argument == "--smoke":
            smoke = true
        else:
            error(ui.invalid, f"unknown option: {argument}")

    let label = Text("Clicks 0")
    let counter = Counter(label)
    let button = Button("Add one")
    let clicked = button.on_click(counter.increment)
    let content = VStack([
        Text("Luce UI"),
        HStack([button, label, Spacer()], spacing = 20.0),
        Text("Click the button or use Tab and Space"),
        Spacer()
    ], spacing = 20.0, padding = 24.0)
    let app = Application(content, title = "Luce UI", width = 760, height = 360)
    app.run(frame_limit = 12 if smoke else 0)
    clicked.disconnect()
    print("UI demo complete")
    return 0