wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run

ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:31:34 +03:00
parent 5ffe50ed02
commit 19fcf60599
459 changed files with 17862 additions and 17603 deletions

View file

@ -12,13 +12,15 @@ program CombatKit {
model Hero { Position, Body, Collider, TopDown, Weapon, Faction, Stats, Dash, Melee }
model Creature { Position, Body, Collider, Faction, Stats, Foe }
model WorldRules { Solids }
var frames: int = 0
var hero: int = -1
state CombatKitState {
frames: int = 0
hero: int = -1
}
@On(MeleeHit) handler H { print(5000 + target) }
@On(Crit) handler C { print(6000) }
handler Tick phase Update {
frames += 1
if frames == 1 {
handler Tick(combat_kit_st: mut CombatKitState) phase Update {
combat_kit_st.frames += 1
if combat_kit_st.frames == 1 {
Map.size(20, 15)
Dungeon.arena(Dungeon.random_style(), '#', '.')
Dungeon.set_exit(Side.North, 'D')
@ -28,19 +30,19 @@ program CombatKit {
print(e.x * 1000 + e.y) # 153196
print(Dungeon.opposite(Side.West) * 10 + Dungeon.at_edge(IVec2.make(0, 3))) # 31
Weapon.def(name: "p", fire_rate: 10, damage: 10, speed: 8, spread: 0, pellets: 1, pattern: 0)
hero = spawn Hero { Position { x: 100, y: 100 }, Collider { w: 14, h: 20 }, Body { policy: 1 }, TopDown { move_speed: 4, aim_mode: AimMode.Manual, aim_angle: 0 }, Faction { id: 1 },
combat_kit_st.hero = spawn Hero { Position { x: 100, y: 100 }, Collider { w: 14, h: 20 }, Body { policy: 1 }, TopDown { move_speed: 4, aim_mode: AimMode.Manual, aim_angle: 0 }, Faction { id: 1 },
Stats { hp: 100, max_hp: 100 }, Dash { frames: 3, speed: 9, cooldown_frames: 5 }, Melee { range: 30, damage: 7, knockback: 4 } }
Stats.add(hero, StatKind.CritPct, 100)
Stats.add(hero, StatKind.DamagePct, 50)
let c = Collider.center(hero); print(c.x * 1000 + c.y) # 107110
Stats.add(combat_kit_st.hero, StatKind.CritPct, 100)
Stats.add(combat_kit_st.hero, StatKind.DamagePct, 50)
let c = Collider.center(combat_kit_st.hero); print(c.x * 1000 + c.y) # 107110
spawn Creature { Position { x: 120, y: 100 }, Collider { w: 14, h: 20 }, Body { policy: 1 }, Faction { id: 2 }, Stats { hp: 100, max_hp: 100, thorns: 3 }, Foe { n: 1 } }
Faction.set(1, 2, 2)
print(Melee.swing(hero)) # 1 hit (after 6000 and 5002)
print(Melee.swing(combat_kit_st.hero)) # 1 hit (after 6000 and 5002)
for (s, f) in query [Stats, Foe] { print(s.hp) } # 80: 7 * 150% doubled by the crit
print(Stats.of(hero).hp) # 97: thorns
print(Dash.start(hero, 0, 0) * 10 + Dash.active(hero)) # 11
print(Stats.of(combat_kit_st.hero).hp) # 97: thorns
print(Dash.start(combat_kit_st.hero, 0, 0) * 10 + Dash.active(combat_kit_st.hero)) # 11
print(Prefs.max("best", 5) * 10 + Prefs.max("best", 3)) # 10
}
if frames == 7 { print(700 + Dash.active(hero)); print(Position.of(hero).x); quit() } # 700 110
if combat_kit_st.frames == 7 { print(700 + Dash.active(combat_kit_st.hero)); print(Position.of(combat_kit_st.hero).x); quit() } # 700 110
}
}

View file

@ -10,30 +10,32 @@ program ComponentAccess {
model Player { Position, Hero }
model Thing { Position, Tag }
enum HeroState { Idle, Rolling, Swinging }
var hero_state: HeroState = HeroState.Rolling
var player: int = -1
var frames: int = 0
function step() -> void {
machine hero_state {
state ComponentAccessState {
hero_state: HeroState = HeroState.Rolling
player: int = -1
frames: int = 0
}
function step(component_access_st: mut ComponentAccessState) -> void {
machine component_access_st.hero_state {
state Idle { print(100); become Swinging }
state Rolling { print(101); become Idle }
state Swinging { print(102); become Rolling }
}
}
handler Tick phase Update {
frames += 1
if frames == 1 {
player = spawn Player { Position { x: 3, y: 4 }, Hero { roll_frames: 9, flash: 3 } }
handler Tick(component_access_st: mut ComponentAccessState) phase Update {
component_access_st.frames += 1
if component_access_st.frames == 1 {
component_access_st.player = spawn Player { Position { x: 3, y: 4 }, Hero { roll_frames: 9, flash: 3 } }
spawn Thing { Position { x: 30, y: 40 }, Tag { n: 7 } }
print(Hero.of(player).roll_frames) # 9
Hero.of(player).iframes = 20
Hero.of(player).iframes -= 5
print(Hero.of(player).iframes) # 15
let hero = Hero.of(player)
print(Hero.of(component_access_st.player).roll_frames) # 9
Hero.of(component_access_st.player).iframes = 20
Hero.of(component_access_st.player).iframes -= 5
print(Hero.of(component_access_st.player).iframes) # 15
let hero = Hero.of(component_access_st.player)
hero.roll_frames += 1
print(Hero.of(player).roll_frames) # 10
print(Position.of(player).x + Position.of(1).x) # 33
print(Hero.has(player)) # 1
print(Hero.of(component_access_st.player).roll_frames) # 10
print(Position.of(component_access_st.player).x + Position.of(1).x) # 33
print(Hero.has(component_access_st.player)) # 1
print(Hero.has(1)) # 0
print(Hero.has(-1)) # 0
print(Tag.has(1)) # 1
@ -42,13 +44,13 @@ program ComponentAccess {
print(Position.count()) # 1: the player
spawn Thing { Position { x: 1 } }
}
if frames == 2 {
step(); step(); step() # 101 100 102
print(hero_state) # 1
if component_access_st.frames == 2 {
step(component_access_st); step(component_access_st); step(component_access_st) # 101 100 102
print(component_access_st.hero_state) # 1
print(Position.count()) # 2: the player and the thing spawned after
}
if frames == 3 {
print(Hero.of(player).flash) # ticked twice: 1
if component_access_st.frames == 3 {
print(Hero.of(component_access_st.player).flash) # ticked twice: 1
Position.despawn_all()
print(Position.count()) # 0
quit()

View file

@ -17,19 +17,21 @@ program GameplayFoundation {
# a game-supplied policy: while "enraged" is set, halve incoming damage by
# rewriting the pending amount (lever 6, the mutable hook), and hard-veto any
# hit over 100 (lever 4, cancel). Both are just listeners — no engine fork.
var enraged: int = 0
@On(DamageAboutToApply) handler Ward {
state GameplayFoundationState {
enraged: int = 0
deaths: int = 0
}
@On(DamageAboutToApply) handler Ward(gameplay_foundation_st: GameplayFoundationState) {
if amount > 100 { cancel }
if enraged == 1 { Combat.set_amount(amount / 2) }
if gameplay_foundation_st.enraged == 1 { Combat.set_amount(amount / 2) }
}
var deaths: int = 0
@On(Died) handler Tally { deaths += 1 }
@On(Died) handler Tally(gameplay_foundation_st: mut GameplayFoundationState) { gameplay_foundation_st.deaths += 1 }
function tick_n(n: int) -> void { var i = 0; while i < n { tick_fixed(); i += 1 } }
function bi(b: bool) -> int { if b { return 1 }; return 0 }
entry {
entry (gameplay_foundation_st: mut GameplayFoundationState) {
let PS = World.prop_id("Stats")
let fhp = World.field_id(PS, "hp")
let fatk = World.field_id(PS, "atk")
@ -65,9 +67,9 @@ program GameplayFoundation {
print(World.get(t, PS, fhp)) # 85
# mutable hook: enrage halves the next hit ((20 - 5) -> 7)
enraged = 1
gameplay_foundation_st.enraged = 1
print(Combat.damage(t, a, 20)) # 7
enraged = 0
gameplay_foundation_st.enraged = 0
# veto hook: an over-100 hit is cancelled (0 applied)
print(bi(Combat.damage(t, a, 200) == 0)) # 1
@ -75,7 +77,7 @@ program GameplayFoundation {
# finish it off with sub-100 hits so the veto never blocks the kill
var guard = 0
while (World.get(t, PS, fhp) > 0) and (guard < 100) { Combat.damage(t, a, 90); guard += 1 }
print(deaths) # 1
print(gameplay_foundation_st.deaths) # 1
quit()
}

View file

@ -12,9 +12,11 @@ program InputAuto {
property Tag { n: int = 0 }
model Player { Tag }
var hits: int = 0
state InputAutoState {
hits: int = 0
}
@OnStart handler Boot { Input.action("go", 'l') } # 'l' == 108
handler Sense phase Update { if Input.active("go") { hits += 1 } }
@OnQuit handler Report { print(hits) }
handler Sense(input_auto_st: mut InputAutoState) phase Update { if Input.active("go") { input_auto_st.hits += 1 } }
@OnQuit handler Report(input_auto_st: InputAutoState) { print(input_auto_st.hits) }
}

View file

@ -8,10 +8,12 @@ program Managers {
property Tag { n: int = 0 }
model Thing { Position, Body, Sprite, Tag, TopDown }
model WorldRules { Solids }
var frames: int = 0
handler Tick phase Update {
frames += 1
if frames == 1 {
state ManagersState {
frames: int = 0
}
handler Tick(managers_st: mut ManagersState) phase Update {
managers_st.frames += 1
if managers_st.frames == 1 {
Map.size(10, 8)
Map.fill(glyph: '.')
Map.border(glyph: '#')
@ -36,7 +38,7 @@ program Managers {
Fx.number(x: 20, y: 20, value: 42, color: 0xffff00)
spawn Thing { Position { x: 20, y: 20 }, Sprite { id: 5, move_id: 9, face: 1, flash: 3, blink: 6 }, TopDown { want_x: -1 } }
}
if frames == 3 { print(Map.is_solid(x: 0, y: 0) * 10 + Map.is_solid_at(x: 40, y: 40)) } # 10
if frames == 5 { for (s, t) in query [Sprite, Tag] { print(s.flip * 100 + s.flash * 10 + s.blink) }; quit() } # 102
if managers_st.frames == 3 { print(Map.is_solid(x: 0, y: 0) * 10 + Map.is_solid_at(x: 40, y: 40)) } # 10
if managers_st.frames == 5 { for (s, t) in query [Sprite, Tag] { print(s.flip * 100 + s.flash * 10 + s.blink) }; quit() } # 102
}
}

View file

@ -8,9 +8,11 @@ program Prefabs {
model Creature { Position, Enemy }
prefab Foe: Creature { Enemy { team: 2, hp: 1 }, Position { y: 9 } }
prefab Grunt: Foe { Enemy { kind: 1, hp: 30 } }
var last: int = -1
@OnSpawn(Creature) handler Remember { last = self() }
entry {
state PrefabsState {
last: int = -1
}
@OnSpawn(Creature) handler Remember(prefabs_st: mut PrefabsState) { prefabs_st.last = self() }
entry (prefabs_st: PrefabsState) {
let g = spawn Grunt { Position { x: 5 } } # Foe's presets, Grunt's, then this
print(Enemy.of(g).team * 100000 + Enemy.of(g).hp * 1000 + Enemy.of(g).kind * 100 + Position.of(g).x * 10 + Position.of(g).y)
let n = Prefab.spawn(name: "Grunt")
@ -20,6 +22,6 @@ program Prefabs {
print(Position.of(placed).x)
print(Position.of(placed).y)
print(Prefab.spawn(name: "Nope")) # no such prefab
print(last) # self() in the hook: the last spawn
print(prefabs_st.last) # self() in the hook: the last spawn
}
}

View file

@ -6,8 +6,10 @@ program SceneMenus {
import "ludic.core/components.ludic"
property Pos { x: int = 0 }
model Thing { Pos }
var menu_font: int = 0
var frames: int = 0
let menu_font: int = 0
state SceneMenusState {
frames: int = 0
}
ui Menu {
panel id: Root w: 100 pad: 4 bg: Color.Gunmetal border: Color.SlateGray align: center {
button id: Go text: "Go" font: menu_font size: 16 w: 80 goto: Play
@ -17,7 +19,7 @@ program SceneMenus {
scene Title shows Menu {
on enter { print(200) }
on exit { print(202) }
layer L { handler Tick phase Update { frames += 1; if frames == 1 { print(201); emit UiClicked(id: UI_Go) } } }
layer L { handler Tick(scene_menus_st: mut SceneMenusState) phase Update { scene_menus_st.frames += 1; if scene_menus_st.frames == 1 { print(201); emit UiClicked(id: UI_Go) } } }
}
@On(UiClicked) handler Report { print(id) } # UI_Go is widget 1 (the root panel is 0)
scene Play {

View file

@ -10,23 +10,25 @@
program SpriteAtlas {
import "ludic.core/components.ludic"
var TALL: int = 0
state SpriteAtlasState {
TALL: int = 0
}
function bi(b: bool) -> int { if b { return 1 }; return 0 }
@OnStart handler Boot {
@OnStart handler Boot(sprite_atlas_st: mut SpriteAtlasState) {
let sheet = Sprite.sheet("assets/kenney/tiny-dungeon/Tilemap/tilemap_packed.png", 16, 16)
TALL = Sprite.cell_span(sheet, 0, 0, 1, 2) # a 16x32 sprite: two cells tall
spawn Tall { Position { x: 40, y: 40 }, Sprite { id: TALL, atlas: 1 } }
spawn Tinted { Position { x: 100, y: 40 }, Sprite { id: TALL, atlas: 1, tint: 0xff0000 } }
spawn Table { Position { x: 160, y: 40 }, Sprite { id: TALL } } # atlas: 0 -> the (empty) 16x16 table
sprite_atlas_st.TALL = Sprite.cell_span(sheet, 0, 0, 1, 2) # a 16x32 sprite: two cells tall
spawn Tall { Position { x: 40, y: 40 }, Sprite { id: sprite_atlas_st.TALL, atlas: 1 } }
spawn Tinted { Position { x: 100, y: 40 }, Sprite { id: sprite_atlas_st.TALL, atlas: 1, tint: 0xff0000 } }
spawn Table { Position { x: 160, y: 40 }, Sprite { id: sprite_atlas_st.TALL } } # atlas: 0 -> the (empty) 16x16 table
}
# An empty Render handler: the engine sprite system draws the Sprite entities.
handler Draw phase Render { }
@OnQuit handler Report {
print(Sprite.height(TALL)) # 32 — the span is two cells tall
@OnQuit handler Report(sprite_atlas_st: SpriteAtlasState) {
print(Sprite.height(sprite_atlas_st.TALL)) # 32 — the span is two cells tall
var top = 0
for yy in 40 .. 56 { for xx in 40 .. 56 { if Screen.pixel(xx, yy) != 0 { top = 1 } } }

View file

@ -9,12 +9,14 @@
program SpriteRender {
import "ludic.core/components.ludic"
var HERO: int = 0
state SpriteRenderState {
HERO: int = 0
}
@OnStart handler Boot {
HERO = png_load("assets/kenney/tiny-dungeon/Tiles/tile_0096.png")
spawn Shown { Position { x: 40, y: 40 }, Sprite { id: HERO } }
spawn Hidden { Position { x: 100, y: 40 }, Sprite { id: HERO, hidden: 1 } }
@OnStart handler Boot(sprite_render_st: mut SpriteRenderState) {
sprite_render_st.HERO = png_load("assets/kenney/tiny-dungeon/Tiles/tile_0096.png")
spawn Shown { Position { x: 40, y: 40 }, Sprite { id: sprite_render_st.HERO } }
spawn Hidden { Position { x: 100, y: 40 }, Sprite { id: sprite_render_st.HERO, hidden: 1 } }
}
# An empty Render handler: the engine sprite system draws the Sprite entities.

View file

@ -6,25 +6,27 @@
program Threads {
const N: int = 20000
var calls: int = 0 # an atomic handle, made on the main thread before any work
var lock: int = 0 # a mutex handle
var total: long = 0 # guarded by `lock`
state ThreadsState {
calls: int = 0 # an atomic handle, made on the main thread before any work
lock: int = 0 # a mutex handle
total: long = 0 # guarded by `lock`
}
# out[i] = i * i: every index written exactly once, by whichever thread claimed it
function square(i: int, out: words) -> void { out[i] = i * i }
# count the call atomically, and add i to a shared total under the mutex
function tally(i: int, ctx: pointer) -> void {
Sync.add(calls, 1)
Sync.lock(lock)
total = total + i
Sync.unlock(lock)
function tally(threads_st: mut ThreadsState, i: int, ctx: pointer) -> void {
Sync.add(threads_st.calls, 1)
Sync.lock(threads_st.lock)
threads_st.total = threads_st.total + i
Sync.unlock(threads_st.lock)
}
# remember which calls ran on a pool thread
function placed(i: int, out: words) -> void { if Job.is_worker() { out[i] = 1 } else { out[i] = 0 } }
entry {
entry (threads_st: mut ThreadsState) {
if Sync.cpu_count() >= 1 { print(1) }
if not Job.is_worker() { print(2) }
@ -34,12 +36,12 @@ program Threads {
for i in 0 .. N { if sq[i] != i * i { right = false } }
if right { print(3) }
calls = Sync.atomic()
lock = Sync.mutex()
threads_st.calls = Sync.atomic()
threads_st.lock = Sync.mutex()
Job.parallel_for(N, fn tally, null)
if Sync.get(calls) == N { print(4) }
if Sync.get(threads_st.calls) == N { print(4) }
let want: long = N * (N - 1) / 2
if total == want { print(5) }
if threads_st.total == want { print(5) }
let ran = words(N)
Job.parallel_for(N, fn placed, ran)

View file

@ -4,24 +4,26 @@
import "ludic.ui"
program UiAnim {
numbers float
var dim: bool = false
view Anim {
dim = dim
state UiAnimState {
dim: bool = false
}
view Anim (ui_anim_st: UiAnimState) {
dim = ui_anim_st.dim
}
const PAGE: string = "<ui><style>@keyframes fade { from { opacity: 0 } to { opacity: 1 } }\n@keyframes pulse { from { opacity: 1 } to { opacity: 0.5 } }\n.in { animation: fade 1s }\n.beat { animation: pulse 0.5s infinite alternate }\n.soft { transition: opacity 1s }\n.dim { opacity: 0.2 }</style><screen name='a'><p class='in'>a</p><p class='beat'>b</p><p class=\"soft {dim ? 'dim' : ''}\">c</p></screen></ui>"
function at() -> string {
ui_show("a", view_anim(), 0.0, 0.0, 200.0, 200.0)
let r: UiNode = ui_nodes("a", view_anim())
function at(ui_st: mut UiState) -> string {
ui_show(ui_st, "a", view_anim(), 0.0, 0.0, 200.0, 200.0)
let r: UiNode = ui_nodes(ui_st, "a", view_anim())
return `{int(r.children[0].alpha * 100.0)} {int(r.children[1].alpha * 100.0)} {int(r.children[2].alpha * 100.0)}`
}
entry {
ui_load_text(PAGE, "a.xml")
var out = at()
for i in 0 .. 29 { at() }
out = out + " | " + at()
dim = true
for i in 0 .. 29 { at() }
out = out + " | " + at()
entry (ui_anim_st: mut UiAnimState, ui_st: mut UiState) {
ui_load_text(ui_st, PAGE, "a.xml")
var out = at(ui_st)
for i in 0 .. 29 { at(ui_st) }
out = out + " | " + at(ui_st)
ui_anim_st.dim = true
for i in 0 .. 29 { at(ui_st) }
out = out + " | " + at(ui_st)
print(out)
}
}

View file

@ -6,14 +6,14 @@ program UiBox {
numbers float
const PAGE: string = "<ui><style>.side { width: 100px; height: 60px; margin: 10px }</style><screen name='b'><p>title</p><div id='panel' class='side'/></screen></ui>"
function scale() -> float { return 1.5 }
entry {
entry (ui_st: mut UiState) {
let b = new UiBackend
b.scale = fn scale
ui_backend(b)
ui_load_text(PAGE, "b.xml")
ui_show("b", null, 20.0, 30.0, 800.0, 600.0)
let p = ui_box("panel")
let none = ui_box("nothing")
print(`scale {ui_scale()} | panel {int(p.x)},{int(p.y)} {int(p.w)}x{int(p.h)} | missing {none == null}`)
ui_backend(ui_st, b)
ui_load_text(ui_st, PAGE, "b.xml")
ui_show(ui_st, "b", null, 20.0, 30.0, 800.0, 600.0)
let p = ui_box(ui_st, "panel")
let none = ui_box(ui_st, "nothing")
print(`scale {ui_scale(ui_st)} | panel {int(p.x)},{int(p.y)} {int(p.w)}x{int(p.h)} | missing {none == null}`)
}
}

View file

@ -6,11 +6,11 @@ import "ludic.ui"
import "ui_boxes_parts/Boxes.ludic"
program UiBoxes {
numbers float
entry {
ui_backend(new UiBackend)
ui_show("Boxes", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes("Boxes", null)
ui_place(root, 0.0, 0.0, 400.0, 600.0)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_show(ui_st, "Boxes", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes(ui_st, "Boxes", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 600.0)
let page = root.children[0]
let list = page.children[0].children[1]
let line = page.children[1]

View file

@ -5,12 +5,12 @@ program UiCalc {
numbers float
const STYLE: string = "<style>.a { width: min(300px, 50vw) }\n.b { width: max(10px, calc(5em + 2px)) }\n.c { width: clamp(50px, 10vw, 100px) }\n.d { height: calc(clamp(1px, 2em, 20px) + 1px) }\n.box { width: 300px; height: 200px; position: relative }\n.p { position: absolute; left: 50%; top: calc(25% + 10px); width: 20px; height: 20px }\n.q { position: absolute; right: calc(10% - 5px); bottom: 50%; width: 20px; height: 20px }\n.r { position: relative; left: 10%; width: 20px; height: 20px }</style>"
const BODY: string = "<screen name='c'><div class='a'/><div class='b'/><div class='c'/><div class='d'/><div class='box'><div class='p'/><div class='q'/><div class='r'/></div></screen>"
entry {
ui_backend(new UiBackend)
ui_load_text("<ui>" + STYLE + BODY + "</ui>", "c.xml")
ui_show("c", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes("c", null)
ui_place(r, 0.0, 0.0, 400.0, 600.0)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_load_text(ui_st, "<ui>" + STYLE + BODY + "</ui>", "c.xml")
ui_show(ui_st, "c", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes(ui_st, "c", null)
ui_place(ui_st, r, 0.0, 0.0, 400.0, 600.0)
let box = r.children[4]
let p = box.children[0]
let q = box.children[1]

View file

@ -11,18 +11,18 @@ program UiComponent {
if n.text != "" { push(out, n.text) }
for i in 0 .. len(n.children) { texts(n.children[i], out) }
}
function frame() -> UiNode {
let root: UiNode = ui_nodes("App", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState) -> UiNode {
let root: UiNode = ui_nodes(ui_st, "App", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
entry {
var root = frame()
entry (ui_st: mut UiState) {
var root = frame(ui_st)
let b = root.children[0].children[2]
ui_press(b.children[1])
ui_press(b.children[1])
ui_press(root.children[0].children[1].children[1])
root = frame()
ui_press(ui_st, b.children[1])
ui_press(ui_st, b.children[1])
ui_press(ui_st, root.children[0].children[1].children[1])
root = frame(ui_st)
let out = new []string
texts(root, out)
var joined = ""
@ -30,8 +30,8 @@ program UiComponent {
print(joined)
let b2 = root.children[0].children[2]
print(`b margin {int(b2.mt)}; b text {b2.children[0].fg}; outside {root.children[0].children[3].fg}; button {int(b2.children[1].ch)}`)
ui_press(b2.children[2])
root = frame()
ui_press(ui_st, b2.children[2])
root = frame(ui_st)
print(root.children[0].children[2].children[0].text)
}
}

View file

@ -6,11 +6,11 @@ import "ludic.ui"
import "ui_controls_parts/Settings.ludic"
program UiControls {
numbers float
function frame(i: UiInput) -> UiNode {
ui_input(i)
ui_show("Settings", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Settings", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Settings", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Settings", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
function press(tab: bool, down: bool, right: bool, enter: bool) -> UiInput {
@ -26,30 +26,30 @@ program UiControls {
let last = page.children[len(page.children) - 1]
return last.text
}
entry {
ui_backend(new UiBackend)
var root = frame(new UiInput)
root = frame(press(true, false, false, false))
root = frame(press(false, false, false, true))
root = frame(press(false, true, false, false))
root = frame(press(false, false, false, true))
root = frame(press(false, true, false, false))
root = frame(press(false, false, true, false))
root = frame(press(false, false, true, false))
root = frame(press(false, true, false, false))
root = frame(press(false, false, true, false))
root = frame(press(false, true, false, false))
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
var root = frame(ui_st, new UiInput)
root = frame(ui_st, press(true, false, false, false))
root = frame(ui_st, press(false, false, false, true))
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, false, true))
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, true, false))
root = frame(ui_st, press(false, false, true, false))
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, true, false))
root = frame(ui_st, press(false, true, false, false))
let typed = new UiInput
typed.typed = "lovelace"
root = frame(typed)
root = frame(ui_st, typed)
let back = new UiInput
back.backspace = true
root = frame(back)
root = frame(press(false, true, false, false))
root = frame(press(false, false, false, true))
root = frame(ui_st, back)
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, false, true))
let k = new UiInput
k.key = 70
root = frame(k)
root = frame(ui_st, k)
print(state(root))
let range = root.children[0].children[2]
let track = range.children[1]
@ -57,15 +57,15 @@ program UiControls {
at.x = track.x + track.cw * 0.8
at.y = track.y + 2.0
at.down = true
root = frame(at)
root = frame(new UiInput)
root = frame(ui_st, at)
root = frame(ui_st, new UiInput)
let list = root.children[0].children[6]
let w = new UiInput
w.x = list.x + 5.0
w.y = list.y + 5.0
w.wheel = -1.0
root = frame(w)
root = frame(new UiInput)
root = frame(ui_st, w)
root = frame(ui_st, new UiInput)
print(`{state(root)}; scrolled {int(root.children[0].children[6].scroll_y)}`)
}
}

View file

@ -9,12 +9,12 @@ program UiCss {
}
const LOOK: string = "screen { --gap: 6px; --accent: #ff8800 }\n.panel { position: relative; width: 300px; height: 200px; padding: 10px }\n.badge { position: absolute; right: 5px; bottom: 5px; width: 40px; height: 20px; background: var(--accent) }\n.corner { position: fixed; left: 0; top: 0; width: 10vw; height: 2rem }\n.nudge { position: relative; left: 7px; top: 3px }\n.big { font-size: 2em }\n.missing { color: var(--nope, #00ff00) }\n@media (max-width: 500px) { .wide-only { display: none } }\n@media (min-width: 500px) { .narrow-only { display: none } }\nli + li { margin-top: var(--gap) }\nh3 ~ p { color: var(--accent) }\nli:nth-child(2n+1) { color: #0000ff }\ninput:checked { opacity: 0.25 }\n.list { overflow: auto; height: 50px }\n.para { width: 120px }\n"
const PAGE: string = "<ui>\n<import src='look.lss'/>\n<screen name='css'>\n <div class='panel'><span class='badge'>!</span><p class='nudge'>moved</p><p class='big'>big</p></div>\n <div class='corner'/>\n <p class='wide-only'>wide</p><p class='narrow-only'>narrow</p>\n <ul><li>a</li><li>b</li><li>c</li></ul>\n <h3>h</h3><p>after</p><p class='missing'>fallback</p>\n <input type='checkbox' checked='true'/>\n <div class='list'><p>1</p><p>2</p><p>3</p><p>4</p></div>\n <p class='para'>a sentence long enough that it has to wrap onto several lines</p>\n</screen>\n</ui>\n"
entry {
ui_load_text(LOOK, "ui/look.lss")
ui_load_text(PAGE, "ui/css.xml")
ui_viewport(400.0, 300.0)
let root: UiNode = ui_nodes("css", view_css())
ui_place(root, 0.0, 0.0, 400.0, 300.0)
entry (ui_st: mut UiState) {
ui_load_text(ui_st, LOOK, "ui/look.lss")
ui_load_text(ui_st, PAGE, "ui/css.xml")
ui_viewport(ui_st, 400.0, 300.0)
let root: UiNode = ui_nodes(ui_st, "css", view_css())
ui_place(ui_st, root, 0.0, 0.0, 400.0, 300.0)
let panel = root.children[0]
let badge = panel.children[0]
let ul = root.children[3]

View file

@ -4,30 +4,32 @@
import "ludic.ui"
program UiEase {
numbers float
var dim: bool = false
var now: float = 0.0
view Ease {
dim = dim
state UiEaseState {
dim: bool = false
now: float = 0.0
}
view Ease (ui_ease_st: UiEaseState) {
dim = ui_ease_st.dim
}
const STYLE: string = "<style>@keyframes slide { from { left: 0 } to { left: 37 } }\n.go { animation: slide 0.25s }\n.soft { transition: opacity 0.25s }\n.dim { opacity: 0.2 }</style>"
const BODY: string = "<p class='go'>a</p><p class=\"soft {dim ? 'dim' : ''}\">b</p><p class='dim'>c</p></screen>"
function clock() -> float { return now }
function nodes(name: string) -> UiNode {
ui_show(name, view_ease(), 0.0, 0.0, 200.0, 200.0)
return ui_nodes(name, view_ease())
function clock(ui_ease_st: UiEaseState) -> float { return ui_ease_st.now }
function nodes(ui_st: mut UiState, name: string) -> UiNode {
ui_show(ui_st, name, view_ease(), 0.0, 0.0, 200.0, 200.0)
return ui_nodes(ui_st, name, view_ease())
}
# one rate, on its own screen: the slide from its first frame, the fade from half a second in
function at_rate(hz: int) -> string {
function at_rate(ui_ease_st: mut UiEaseState, ui_st: mut UiState, hz: int) -> string {
let name = `r{hz}`
dim = false
ui_ease_st.dim = false
var mid = ""
var slid = false
var landed = false
var over = false
for k in 0 .. hz + 1 {
now = float(k) / float(hz)
if k == hz / 2 { dim = true }
let r = nodes(name)
ui_ease_st.now = float(k) / float(hz)
if k == hz / 2 { ui_ease_st.dim = true }
let r = nodes(ui_st, name)
let go = r.children[0]
let soft = r.children[1]
let want = r.children[2].alpha
@ -39,17 +41,17 @@ program UiEase {
}
return `{hz}: {mid} slid {slid} landed {landed} left {over}`
}
entry {
ui_backend(new UiBackend)
ui_clock(fn clock)
entry (ui_ease_st: mut UiEaseState, ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_clock(ui_st, fn clock)
var page = "<ui>" + STYLE
for i in 0 .. 4 {
let hz = 60 * (i + 1)
page = page + `<screen name='r{hz}'>` + BODY
}
ui_load_text(page + "</ui>", "e.xml")
ui_load_text(ui_st, page + "</ui>", "e.xml")
var out = ""
for i in 0 .. 4 { out = out + at_rate(60 * (i + 1)) + "; " }
for i in 0 .. 4 { out = out + at_rate(ui_ease_st, ui_st, 60 * (i + 1)) + "; " }
print(out)
}
}

View file

@ -4,21 +4,23 @@
import "ludic.ui"
program UiFill {
numbers float
var rects: []string = new []string
var pics: []string = new []string
var clips: int = 0
state UiFillState {
rects: []string = new []string
pics: []string = new []string
clips: int = 0
}
const STYLE: string = "<style>.g { width: 100px; height: 20px; background: linear-gradient(to right, #000000, #ffffff) }\n.h { width: 50px; height: 40px; background-image: linear-gradient(180deg, #ff0000 0%, #0000ff 50%, #0000ff) }\nimg { width: 100px; height: 100px }\n.contain { object-fit: contain }\n.cover { object-fit: cover }\n.r { width: 160px; aspect-ratio: 16 / 9 }\nknob { height: 30px; aspect-ratio: 2 }</style>"
const BODY: string = "<screen name='f'><div class='g'/><div class='h'/><img class='contain' src='wide.png'/><img class='cover' src='wide.png'/><div class='r'/><row><knob/></row></screen>"
function rec_rect(x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(rects, `{int(x)},{int(y)} {int(w)}x{int(h)} {ui_hex(c)}`) }
function rec_image(src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(pics, `{int(x)},{int(y)} {int(w)}x{int(h)}`) }
function rec_clip(x: float, y: float, w: float, h: float) -> void { clips += 1 }
function rec_rect(ui_fill_st: mut UiFillState, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(ui_fill_st.rects, `{int(x)},{int(y)} {int(w)}x{int(h)} {ui_hex(c)}`) }
function rec_image(ui_fill_st: mut UiFillState, src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(ui_fill_st.pics, `{int(x)},{int(y)} {int(w)}x{int(h)}`) }
function rec_clip(ui_fill_st: mut UiFillState, x: float, y: float, w: float, h: float) -> void { ui_fill_st.clips += 1 }
function no_clip() -> void { }
function no_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { }
function nat_w(src: string) -> float { return 200.0 }
function nat_h(src: string) -> float { return 100.0 }
function knob_measure(n: UiNode, avail: float) -> void { }
function knob_draw(n: UiNode) -> void { }
entry {
entry (ui_fill_st: UiFillState, ui_st: mut UiState) {
let b = new UiBackend
b.rect = fn rec_rect
b.text = fn no_text
@ -27,13 +29,13 @@ program UiFill {
b.image_h = fn nat_h
b.clip = fn rec_clip
b.unclip = fn no_clip
ui_backend(b)
ui_native("knob", fn knob_measure, fn knob_draw)
ui_load_text("<ui>" + STYLE + BODY + "</ui>", "f.xml")
ui_show("f", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes("f", null)
ui_place(r, 0.0, 0.0, 400.0, 600.0)
let n = len(rects)
print(`{rects[0]} .. {rects[49]} | {rects[50]} .. {rects[59]} .. {rects[69]} of {n} | {pics[0]} | {pics[1]} clipped {clips} | ratio {int(r.children[4].ch)} knob {int(r.children[5].children[0].cw)}`)
ui_backend(ui_st, b)
ui_native(ui_st, "knob", fn knob_measure, fn knob_draw)
ui_load_text(ui_st, "<ui>" + STYLE + BODY + "</ui>", "f.xml")
ui_show(ui_st, "f", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes(ui_st, "f", null)
ui_place(ui_st, r, 0.0, 0.0, 400.0, 600.0)
let n = len(ui_fill_st.rects)
print(`{ui_fill_st.rects[0]} .. {ui_fill_st.rects[49]} | {ui_fill_st.rects[50]} .. {ui_fill_st.rects[59]} .. {ui_fill_st.rects[69]} of {n} | {ui_fill_st.pics[0]} | {ui_fill_st.pics[1]} clipped {ui_fill_st.clips} | ratio {int(r.children[4].ch)} knob {int(r.children[5].children[0].cw)}`)
}
}

View file

@ -4,19 +4,19 @@
import "ludic.ui"
program UiFlex {
numbers float
var picked: int = 1
let picked: int = 1
view Tags {
picked = picked
}
const BASE: string = "/* base.lss - every text small */\ntext { size: 10 }\n"
const THEME: string = "/* theme.lss - the base, and a colour for what is on */\n@import \"base.lss\";\n.on { color: #ff0000 }\n"
const PAGE: string = "<ui>\n<import src='theme.lss'/>\n<style>\nrow.bar { gap: 10; pad: 5 }\ntext.big { size: {picked * 20} }\n</style>\n<screen name='flex' gap='8'>\n <row class='bar' w='fill'>\n <text grow='1'>a</text><text grow='3'>b</text>\n </row>\n <row w='fill' justify='between'><text>l</text><text>m</text><text>r</text></row>\n <row w='200' wrap='true' gap='4'>\n <each in='{range(6)}' as='i'><text w='60' class='{i == picked ? \"on\" : \"\"}'>t{i}</text></each>\n </row>\n <row h='40' align='stretch' w='fill'><col w='30' bg='#00ff00'/><text self='end' class='big' size='12'>x</text></row>\n</screen>\n</ui>\n"
entry {
ui_load_text(BASE, "ui/base.lss")
ui_load_text(THEME, "ui/theme.lss")
ui_load_text(PAGE, "ui/flex.xml")
let root: UiNode = ui_nodes("flex", view_tags())
ui_place(root, 0.0, 0.0, 400.0, 300.0)
entry (ui_st: mut UiState) {
ui_load_text(ui_st, BASE, "ui/base.lss")
ui_load_text(ui_st, THEME, "ui/theme.lss")
ui_load_text(ui_st, PAGE, "ui/flex.xml")
let root: UiNode = ui_nodes(ui_st, "flex", view_tags())
ui_place(ui_st, root, 0.0, 0.0, 400.0, 300.0)
let bar = root.children[0]
let wrap = root.children[2]
let tall = root.children[3]

View file

@ -4,36 +4,38 @@
import "ludic.ui"
program UiFocusTip {
numbers float
var said: []string = new []string
var now: float = 0.0
const PAGE: string = "<ui><screen name='f'><button title='Drop it'>a</button><button title='Give it away'>b</button></screen></ui>"
function rec_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(said, `{s} {int(x)},{int(y)}`) }
function clock() -> float { return now }
function frame(i: UiInput, secs: float) -> string {
now = now + secs
said = new []string
ui_input(i)
ui_show("f", null, 0.0, 0.0, 400.0, 400.0)
return said[len(said) - 1]
state UiFocusTipState {
said: []string = new []string
now: float = 0.0
}
entry {
const PAGE: string = "<ui><screen name='f'><button title='Drop it'>a</button><button title='Give it away'>b</button></screen></ui>"
function rec_text(ui_focus_tip_st: mut UiFocusTipState, x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(ui_focus_tip_st.said, `{s} {int(x)},{int(y)}`) }
function clock(ui_focus_tip_st: UiFocusTipState) -> float { return ui_focus_tip_st.now }
function frame(ui_focus_tip_st: mut UiFocusTipState, ui_st: mut UiState, i: UiInput, secs: float) -> string {
ui_focus_tip_st.now = ui_focus_tip_st.now + secs
ui_focus_tip_st.said = new []string
ui_input(ui_st, i)
ui_show(ui_st, "f", null, 0.0, 0.0, 400.0, 400.0)
return ui_focus_tip_st.said[len(ui_focus_tip_st.said) - 1]
}
entry (ui_focus_tip_st: mut UiFocusTipState, ui_st: mut UiState) {
let b = new UiBackend
b.text = fn rec_text
ui_backend(b)
ui_clock(fn clock)
ui_load_text(PAGE, "f.xml")
frame(new UiInput, 0.0)
ui_backend(ui_st, b)
ui_clock(ui_st, fn clock)
ui_load_text(ui_st, PAGE, "f.xml")
frame(ui_focus_tip_st, ui_st, new UiInput, 0.0)
let tab = new UiInput
tab.tab = true
frame(tab, 0.0)
let early = frame(new UiInput, 0.2)
let shown = frame(new UiInput, 0.4)
frame(tab, 0.0)
let next = frame(new UiInput, 0.6)
frame(ui_focus_tip_st, ui_st, tab, 0.0)
let early = frame(ui_focus_tip_st, ui_st, new UiInput, 0.2)
let shown = frame(ui_focus_tip_st, ui_st, new UiInput, 0.4)
frame(ui_focus_tip_st, ui_st, tab, 0.0)
let next = frame(ui_focus_tip_st, ui_st, new UiInput, 0.6)
let moved = new UiInput
moved.x = 390.0
moved.y = 390.0
let gone = frame(moved, 0.6)
let gone = frame(ui_focus_tip_st, ui_st, moved, 0.6)
print(`{early} | {shown} | {next} | {gone}`)
}
}

View file

@ -5,19 +5,21 @@ import "ludic.ui"
import "ui_gamepad_parts/Pad.ludic"
program UiGamepad {
numbers float
var now: float = 0.0
function clock() -> float { return now }
function frame(i: UiInput) -> string {
ui_input(i)
ui_show("Pad", null, 0.0, 0.0, 400.0, 600.0)
let page = ui_nodes("Pad", null).children[0]
state UiGamepadState {
now: float = 0.0
}
function clock(ui_gamepad_st: UiGamepadState) -> float { return ui_gamepad_st.now }
function frame(ui_st: mut UiState, i: UiInput) -> string {
ui_input(ui_st, i)
ui_show(ui_st, "Pad", null, 0.0, 0.0, 400.0, 600.0)
let page = ui_nodes(ui_st, "Pad", null).children[0]
return page.children[len(page.children) - 1].text
}
# `what` held for `secs` at `hz`, then let go
function hold(what: string, secs: float, hz: int) -> string {
function hold(ui_gamepad_st: mut UiGamepadState, ui_st: mut UiState, what: string, secs: float, hz: int) -> string {
let frames = int(secs * float(hz) + 0.5)
for k in 0 .. frames + 1 {
now = now + 1.0 / float(hz)
ui_gamepad_st.now = ui_gamepad_st.now + 1.0 / float(hz)
let i = new UiInput
i.held_up = what == "up"
i.held_down = what == "down"
@ -25,28 +27,28 @@ program UiGamepad {
i.held_right = what == "right"
i.pad_a = what == "a"
i.pad_b = what == "b"
frame(i)
frame(ui_st, i)
}
now = now + 1.0 / float(hz)
return frame(new UiInput)
ui_gamepad_st.now = ui_gamepad_st.now + 1.0 / float(hz)
return frame(ui_st, new UiInput)
}
function tap(what: string) -> string { return hold(what, 0.0, 60) }
entry {
ui_backend(new UiBackend)
ui_clock(fn clock)
frame(new UiInput)
hold("down", 1.0, 240)
let fast = tap("a")
hold("down", 1.0, 60)
hold("up", 0.5, 60)
let slow = tap("a")
for k in 0 .. 8 { tap("down") }
let vol = hold("right", 0.5, 60)
tap("down")
let q = tap("left")
tap("down")
let open = tap("a")
let shut = tap("b")
function tap(ui_gamepad_st: mut UiGamepadState, ui_st: mut UiState, what: string) -> string { return hold(ui_gamepad_st, ui_st, what, 0.0, 60) }
entry (ui_gamepad_st: mut UiGamepadState, ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_clock(ui_st, fn clock)
frame(ui_st, new UiInput)
hold(ui_gamepad_st, ui_st, "down", 1.0, 240)
let fast = tap(ui_gamepad_st, ui_st, "a")
hold(ui_gamepad_st, ui_st, "down", 1.0, 60)
hold(ui_gamepad_st, ui_st, "up", 0.5, 60)
let slow = tap(ui_gamepad_st, ui_st, "a")
for k in 0 .. 8 { tap(ui_gamepad_st, ui_st, "down") }
let vol = hold(ui_gamepad_st, ui_st, "right", 0.5, 60)
tap(ui_gamepad_st, ui_st, "down")
let q = tap(ui_gamepad_st, ui_st, "left")
tap(ui_gamepad_st, ui_st, "down")
let open = tap(ui_gamepad_st, ui_st, "a")
let shut = tap(ui_gamepad_st, ui_st, "b")
print(`{fast} | {slow} | {vol} | {q} | {open} | {shut}`)
}
}

View file

@ -4,33 +4,35 @@
import "ludic.ui"
program UiHold {
numbers float
var now: float = 0.0
var held: float = 0.0
var frames: int = 0
var last_t: float = 0.0
var ends: string = ""
view Craft {
state UiHoldState {
now: float = 0.0
held: float = 0.0
frames: int = 0
last_t: float = 0.0
ends: string = ""
}
view Craft (ui_hold_st: mut UiHoldState) {
on tick(dt: float, t: float) {
held = held + dt
frames = frames + 1
last_t = t
ui_hold_st.held = ui_hold_st.held + dt
ui_hold_st.frames = ui_hold_st.frames + 1
ui_hold_st.last_t = t
}
on down() { ends = ends + "d" }
on up() { ends = ends + "u" }
on down() { ui_hold_st.ends = ui_hold_st.ends + "d" }
on up() { ui_hold_st.ends = ui_hold_st.ends + "u" }
}
const PAGE: string = "<ui><screen name='h'><button on-hold='tick(event.dt, event.t)' on-down='down()' on-up='up()'>Make</button></screen></ui>"
function clock() -> float { return now }
function frame(i: UiInput) -> UiNode {
ui_input(i)
ui_show("h", view_craft(), 0.0, 0.0, 400.0, 400.0)
let r: UiNode = ui_nodes("h", view_craft())
ui_place(r, 0.0, 0.0, 400.0, 400.0)
function clock(ui_hold_st: UiHoldState) -> float { return ui_hold_st.now }
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "h", view_craft(), 0.0, 0.0, 400.0, 400.0)
let r: UiNode = ui_nodes(ui_st, "h", view_craft())
ui_place(ui_st, r, 0.0, 0.0, 400.0, 400.0)
return r.children[0]
}
# held for `secs` at `hz`, by the pointer (off the button after the first frame) or by A
function hold(b: UiNode, secs: float, hz: int, pad: bool) -> string {
held = 0.0
frames = 0
function hold(ui_hold_st: mut UiHoldState, ui_st: mut UiState, b: UiNode, secs: float, hz: int, pad: bool) -> string {
ui_hold_st.held = 0.0
ui_hold_st.frames = 0
let n = int(secs * float(hz) + 0.5)
for k in 0 .. n + 1 {
let i = new UiInput
@ -39,21 +41,21 @@ program UiHold {
i.x = b.x + 5.0
i.y = b.y + 5.0
if k > 0 and not pad { i.x = 390.0 }
frame(i)
now = now + 1.0 / float(hz)
frame(ui_st, i)
ui_hold_st.now = ui_hold_st.now + 1.0 / float(hz)
}
frame(new UiInput)
now = now + 1.0 / float(hz)
return `{frames} frames {int(Math.round(held * 1000.0))} ms t {int(Math.round(last_t * 1000.0))}`
frame(ui_st, new UiInput)
ui_hold_st.now = ui_hold_st.now + 1.0 / float(hz)
return `{ui_hold_st.frames} frames {int(Math.round(ui_hold_st.held * 1000.0))} ms t {int(Math.round(ui_hold_st.last_t * 1000.0))}`
}
entry {
ui_backend(new UiBackend)
ui_clock(fn clock)
ui_load_text(PAGE, "h.xml")
let b = frame(new UiInput)
let slow = hold(b, 0.5, 60, false)
let fast = hold(b, 0.5, 240, false)
let pad = hold(b, 0.25, 60, true)
print(`{slow} | {fast} | pad {pad} | {ends}`)
entry (ui_hold_st: mut UiHoldState, ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_clock(ui_st, fn clock)
ui_load_text(ui_st, PAGE, "h.xml")
let b = frame(ui_st, new UiInput)
let slow = hold(ui_hold_st, ui_st, b, 0.5, 60, false)
let fast = hold(ui_hold_st, ui_st, b, 0.5, 240, false)
let pad = hold(ui_hold_st, ui_st, b, 0.25, 60, true)
print(`{slow} | {fast} | pad {pad} | {ui_hold_st.ends}`)
}
}

View file

@ -4,25 +4,27 @@
import "ludic.ui"
program UiHtml {
numbers float
var clicks: int = 0
view Page {
clicks = clicks
on clicked() { clicks += 1 }
state UiHtmlState {
clicks: int = 0
}
view Page (ui_html_st: mut UiHtmlState) {
clicks = ui_html_st.clicks
on clicked() { ui_html_st.clicks += 1 }
}
const LOOK: string = "/* look.lss */\n.card { padding: 4 8 12 16; margin: 3; border: 2px solid #0000ff; width: 50% }\n#title { font-size: 40 }\nh1.big { font-size: 20 }\n.card p { color: #00ff00 }\nul > li { height: 30 }\nli:first-child { color: #ff0000 }\nli:nth-child(even) { color: #0000ff }\nli:last-child:not(.keep) { display: none }\n[kind=warn] { background-color: #ffff00 }\nbutton:disabled { opacity: 0.5 }\n"
const PAGE: string = "<ui>\n<import src='look.lss'/>\n<screen name='page'>\n <h1 id='title' class='big'>Title</h1>\n <div class='card'><p>inside</p><span kind='warn'>careful</span></div>\n <p>outside</p>\n <ul><li>one</li><li>two</li><li>three</li><li>gone</li></ul>\n <hr/>\n <p style='text-align: center; width: 200px'>mid</p>\n <button disabled='{clicks > 0}' onclick='clicked()'>Go</button>\n <p hidden='true'>never</p>\n</screen>\n</ui>\n"
entry {
ui_load_text(LOOK, "ui/look.lss")
ui_load_text(PAGE, "ui/page.ludic.xml")
var root: UiNode = ui_nodes("page", view_page())
ui_place(root, 0.0, 0.0, 400.0, 600.0)
entry (ui_html_st: UiHtmlState, ui_st: mut UiState) {
ui_load_text(ui_st, LOOK, "ui/look.lss")
ui_load_text(ui_st, PAGE, "ui/page.ludic.xml")
var root: UiNode = ui_nodes(ui_st, "page", view_page())
ui_place(ui_st, root, 0.0, 0.0, 400.0, 600.0)
let card = root.children[1]
let items = root.children[3].children
print(`id beats class: {int(root.children[0].rsize)}; card {int(card.cw)} wide at {int(card.x)},{int(card.y)} pad {int(card.pt)} {int(card.pr)} {int(card.pb)} {int(card.pl)} border {int(card.border)}`)
print(`inside {card.children[0].fg}, outside {root.children[2].fg}; warn bg {card.children[1].bg}; items {len(items)} of 30: {int(items[0].ch)}; colours {items[0].fg} {items[1].fg} {items[2].fg}; hr {int(root.children[4].ch)}; children {len(root.children)}`)
ui_press(root.children[6])
root = ui_nodes("page", view_page())
ui_place(root, 0.0, 0.0, 400.0, 600.0)
print(`clicks {clicks}; the button now disabled {not root.children[6].enabled} at opacity {root.children[6].alpha}; text-align {root.children[5].talign}`)
ui_press(ui_st, root.children[6])
root = ui_nodes(ui_st, "page", view_page())
ui_place(ui_st, root, 0.0, 0.0, 400.0, 600.0)
print(`clicks {ui_html_st.clicks}; the button now disabled {not root.children[6].enabled} at opacity {root.children[6].alpha}; text-align {root.children[5].talign}`)
}
}

View file

@ -8,11 +8,11 @@ import "ui_inputs_parts/Form.ludic"
import "ui_inputs_parts/Tag.ludic"
program UiInputs {
numbers float
function frame(i: UiInput) -> UiNode {
ui_input(i)
ui_show("Form", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Form", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Form", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Form", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root.children[0]
}
function keys(tab: bool, shift: bool, enter: bool, left: bool) -> UiInput {
@ -32,52 +32,52 @@ program UiInputs {
}
function shown_state(page: UiNode) -> string { return page.children[len(page.children) - 1].text }
function last(n: UiNode) -> string { return n.children[len(n.children) - 1].text }
entry {
ui_backend(new UiBackend)
var page = frame(new UiInput)
frame(keys(true, false, false, false))
frame(typed("12"))
page = frame(keys(false, false, true, false))
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
var page = frame(ui_st, new UiInput)
frame(ui_st, keys(true, false, false, false))
frame(ui_st, typed("12"))
page = frame(ui_st, keys(false, false, true, false))
let shown = page.children[0].children[1].children[0].text
let a = shown_state(page)
frame(typed("99"))
page = frame(keys(true, false, false, false))
frame(ui_st, typed("99"))
page = frame(ui_st, keys(true, false, false, false))
let b = shown_state(page)
frame(keys(true, true, false, false))
page = frame(keys(false, false, false, true))
frame(ui_st, keys(true, true, false, false))
page = frame(ui_st, keys(false, false, false, true))
let c = shown_state(page)
let note = page.children[0].children[0].children[1].text
frame(keys(true, false, false, false))
frame(ui_st, keys(true, false, false, false))
let space = page.children[1].children[1].children[0].text
frame(keys(false, false, true, false))
let cap = ui_capturing()
page = frame(keys(true, false, false, false))
frame(ui_st, keys(false, false, true, false))
let cap = ui_capturing(ui_st)
page = frame(ui_st, keys(true, false, false, false))
let d = shown_state(page)
frame(keys(false, false, true, false))
frame(ui_st, keys(false, false, true, false))
let esc = new UiInput
esc.escape = true
esc.key = Key.Escape
page = frame(esc)
page = frame(ui_st, esc)
let e = shown_state(page)
let back = new UiInput
back.backspace = true
page = frame(back)
page = frame(ui_st, back)
let f = shown_state(page)
frame(keys(true, false, false, false))
frame(ui_st, keys(true, false, false, false))
let right = new UiInput
right.right = true
page = frame(right)
page = frame(new UiInput)
page = frame(ui_st, right)
page = frame(ui_st, new UiInput)
let button = page.children[4]
let click = new UiInput
click.x = button.x + 2.0
click.y = button.y + 2.0
click.down = true
frame(click)
frame(ui_st, click)
let up = new UiInput
up.x = click.x
up.y = click.y
page = frame(up)
page = frame(ui_st, up)
print(`count {shown} {a} | {b} | {c} | {note} | {space} listening {cap} {d} | {e} | {f} | {last(page.children[2])} {last(page.children[3])} | {shown_state(page)} | {page.children[5].text}`)
}
}

View file

@ -4,52 +4,54 @@
import "ludic.ui"
program UiKeycap {
numbers float
var bind: int = 32
var pressed: int = 0
view Keys {
bind = bind
pressed = pressed
on set_bind(v: int) { bind = v }
on press() { pressed = pressed + 1 }
state UiKeycapState {
bind: int = 32
pressed: int = 0
}
view Keys (ui_keycap_st: mut UiKeycapState) {
bind = ui_keycap_st.bind
pressed = ui_keycap_st.pressed
on set_bind(v: int) { ui_keycap_st.bind = v }
on press() { ui_keycap_st.pressed = ui_keycap_st.pressed + 1 }
}
const PAGE: string = "<ui><style>.k:capturing { background: #ff0000 }</style><screen name='k'><input type='key' class='k' label='Jump' value='{bind}' on-change='set_bind(event.value)'/><button on-click='press()'>b</button></screen></ui>"
function frame(x: float, y: float, b: int) -> UiNode {
function frame(ui_st: mut UiState, x: float, y: float, b: int) -> UiNode {
let i = new UiInput
i.x = x
i.y = y
i.down = b == 0
i.down_right = b == 1
i.down_middle = b == 2
ui_input(i)
ui_show("k", view_keys(), 0.0, 0.0, 400.0, 400.0)
let r: UiNode = ui_nodes("k", view_keys())
ui_place(r, 0.0, 0.0, 400.0, 400.0)
ui_input(ui_st, i)
ui_show(ui_st, "k", view_keys(), 0.0, 0.0, 400.0, 400.0)
let r: UiNode = ui_nodes(ui_st, "k", view_keys())
ui_place(ui_st, r, 0.0, 0.0, 400.0, 400.0)
return r
}
function listen(k: UiNode) -> int {
frame(k.x + 5.0, k.y + 5.0, 0)
frame(k.x + 5.0, k.y + 5.0, -1)
return frame(-1.0, -1.0, -1).children[0].bg
function listen(ui_st: mut UiState, k: UiNode) -> int {
frame(ui_st, k.x + 5.0, k.y + 5.0, 0)
frame(ui_st, k.x + 5.0, k.y + 5.0, -1)
return frame(ui_st, -1.0, -1.0, -1).children[0].bg
}
function take(at: UiNode, b: int) -> string {
frame(at.x + 5.0, at.y + 5.0, b)
frame(at.x + 5.0, at.y + 5.0, -1)
let r = frame(-1.0, -1.0, -1)
function take(ui_keycap_st: UiKeycapState, ui_st: mut UiState, at: UiNode, b: int) -> string {
frame(ui_st, at.x + 5.0, at.y + 5.0, b)
frame(ui_st, at.x + 5.0, at.y + 5.0, -1)
let r = frame(ui_st, -1.0, -1.0, -1)
let f = r.children[0]
return `{bind} {f.children[1].children[0].text} {f.bg}`
return `{ui_keycap_st.bind} {f.children[1].children[0].text} {f.bg}`
}
entry {
ui_backend(new UiBackend)
ui_load_text(PAGE, "k.xml")
let r = frame(-1.0, -1.0, -1)
entry (ui_keycap_st: UiKeycapState, ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_load_text(ui_st, PAGE, "k.xml")
let r = frame(ui_st, -1.0, -1.0, -1)
let k = r.children[0]
let btn = r.children[1]
let red = listen(k)
let right = take(btn, 1)
listen(k)
let middle = take(btn, 2)
listen(k)
let left = take(btn, 0)
print(`listening {red} | {right} | {middle} | {left} | pressed {pressed}`)
let red = listen(ui_st, k)
let right = take(ui_keycap_st, ui_st, btn, 1)
listen(ui_st, k)
let middle = take(ui_keycap_st, ui_st, btn, 2)
listen(ui_st, k)
let left = take(ui_keycap_st, ui_st, btn, 0)
print(`listening {red} | {right} | {middle} | {left} | pressed {ui_keycap_st.pressed}`)
}
}

View file

@ -10,54 +10,56 @@ import "ui_look_parts/Inner.ludic"
import "ui_look_parts/Menu.ludic"
program UiLook {
numbers float
var said: []string = new []string
var seen: float = 0.0
state UiLookState {
said: []string = new []string
seen: float = 0.0
}
function rec_rect(x: float, y: float, w: float, h: float, c: int, a: float) -> void { }
function rec_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(said, `text {s} {int(x)},{int(y)} {ui_hex(c)}`) }
function rec_image(src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(said, `image {src} {ui_hex(c)}`) }
function rec_nine(src: string, slice: float, x: float, y: float, w: float, h: float, dst: float, c: int, a: float) -> void { push(said, `nine {int(w)} {ui_hex(c)}`) }
function rec_text(ui_look_st: mut UiLookState, x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(ui_look_st.said, `text {s} {int(x)},{int(y)} {ui_hex(c)}`) }
function rec_image(ui_look_st: mut UiLookState, src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(ui_look_st.said, `image {src} {ui_hex(c)}`) }
function rec_nine(ui_look_st: mut UiLookState, src: string, slice: float, x: float, y: float, w: float, h: float, dst: float, c: int, a: float) -> void { push(ui_look_st.said, `nine {int(w)} {ui_hex(c)}`) }
function gauge_measure(n: UiNode, avail: float) -> void { }
function gauge_draw(n: UiNode) -> void { seen = ui_opacity() }
function count(s: string) -> int {
function gauge_draw(ui_look_st: mut UiLookState, ui_st: UiState, n: UiNode) -> void { ui_look_st.seen = ui_opacity(ui_st) }
function count(ui_look_st: UiLookState, s: string) -> int {
var n = 0
for i in 0 .. len(said) {
if Text.starts_with(said[i], s) { n += 1 }
for i in 0 .. len(ui_look_st.said) {
if Text.starts_with(ui_look_st.said[i], s) { n += 1 }
}
return n
}
function has(s: string) -> string {
for i in 0 .. len(said) {
if Text.starts_with(said[i], s) { return said[i] }
function has(ui_look_st: UiLookState, s: string) -> string {
for i in 0 .. len(ui_look_st.said) {
if Text.starts_with(ui_look_st.said[i], s) { return ui_look_st.said[i] }
}
return "-"
}
function show(name: string, i: UiInput) -> UiNode {
ui_input(i)
said = new []string
ui_show(name, null, 0.0, 0.0, 400.0, 300.0)
let root: UiNode = ui_nodes(name, null)
ui_place(root, 0.0, 0.0, 400.0, 300.0)
function show(ui_look_st: mut UiLookState, ui_st: mut UiState, name: string, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_look_st.said = new []string
ui_show(ui_st, name, null, 0.0, 0.0, 400.0, 300.0)
let root: UiNode = ui_nodes(ui_st, name, null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 300.0)
return root.children[0]
}
entry {
entry (ui_look_st: mut UiLookState, ui_st: mut UiState) {
let b = new UiBackend
b.rect = fn rec_rect
b.text = fn rec_text
b.image = fn rec_image
b.nine = fn rec_nine
ui_backend(b)
ui_native("gauge", fn gauge_measure, fn gauge_draw)
var page = show("Look", new UiInput)
ui_backend(ui_st, b)
ui_native(ui_st, "gauge", fn gauge_measure, fn gauge_draw)
var page = show(ui_look_st, ui_st, "Look", new UiInput)
let inner = page.children[0]
let tip = page.children[7]
let rest = new UiInput
rest.x = tip.x + 2.0
rest.y = tip.y + 2.0
for f in 0 .. 40 { page = show("Look", rest) }
for f in 0 .. 40 { page = show(ui_look_st, ui_st, "Look", rest) }
print(`root {inner.tag}.{inner.classes[0]}.{inner.classes[1]}.{inner.classes[2]} pad {int(inner.pt)} margin {int(inner.mt)} color {ui_hex(inner.fg)}`)
print(`{has("text Hi")} | {has("text Hi 0")} | opacity {seen} | {has("nine 40 #ffffff")} {has("nine 40 #ff0000")} of {count("nine")}`)
print(`{has("image photo")} | {has("image icon")} | {has("text first")} | {has("text second")}`)
let menu = show("Menu", new UiInput)
print(`{has(ui_look_st, "text Hi")} | {has(ui_look_st, "text Hi 0")} | opacity {ui_look_st.seen} | {has(ui_look_st, "nine 40 #ffffff")} {has(ui_look_st, "nine 40 #ff0000")} of {count(ui_look_st, "nine")}`)
print(`{has(ui_look_st, "image photo")} | {has(ui_look_st, "image icon")} | {has(ui_look_st, "text first")} | {has(ui_look_st, "text second")}`)
let menu = show(ui_look_st, ui_st, "Menu", new UiInput)
let a = menu.children[1]
let c = menu.children[3]
print(`by id at {int(a.x)},{int(a.y)} | flipped at {int(c.x)},{int(c.y)} {int(c.cw)}x{int(c.ch)}`)

View file

@ -5,56 +5,58 @@ import "ludic.ui"
import "ui_pointer_parts/Chart.ludic"
program UiPointer {
numbers float
var log: string = ""
var dragged: float = 0.0
state UiPointerState {
log: string = ""
dragged: float = 0.0
}
function map_measure(n: UiNode, avail: float) -> void { }
function map_draw(n: UiNode) -> void { }
function map_input(n: UiNode, e: UiPointer) -> bool {
if e.kind == "drag" { dragged = dragged + e.dx } else if e.kind != "pointermove" { log = log + `{e.kind} {int(e.x)},{int(e.y)} {e.button} {int(e.wheel)}; ` }
function map_input(ui_pointer_st: mut UiPointerState, n: UiNode, e: UiPointer) -> bool {
if e.kind == "drag" { ui_pointer_st.dragged = ui_pointer_st.dragged + e.dx } else if e.kind != "pointermove" { ui_pointer_st.log = ui_pointer_st.log + `{e.kind} {int(e.x)},{int(e.y)} {e.button} {int(e.wheel)}; ` }
return true
}
function frame(x: float, y: float, down: bool, wheel: float, enter: bool) -> UiNode {
function frame(ui_st: mut UiState, x: float, y: float, down: bool, wheel: float, enter: bool) -> UiNode {
let i = new UiInput
i.x = x
i.y = y
i.down = down
i.wheel = wheel
i.held_enter = enter
ui_input(i)
ui_show("Chart", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Chart", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
ui_input(ui_st, i)
ui_show(ui_st, "Chart", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Chart", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root.children[0]
}
function said(page: UiNode) -> string { return page.children[len(page.children) - 1].text }
entry {
ui_backend(new UiBackend)
ui_native("chartmap", fn map_measure, fn map_draw)
ui_native_input("chartmap", fn map_input)
let page = frame(-1.0, -1.0, false, 0.0, false)
entry (ui_pointer_st: UiPointerState, ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_native(ui_st, "chartmap", fn map_measure, fn map_draw)
ui_native_input(ui_st, "chartmap", fn map_input)
let page = frame(ui_st, -1.0, -1.0, false, 0.0, false)
let box = page.children[0]
let pad = page.children[1]
let hold = page.children[2]
frame(box.x + 20.0, box.y + 20.0, true, 0.0, false)
frame(box.x + 20.0, box.y + 20.0, false, 0.0, false)
frame(box.x + 100.0, box.y + 80.0, true, 0.0, false)
frame(box.x + 130.0, box.y + 60.0, true, 0.0, false)
frame(box.x + 300.0, box.y + 300.0, true, 0.0, false)
frame(box.x + 300.0, box.y + 300.0, false, 0.0, false)
frame(box.x + 50.0, box.y + 50.0, false, 1.0, false)
frame(pad.x + 7.0, pad.y + 9.0, true, 0.0, false)
frame(pad.x + 17.0, pad.y + 9.0, true, 0.0, false)
frame(pad.x + 17.0, pad.y + 9.0, false, 0.0, false)
frame(pad.x + 17.0, pad.y + 9.0, false, 2.0, false)
frame(hold.x + 5.0, hold.y + 5.0, true, 0.0, false)
let down = frame(hold.x + 5.0, hold.y + 5.0, true, 0.0, false)
frame(ui_st, box.x + 20.0, box.y + 20.0, true, 0.0, false)
frame(ui_st, box.x + 20.0, box.y + 20.0, false, 0.0, false)
frame(ui_st, box.x + 100.0, box.y + 80.0, true, 0.0, false)
frame(ui_st, box.x + 130.0, box.y + 60.0, true, 0.0, false)
frame(ui_st, box.x + 300.0, box.y + 300.0, true, 0.0, false)
frame(ui_st, box.x + 300.0, box.y + 300.0, false, 0.0, false)
frame(ui_st, box.x + 50.0, box.y + 50.0, false, 1.0, false)
frame(ui_st, pad.x + 7.0, pad.y + 9.0, true, 0.0, false)
frame(ui_st, pad.x + 17.0, pad.y + 9.0, true, 0.0, false)
frame(ui_st, pad.x + 17.0, pad.y + 9.0, false, 0.0, false)
frame(ui_st, pad.x + 17.0, pad.y + 9.0, false, 2.0, false)
frame(ui_st, hold.x + 5.0, hold.y + 5.0, true, 0.0, false)
let down = frame(ui_st, hold.x + 5.0, hold.y + 5.0, true, 0.0, false)
let active = down.children[2].bg
let mid = said(down)
frame(hold.x + 5.0, hold.y + 90.0, false, 0.0, false)
let off = frame(-1.0, -1.0, false, 0.0, false)
frame(-1.0, -1.0, false, 0.0, true)
let keyed = said(frame(-1.0, -1.0, false, 0.0, true))
let up = frame(-1.0, -1.0, false, 0.0, false)
print(`{log}dragged {int(dragged)} | {mid} active {active} | {said(off)} | {keyed} | {said(up)} {up.children[2].bg}`)
frame(ui_st, hold.x + 5.0, hold.y + 90.0, false, 0.0, false)
let off = frame(ui_st, -1.0, -1.0, false, 0.0, false)
frame(ui_st, -1.0, -1.0, false, 0.0, true)
let keyed = said(frame(ui_st, -1.0, -1.0, false, 0.0, true))
let up = frame(ui_st, -1.0, -1.0, false, 0.0, false)
print(`{ui_pointer_st.log}dragged {int(ui_pointer_st.dragged)} | {mid} active {active} | {said(off)} | {keyed} | {said(up)} {up.children[2].bg}`)
}
}

View file

@ -4,55 +4,55 @@ import "ludic.ui"
import "ui_popover_parts/Verbs.ludic"
program UiPopover {
numbers float
function frame(i: UiInput) -> UiNode {
ui_input(i)
ui_show("Verbs", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Verbs", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Verbs", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Verbs", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
function click(x: float, y: float) -> void {
function click(ui_st: mut UiState, x: float, y: float) -> void {
let d = new UiInput
d.x = x
d.y = y
d.down = true
frame(d)
frame(ui_st, d)
let u = new UiInput
u.x = x
u.y = y
frame(u)
frame(ui_st, u)
}
function said(root: UiNode) -> string {
let page = root.children[0]
return page.children[len(page.children) - 1].text
}
entry {
ui_backend(new UiBackend)
var root = frame(new UiInput)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
var root = frame(ui_st, new UiInput)
let cell = root.children[0].children[0]
click(cell.x + 2.0, cell.y + 2.0)
root = frame(new UiInput)
click(ui_st, cell.x + 2.0, cell.y + 2.0)
root = frame(ui_st, new UiInput)
let tab = new UiInput
tab.tab = true
frame(tab)
frame(tab)
root = frame(tab)
frame(ui_st, tab)
frame(ui_st, tab)
root = frame(ui_st, tab)
let enter = new UiInput
enter.enter = true
root = frame(enter)
root = frame(new UiInput)
root = frame(ui_st, enter)
root = frame(ui_st, new UiInput)
let first = said(root)
click(cell.x + 2.0, cell.y + 2.0)
root = frame(new UiInput)
click(ui_st, cell.x + 2.0, cell.y + 2.0)
root = frame(ui_st, new UiInput)
let opened = said(root)
click(390.0, 390.0)
root = frame(new UiInput)
click(ui_st, 390.0, 390.0)
root = frame(ui_st, new UiInput)
let outside = said(root)
click(cell.x + 2.0, cell.y + 2.0)
click(ui_st, cell.x + 2.0, cell.y + 2.0)
let esc = new UiInput
esc.escape = true
frame(esc)
root = frame(new UiInput)
frame(ui_st, esc)
root = frame(ui_st, new UiInput)
let bar = root.children[0].children[1]
print(`{first} | {opened} | {outside} | {said(root)} | fill {int(bar.children[0].cw)} of {int(bar.cw)}`)
}

View file

@ -6,11 +6,11 @@ import "ui_popover_align_parts/Menus.ludic"
program UiPopoverAlign {
numbers float
function at(n: UiNode, base: UiNode) -> string { return `{int(n.x - base.x)},{int(n.y - base.y)}` }
entry {
ui_backend(new UiBackend)
ui_show("Menus", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Menus", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_show(ui_st, "Menus", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Menus", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
let panel = root.children[0].children[0]
let list = root.children[0].children[1]
let b = list.children[1]

View file

@ -5,24 +5,24 @@ import "ludic.ui"
import "ui_popover_mouse_parts/Grid.ludic"
program UiPopoverMouse {
numbers float
function frame(i: UiInput) -> UiNode {
ui_input(i)
ui_show("Grid", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Grid", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Grid", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Grid", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
function click(x: float, y: float) -> string {
function click(ui_st: mut UiState, x: float, y: float) -> string {
let d = new UiInput
d.x = x
d.y = y
d.down = true
frame(d)
frame(ui_st, d)
let u = new UiInput
u.x = x
u.y = y
frame(u)
let root = frame(new UiInput)
frame(ui_st, u)
let root = frame(ui_st, new UiInput)
let page = root.children[0]
return page.children[len(page.children) - 1].text
}
@ -34,19 +34,19 @@ program UiPopoverMouse {
}
return null
}
entry {
ui_backend(new UiBackend)
frame(new UiInput)
let opened = click(20.0, 20.0)
let root = frame(new UiInput)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
frame(ui_st, new UiInput)
let opened = click(ui_st, 20.0, 20.0)
let root = frame(ui_st, new UiInput)
let drop = find(root, "drop")
let cell = find(root, "cell")
let over = drop.x >= cell.x and drop.y >= cell.y and drop.x + drop.cw <= cell.x + cell.cw
let dropped = click(drop.x + drop.cw / 2.0, drop.y + drop.ch / 2.0)
click(20.0, 20.0)
let on_cell = click(180.0, 90.0)
click(20.0, 20.0)
let on_nothing = click(390.0, 390.0)
let dropped = click(ui_st, drop.x + drop.cw / 2.0, drop.y + drop.ch / 2.0)
click(ui_st, 20.0, 20.0)
let on_cell = click(ui_st, 180.0, 90.0)
click(ui_st, 20.0, 20.0)
let on_nothing = click(ui_st, 390.0, 390.0)
print(`over the cell {over} | {opened} | {dropped} | {on_cell} | {on_nothing}`)
}
}

View file

@ -4,18 +4,20 @@
import "ludic.ui"
program UiReact {
numbers float
var names: []string = new []string
var volume: int = 3
var mounted: int = 0
var unmounted: int = 0
var show_extra: bool = true
view Mixer {
names = names
volume = volume
extra = show_extra
on set_volume(v: int) { volume = v }
on mount() { mounted += 1 }
on unmount() { unmounted += 1 }
state UiReactState {
names: []string = new []string
volume: int = 3
mounted: int = 0
unmounted: int = 0
show_extra: bool = true
}
view Mixer (ui_react_st: mut UiReactState) {
names = ui_react_st.names
volume = ui_react_st.volume
extra = ui_react_st.show_extra
on set_volume(v: int) { ui_react_st.volume = v }
on mount() { ui_react_st.mounted += 1 }
on unmount() { ui_react_st.unmounted += 1 }
}
# a dial the program draws itself: it measures 40 square and, pressed, turns up by one
function dial_measure(n: UiNode, avail: float) -> void {
@ -28,32 +30,32 @@ program UiReact {
if n.text != "" { push(out, n.text) }
for i in 0 .. len(n.children) { texts(n.children[i], out) }
}
function frame() -> UiNode {
ui_show("mix", view_mixer(), 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("mix", view_mixer())
ui_place(root, 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState) -> UiNode {
ui_show(ui_st, "mix", view_mixer(), 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "mix", view_mixer())
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
entry {
ui_native("dial", fn dial_measure, fn dial_draw)
push(names, "bass")
push(names, "drums")
ui_load_text(PAGE, "ui/mix.xml")
var root = frame()
ui_press(root.children[2])
names[0] = "drums"
names[1] = "bass"
root = frame()
entry (ui_react_st: mut UiReactState, ui_st: mut UiState) {
ui_native(ui_st, "dial", fn dial_measure, fn dial_draw)
push(ui_react_st.names, "bass")
push(ui_react_st.names, "drums")
ui_load_text(ui_st, PAGE, "ui/mix.xml")
var root = frame(ui_st)
ui_press(ui_st, root.children[2])
ui_react_st.names[0] = "drums"
ui_react_st.names[1] = "bass"
root = frame(ui_st)
let dial = root.children[3]
ui_event(dial, "change", Value.int(volume + 4))
ui_event(root.children[4], "change", Value.bool(1))
show_extra = false
root = frame()
ui_event(ui_st, dial, "change", Value.int(ui_react_st.volume + 4))
ui_event(ui_st, root.children[4], "change", Value.bool(1))
ui_react_st.show_extra = false
root = frame(ui_st)
let out = new []string
texts(root, out)
var joined = ""
for i in 0 .. len(out) { joined = joined + out[i] + "|" }
print(joined)
print(`volume {volume}; dial {int(dial.cw)}x{int(dial.ch)}; mounted {mounted}, unmounted {unmounted}`)
print(`volume {ui_react_st.volume}; dial {int(dial.cw)}x{int(dial.ch)}; mounted {ui_react_st.mounted}, unmounted {ui_react_st.unmounted}`)
}
}

View file

@ -9,21 +9,21 @@ program UiReload {
const PATH: string = "build/ui_reload_example.xml"
const V1: string = "<ui><screen name='note'><state n='{0}'/><button on-click='set n = n + 1'>{title} {n}</button></screen></ui>"
const V2: string = "<ui><screen name='note'><state n='{0}'/><h1>{title} again {n}</h1></screen></ui>"
function shown() -> string {
let root: UiNode = ui_nodes("note", view_note())
function shown(ui_st: mut UiState) -> string {
let root: UiNode = ui_nodes(ui_st, "note", view_note())
let first = root.children[0]
if len(first.children) > 0 { return first.children[0].text }
return first.text
}
entry {
entry (ui_st: mut UiState) {
Fs.write_text(PATH, V1)
ui_load(PATH)
let root: UiNode = ui_nodes("note", view_note())
ui_press(root.children[0])
let before = shown()
let same = ui_reload()
ui_load(ui_st, PATH)
let root: UiNode = ui_nodes(ui_st, "note", view_note())
ui_press(ui_st, root.children[0])
let before = shown(ui_st)
let same = ui_reload(ui_st)
Fs.write_text(PATH, V2)
let changed = ui_reload()
print(`{before} | reloaded {same} then {changed} | {shown()}`)
let changed = ui_reload(ui_st)
print(`{before} | reloaded {same} then {changed} | {shown(ui_st)}`)
}
}

View file

@ -4,29 +4,29 @@ import "ludic.ui"
import "ui_scroll_hold_parts/Held.ludic"
program UiScrollHold {
numbers float
function frame(x: float, y: float, wheel: float) -> UiNode {
function frame(ui_st: mut UiState, x: float, y: float, wheel: float) -> UiNode {
let i = new UiInput
i.x = x
i.y = y
i.wheel = wheel
ui_input(i)
ui_show("Held", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes("Held", null)
ui_place(root, 0.0, 0.0, 400.0, 600.0)
ui_input(ui_st, i)
ui_show(ui_st, "Held", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes(ui_st, "Held", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 600.0)
return root.children[0]
}
function at(p: UiNode) -> string { return `{int(p.children[0].scroll_y)} {int(p.children[1].scroll_y)} {int(p.children[2].scroll_y)} {p.children[3].text}` }
entry {
ui_backend(new UiBackend)
let p = frame(-1.0, -1.0, 0.0)
let first = at(frame(-1.0, -1.0, 0.0))
frame(p.children[0].x + 5.0, p.children[0].y + 5.0, 1.0)
let followed = at(frame(-1.0, -1.0, 0.0))
frame(p.children[1].x + 5.0, p.children[1].y + 5.0, -1.0)
let fixed = at(frame(-1.0, -1.0, 0.0))
ui_scroll_set("free", 70.0)
let set = at(frame(-1.0, -1.0, 0.0))
frame(p.children[2].x + 5.0, p.children[2].y + 5.0, 1.0)
print(`{first} | {followed} | {fixed} | {set} | {at(frame(-1.0, -1.0, 0.0))}`)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
let p = frame(ui_st, -1.0, -1.0, 0.0)
let first = at(frame(ui_st, -1.0, -1.0, 0.0))
frame(ui_st, p.children[0].x + 5.0, p.children[0].y + 5.0, 1.0)
let followed = at(frame(ui_st, -1.0, -1.0, 0.0))
frame(ui_st, p.children[1].x + 5.0, p.children[1].y + 5.0, -1.0)
let fixed = at(frame(ui_st, -1.0, -1.0, 0.0))
ui_scroll_set(ui_st, "free", 70.0)
let set = at(frame(ui_st, -1.0, -1.0, 0.0))
frame(ui_st, p.children[2].x + 5.0, p.children[2].y + 5.0, 1.0)
print(`{first} | {followed} | {fixed} | {set} | {at(frame(ui_st, -1.0, -1.0, 0.0))}`)
}
}

View file

@ -5,48 +5,50 @@ import "ludic.ui"
import "ui_scrollbar_parts/Long.ludic"
program UiScrollbar {
numbers float
var bx: float = 0.0
var by: float = 0.0
function frame(i: UiInput) -> UiNode {
ui_input(i)
ui_show("Long", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes("Long", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
state UiScrollbarState {
bx: float = 0.0
by: float = 0.0
}
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Long", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Long", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root.children[0]
}
# the pointer at (bx + x, by + y), held or not; how far the box is scrolled then
function at(x: float, y: float, down: bool) -> int {
function at(ui_scrollbar_st: UiScrollbarState, ui_st: mut UiState, x: float, y: float, down: bool) -> int {
let i = new UiInput
i.x = bx + x
i.y = by + y
i.x = ui_scrollbar_st.bx + x
i.y = ui_scrollbar_st.by + y
i.down = down
return int(frame(i).children[0].scroll_y)
return int(frame(ui_st, i).children[0].scroll_y)
}
function wheel(x: float, y: float) -> int {
function wheel(ui_scrollbar_st: UiScrollbarState, ui_st: mut UiState, x: float, y: float) -> int {
let i = new UiInput
i.x = bx + x
i.y = by + y
i.x = ui_scrollbar_st.bx + x
i.y = ui_scrollbar_st.by + y
i.wheel = 1.0
frame(i)
return int(frame(new UiInput).children[0].scroll_y)
frame(ui_st, i)
return int(frame(ui_st, new UiInput).children[0].scroll_y)
}
entry {
ui_backend(new UiBackend)
let list = frame(new UiInput).children[0]
bx = list.x
by = list.y
let grab = at(195.0, 10.0, true)
let moved = at(195.0, 40.0, true)
let far = at(195.0, 300.0, true)
let back = at(195.0, 25.0, true)
let kept = at(195.0, 25.0, false)
at(0.0 - bx - 1.0, 0.0 - by - 1.0, false)
let jump = at(195.0, 80.0, true)
at(195.0, 80.0, false)
let wheeled = wheel(50.0, 50.0)
at(50.0, 20.0, true)
at(50.0, 20.0, false)
let page = frame(new UiInput)
entry (ui_scrollbar_st: mut UiScrollbarState, ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
let list = frame(ui_st, new UiInput).children[0]
ui_scrollbar_st.bx = list.x
ui_scrollbar_st.by = list.y
let grab = at(ui_scrollbar_st, ui_st, 195.0, 10.0, true)
let moved = at(ui_scrollbar_st, ui_st, 195.0, 40.0, true)
let far = at(ui_scrollbar_st, ui_st, 195.0, 300.0, true)
let back = at(ui_scrollbar_st, ui_st, 195.0, 25.0, true)
let kept = at(ui_scrollbar_st, ui_st, 195.0, 25.0, false)
at(ui_scrollbar_st, ui_st, 0.0 - ui_scrollbar_st.bx - 1.0, 0.0 - ui_scrollbar_st.by - 1.0, false)
let jump = at(ui_scrollbar_st, ui_st, 195.0, 80.0, true)
at(ui_scrollbar_st, ui_st, 195.0, 80.0, false)
let wheeled = wheel(ui_scrollbar_st, ui_st, 50.0, 50.0)
at(ui_scrollbar_st, ui_st, 50.0, 20.0, true)
at(ui_scrollbar_st, ui_st, 50.0, 20.0, false)
let page = frame(ui_st, new UiInput)
print(`grab {grab} moved {moved} far {far} back {back} kept {kept} | jump {jump} | wheel {wheeled} | {page.children[1].text}`)
}
}

View file

@ -3,43 +3,45 @@
import "ludic.ui"
program UiSubmit {
numbers float
var said: string = ""
var chat: string = ""
var name: string = ""
view Chat {
chat = chat
name = name
on set_chat(v: string) { chat = v }
on set_name(v: string) { name = v }
on send(v: string) { said = said + "[" + v + "]" }
state UiSubmitState {
said: string = ""
chat: string = ""
name: string = ""
}
view Chat (ui_submit_st: mut UiSubmitState) {
chat = ui_submit_st.chat
name = ui_submit_st.name
on set_chat(v: string) { ui_submit_st.chat = v }
on set_name(v: string) { ui_submit_st.name = v }
on send(v: string) { ui_submit_st.said = ui_submit_st.said + "[" + v + "]" }
}
const PAGE: string = "<ui><screen name='c'><input type='text' label='Say' value='{chat}' clear-on-submit on-change='set_chat(event.value)' on-submit='send(event.value)'/><input type='text' label='Name' value='{name}' on-change='set_name(event.value)' on-submit='send(event.value)'/></screen></ui>"
function frame(i: UiInput) -> void {
ui_input(i)
ui_show("c", view_chat(), 0.0, 0.0, 400.0, 400.0)
function frame(ui_st: mut UiState, i: UiInput) -> void {
ui_input(ui_st, i)
ui_show(ui_st, "c", view_chat(), 0.0, 0.0, 400.0, 400.0)
}
function press(tab: bool, enter: bool, pad: bool, typed: string) -> void {
function press(ui_st: mut UiState, tab: bool, enter: bool, pad: bool, typed: string) -> void {
let i = new UiInput
i.tab = tab
i.enter = enter
i.pad_a = pad
i.typed = typed
frame(i)
frame(new UiInput)
frame(ui_st, i)
frame(ui_st, new UiInput)
}
entry {
ui_backend(new UiBackend)
ui_load_text(PAGE, "c.xml")
frame(new UiInput)
press(true, false, false, "")
press(false, false, false, "hi")
press(false, true, false, "")
let after = `{said} chat '{chat}'`
press(false, false, false, "yo")
press(false, false, true, "")
press(true, false, false, "")
press(false, false, false, "Ada")
press(false, true, false, "")
print(`{after} | {said} chat '{chat}' name '{name}'`)
entry (ui_st: mut UiState, ui_submit_st: UiSubmitState) {
ui_backend(ui_st, new UiBackend)
ui_load_text(ui_st, PAGE, "c.xml")
frame(ui_st, new UiInput)
press(ui_st, true, false, false, "")
press(ui_st, false, false, false, "hi")
press(ui_st, false, true, false, "")
let after = `{ui_submit_st.said} chat '{ui_submit_st.chat}'`
press(ui_st, false, false, false, "yo")
press(ui_st, false, false, true, "")
press(ui_st, true, false, false, "")
press(ui_st, false, false, false, "Ada")
press(ui_st, false, true, false, "")
print(`{after} | {ui_submit_st.said} chat '{ui_submit_st.chat}' name '{ui_submit_st.name}'`)
}
}

View file

@ -9,40 +9,42 @@ program UiTemplates {
name: string = ""
cost: int = 0
}
var stock: []Item = new []Item
var purse: int = 100
var bought: []int = new []int
function add(name: string, cost: int) -> void {
state UiTemplatesState {
stock: []Item = new []Item
purse: int = 100
bought: []int = new []int
}
function add(ui_templates_st: mut UiTemplatesState, name: string, cost: int) -> void {
let it = new Item
it.name = name
it.cost = cost
push(stock, it)
push(ui_templates_st.stock, it)
}
view Shop {
purse = purse
stock = stock
owned: int = len(bought)
function afford(i: int) -> bool { return purse >= stock[i].cost }
view Shop (ui_templates_st: mut UiTemplatesState) {
purse = ui_templates_st.purse
stock = ui_templates_st.stock
owned: int = len(ui_templates_st.bought)
function afford(i: int) -> bool { return ui_templates_st.purse >= ui_templates_st.stock[i].cost }
on buy(i: int) {
purse -= stock[i].cost
push(bought, i)
ui_templates_st.purse -= ui_templates_st.stock[i].cost
push(ui_templates_st.bought, i)
}
}
const KIT: string = "<ui>\n<component name='Price'><text>${cost}</text></component>\n<component name='Line' export='true'>\n <state picks='{0}'/>\n <row gap='8' w='fill' align='center'>\n <text color='{picked ? \"#ffcc00\" : \"#eeeeee\"}'>{item.name} -</text>\n <Price cost='{item.cost}'/>\n <spacer w='fill'/>\n <text>{picks}</text>\n <button enabled='{afford(i)}' on-press='buy(i); set picks = picks + 1; emit chose'>Buy</button>\n </row>\n</component>\n</ui>\n"
const PAGE: string = "<ui>\n<import src='kit.xml' as='kit'/>\n<screen name='shop' gap='4' pad='10'>\n <state pick='{-1}'/>\n <text size='24'>The purse: ${purse}</text>\n <each in='{stock}' as='item' index='i'>\n <kit:Line item='{item}' i='{i}' picked='{pick == i}' on-chose='set pick = i'/>\n </each>\n <if test='{owned == 0}'><text>Nothing bought yet</text></if>\n <else><text>{owned} bought, the last {pick + 1}</text></else>\n</screen>\n</ui>\n"
const PRIVATE: string = "<ui><import src='kit.xml' as='kit'/><screen name='peek'><kit:Price cost='{1}'/></screen></ui>"
entry {
add("Rope", 30)
add("Lantern", 80)
ui_load_text(KIT, "ui/kit.xml")
ui_load_text(PAGE, "ui/shop.xml")
ui_load_text(PRIVATE, "ui/peek.xml")
var root: UiNode = ui_nodes("shop", view_shop())
ui_place(root, 0.0, 0.0, 600.0, 400.0)
entry (ui_st: mut UiState, ui_templates_st: mut UiTemplatesState) {
add(ui_templates_st, "Rope", 30)
add(ui_templates_st, "Lantern", 80)
ui_load_text(ui_st, KIT, "ui/kit.xml")
ui_load_text(ui_st, PAGE, "ui/shop.xml")
ui_load_text(ui_st, PRIVATE, "ui/peek.xml")
var root: UiNode = ui_nodes(ui_st, "shop", view_shop())
ui_place(ui_st, root, 0.0, 0.0, 600.0, 400.0)
let press = root.children[1].children[4]
ui_press(ui_hit(root, press.x + 1.0, press.y + 1.0))
root = ui_nodes("shop", view_shop())
ui_place(root, 0.0, 0.0, 600.0, 400.0)
print(`purse {purse}, bought {len(bought)}; the lantern is enabled: {root.children[2].children[4].enabled}`)
ui_press(ui_st, ui_hit(root, press.x + 1.0, press.y + 1.0))
root = ui_nodes(ui_st, "shop", view_shop())
ui_place(ui_st, root, 0.0, 0.0, 600.0, 400.0)
print(`purse {ui_templates_st.purse}, bought {len(ui_templates_st.bought)}; the lantern is enabled: {root.children[2].children[4].enabled}`)
}
}

View file

@ -5,19 +5,21 @@ import "ludic.ui"
import "ui_text_parts/Fit.ludic"
program UiText {
numbers float
var said: []string = new []string
function rec_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(said, `{s}@{int(size * 10.0)} y{int(y)}`) }
state UiTextState {
said: []string = new []string
}
function rec_text(ui_text_st: mut UiTextState, x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(ui_text_st.said, `{s}@{int(size * 10.0)} y{int(y)}`) }
function w(s: string, size: float) -> float { return float(len(s)) * size * 0.5 }
entry {
entry (ui_st: mut UiState, ui_text_st: UiTextState) {
let b = new UiBackend
b.text = fn rec_text
b.measure = fn w
ui_backend(b)
ui_show("Fit", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes("Fit", null)
ui_place(root, 0.0, 0.0, 400.0, 600.0)
ui_backend(ui_st, b)
ui_show(ui_st, "Fit", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes(ui_st, "Fit", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 600.0)
let page = root.children[0]
let lines = page.children[3]
print(`{said[0]} | {said[1]} | {said[2]} | lines {len(lines.lines)} {int(lines.mh)} {said[3]} {said[4]} | tall {int(page.children[4].mh)} | em {int(page.children[5].pt)} {int(page.children[6].pt)} | tie {ui_hex(page.children[7].fg)}`)
print(`{ui_text_st.said[0]} | {ui_text_st.said[1]} | {ui_text_st.said[2]} | lines {len(lines.lines)} {int(lines.mh)} {ui_text_st.said[3]} {ui_text_st.said[4]} | tall {int(page.children[4].mh)} | em {int(page.children[5].pt)} {int(page.children[6].pt)} | tie {ui_hex(page.children[7].fg)}`)
}
}

View file

@ -5,10 +5,10 @@ import "ui_theme_parts/Bare.ludic"
import "ui_theme_parts/Shell.ludic"
program UiTheme {
numbers float
entry {
ui_backend(new UiBackend)
let root: UiNode = ui_nodes("Shell", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
let root: UiNode = ui_nodes(ui_st, "Shell", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
let bare = root.children[0].children[0]
print(`accent {ui_hex(bare.children[0].fg)} gap {int(bare.gap)}`)
}

View file

@ -4,8 +4,10 @@
import "ludic.ui"
program UiTranslate {
numbers float
var said: []string = new []string
var now: float = 0.0
state UiTranslateState {
said: []string = new []string
now: float = 0.0
}
const PAGE: string = "<ui><screen name='t'><p>Hello</p><p translate='no'>Hello</p><div translate='no'><p>Hello</p><p translate='yes'>Hello</p></div><p class='a' title='Save\\nQuit'>a</p><p class='b' title='Line one\\nLine two'>b</p><div translate='no'><p class='c' title='Line one\\nLine two'>c</p></div></screen></ui>"
function tr(s: string) -> string {
if s == "Hello" { return "Merhaba" }
@ -14,31 +16,31 @@ program UiTranslate {
if s == "Line two" { return "Satir iki" }
return s
}
function rec_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(said, s) }
function clock() -> float { return now }
function tip(root: UiNode, k: int) -> string {
function rec_text(ui_translate_st: mut UiTranslateState, x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(ui_translate_st.said, s) }
function clock(ui_translate_st: UiTranslateState) -> float { return ui_translate_st.now }
function tip(ui_st: mut UiState, ui_translate_st: mut UiTranslateState, root: UiNode, k: int) -> string {
let n = root.children[k]
let i = new UiInput
i.x = n.x + 1.0
i.y = n.y + 1.0
ui_input(i)
ui_show("t", null, 0.0, 0.0, 400.0, 400.0)
now = now + 1.0
said = new []string
ui_input(i)
ui_show("t", null, 0.0, 0.0, 400.0, 400.0)
return `{said[len(said) - 2]}/{said[len(said) - 1]}`
ui_input(ui_st, i)
ui_show(ui_st, "t", null, 0.0, 0.0, 400.0, 400.0)
ui_translate_st.now = ui_translate_st.now + 1.0
ui_translate_st.said = new []string
ui_input(ui_st, i)
ui_show(ui_st, "t", null, 0.0, 0.0, 400.0, 400.0)
return `{ui_translate_st.said[len(ui_translate_st.said) - 2]}/{ui_translate_st.said[len(ui_translate_st.said) - 1]}`
}
entry {
entry (ui_st: mut UiState, ui_translate_st: mut UiTranslateState) {
let b = new UiBackend
b.text = fn rec_text
ui_backend(b)
ui_translator(fn tr)
ui_clock(fn clock)
ui_load_text(PAGE, "t.xml")
let root: UiNode = ui_nodes("t", null)
ui_place(root, 0.0, 0.0, 400.0, 400.0)
ui_backend(ui_st, b)
ui_translator(ui_st, fn tr)
ui_clock(ui_st, fn clock)
ui_load_text(ui_st, PAGE, "t.xml")
let root: UiNode = ui_nodes(ui_st, "t", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
let texts = `{root.children[0].text} {root.children[1].text} {root.children[2].children[0].text} {root.children[2].children[1].text}`
print(`{texts} | {tip(root, 3)} | {tip(root, 4)} | {tip(root, 5)}`)
print(`{texts} | {tip(ui_st, ui_translate_st, root, 3)} | {tip(ui_st, ui_translate_st, root, 4)} | {tip(ui_st, ui_translate_st, root, 5)}`)
}
}

View file

@ -6,12 +6,12 @@ program UiZoom {
numbers float
const STYLE: string = "<style>.box { width: 100px; padding: 10px }\n.half { zoom: 0.5 }\n.twice { zoom: 200% }\n.fit { zoom: min(1, calc(100vw / 800px)) }\np { height: 20px }\n.em { width: 2em }</style>"
const BODY: string = "<screen name='z'><div class='box'><p>a</p></div><div class='box half'><p>b</p><div class='twice'><div class='box'/></div></div><div class='fit'><div class='box'/><div class='em'/></div></screen>"
entry {
ui_backend(new UiBackend)
ui_load_text("<ui>" + STYLE + BODY + "</ui>", "z.xml")
ui_show("z", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes("z", null)
ui_place(r, 0.0, 0.0, 400.0, 600.0)
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
ui_load_text(ui_st, "<ui>" + STYLE + BODY + "</ui>", "z.xml")
ui_show(ui_st, "z", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes(ui_st, "z", null)
ui_place(ui_st, r, 0.0, 0.0, 400.0, 600.0)
let plain = r.children[0]
let half = r.children[1]
let inner = half.children[1].children[0]