Skip to content

Commit accc4ce

Browse files
committed
Expand UIKit controls and comparison fixtures
1 parent f673a29 commit accc4ce

29 files changed

Lines changed: 684 additions & 54 deletions

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ $(HOST_BINARY): $(IOS_LUA_A) $(IOS_HOST_SRCS) ios/LuaRuntime/LuaRuntime.h $(UIKI
158158
@echo "Building iOS host..."
159159
@mkdir -p $(HOST_BUNDLE)
160160
@$(IOS_CC) $(IOS_CFLAGS) \
161-
-framework UIKit -framework Foundation -framework CoreGraphics -framework QuartzCore -framework Security -framework WebKit \
161+
-framework UIKit -framework Foundation -framework CoreGraphics -framework QuartzCore -framework Security -framework WebKit -framework AVFoundation -framework Speech \
162162
-o $(HOST_BUNDLE)/LuaRuntime \
163163
$(IOS_HOST_SRCS) $(UIKIT_RUNTIME_SRC) $(IOS_LUA_A)
164164
@cp ios/LuaRuntime/Info.plist $(HOST_BUNDLE)/Info.plist

‎apps/adventure-arena/Controller.lua‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,20 @@ end
4141

4242
function Controller:push(template, data, title)
4343
local view, refs = xml.renderFile("apps/adventure-arena/views/" .. template .. ".etlua", data, self.ns)
44-
self.navigation:push(self.ns.HostingController(view), title)
44+
local hostingController
45+
if template == "Session" and self.ns.SpeechRecognizer then
46+
hostingController = self.ns.HostingController(view, function()
47+
self.sessionController:onDisappear()
48+
end)
49+
else
50+
hostingController = self.ns.HostingController(view)
51+
end
52+
self.navigation:push(hostingController, title)
4553
return view, refs
4654
end
4755

4856
function Controller:back()
57+
self.sessionController:cancelDictation()
4958
self.navigation:pop()
5059
end
5160

‎apps/adventure-arena/controllers/SessionController.lua‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ function Controller.new(options)
88
push = assert(options.push, "navigation push callback is required"),
99
back = assert(options.back, "navigation back callback is required"),
1010
ns = assert(options.ns, "native platform module is required"),
11+
speech = nil,
12+
dictationActive = false,
13+
dictationPrefix = "",
1114
}, Controller)
1215
end
1316

@@ -21,14 +24,24 @@ function Controller:show(id)
2124
}, game.title)
2225
return false
2326
end
27+
self:cancelDictation()
28+
local speechAvailable = type(self.ns.SpeechRecognizer) == "function"
29+
if speechAvailable then
30+
self.speech = self.ns.SpeechRecognizer(function(state, text, message)
31+
self:onSpeechEvent(state, text, message)
32+
end)
33+
end
2434
local actions = {
2535
submit = function() self:submitCommand(self.refs.input.text) end,
2636
look = function() self:submitCommand("look") end,
2737
inventory = function() self:submitCommand("inventory") end,
28-
close = self.back,
38+
dictate = function() self:toggleDictation() end,
39+
close = function() self:close() end,
2940
}
3041
self.view, self.refs = self.push("Session", {
31-
transcript = self.model:transcript(), actions = actions,
42+
transcript = self.model:transcript(),
43+
speechAvailable = speechAvailable,
44+
actions = actions,
3245
}, game.title)
3346
self.refs.input.accessibilityLabel = "Command"
3447
self.ns._textFieldCallbacks(self.refs.input, nil, function(command)
@@ -39,10 +52,69 @@ function Controller:show(id)
3952
return true
4053
end
4154

55+
function Controller:onSpeechEvent(state, text, message)
56+
if not self.refs then return end
57+
if state == "listening" then
58+
self.dictationActive = true
59+
self.refs.dictationStatus.text = "Listening… Tap the microphone to finish."
60+
elseif state == "partial" or state == "finished" then
61+
local separator = self.dictationPrefix ~= ""
62+
and not self.dictationPrefix:match("%s$") and " " or ""
63+
self.refs.input.text = self.dictationPrefix .. separator .. (text or "")
64+
if state == "finished" then
65+
self.dictationActive = false
66+
self.refs.dictationStatus.text = ""
67+
end
68+
elseif state == "starting" then
69+
self.refs.dictationStatus.text = "Waiting for microphone access…"
70+
elseif state == "processing" then
71+
self.refs.dictationStatus.text = "Transcribing…"
72+
elseif state == "error" then
73+
self.dictationActive = false
74+
self.refs.dictationStatus.text = message or "Dictation is unavailable. Check microphone and speech access in Settings."
75+
elseif state == "idle" then
76+
self.dictationActive = false
77+
self.refs.dictationStatus.text = ""
78+
end
79+
self.view:layout()
80+
end
81+
82+
function Controller:toggleDictation()
83+
if not self.speech then return end
84+
if self.dictationActive then
85+
self.speech:stop()
86+
self.refs.dictationStatus.text = "Transcribing…"
87+
else
88+
self.dictationPrefix = self.refs.input.text or ""
89+
self.dictationActive = true
90+
self.speech:start()
91+
end
92+
self.view:layout()
93+
end
94+
95+
function Controller:cancelDictation()
96+
if self.speech and self.dictationActive then self.speech:cancel() end
97+
self.dictationActive = false
98+
end
99+
100+
function Controller:close()
101+
self:onDisappear()
102+
self.back()
103+
end
104+
105+
function Controller:onDisappear()
106+
self:cancelDictation()
107+
self.speech = nil
108+
self.refs = nil
109+
self.view = nil
110+
end
111+
42112
function Controller:submitCommand(command)
113+
self:cancelDictation()
43114
local ok, err = self.model:submit(command)
44115
self.refs.output.text = self.model:transcript()
45116
self.refs.input.text = ""
117+
self.refs.dictationStatus.text = ""
46118
self.view:layout()
47119
return ok, err
48120
end

‎apps/adventure-arena/views/Session.etlua‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
<Label ref="output" text="<%= transcript %>" size="16" lines="0" />
55
</VStack>
66
</ScrollView>
7-
<HStack paddingHorizontal="16">
8-
<TextField ref="input" placeholder="What do you want to do?" />
9-
<Button ref="send" title="Send" action="submit" />
7+
<Label ref="dictationStatus" text="" size="13" color="secondary" paddingHorizontal="20" lines="2" />
8+
<HStack paddingHorizontal="16" spacing="10">
9+
<GlassEffect style="regular" cornerRadius="28" maxWidth="infinity">
10+
<HStack paddingHorizontal="14" spacing="8" minHeight="56">
11+
<TextField ref="input" placeholder="What do you want to do?" maxWidth="infinity" />
12+
<% if speechAvailable then %>
13+
<Button ref="dictate" title="" systemImage="mic" accessibilityLabel="Dictate command" action="dictate" style="plain" />
14+
<% end %>
15+
</HStack>
16+
</GlassEffect>
17+
<Button ref="send" title="Send" action="submit" style="plain" />
1018
</HStack>
1119
<HStack paddingHorizontal="16" paddingBottom="8">
1220
<Button ref="look" title="look" action="look" />

‎comparison/iphone_swiftui/README.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ contract fixes sample text, font sizes and weights, control styles and values,
66
fixture order, and the capture environment. The two view trees are implemented
77
separately so their output can be compared without sharing layout code.
88

9-
The first comparison covers text styles and wrapping, SF Symbol labels, button
10-
styles and disabled state, `VStack`/`HStack`/`ZStack` composition, and native
11-
text field, toggle, slider, and progress controls. Each family is a launch
12-
selectable fixture, which gives it the full iPhone viewport in the screenshot.
9+
The comparison covers text styles and wrapping, SF Symbol labels, button styles
10+
and roles, enabled and disabled toggles, native tabs, a three-column weather
11+
grid, nested and spaced stacks, and native text field, slider, and progress
12+
controls. Each family is a launch-selectable fixture, which gives it the full
13+
iPhone viewport in the screenshot.
1314

1415
The reference app uses SwiftUI controls. The candidate app uses the public
1516
lua-objc UIKit API and etlua templates. Both run on the same booted Simulator;
@@ -26,6 +27,7 @@ Capture one fixture:
2627

2728
```sh
2829
comparison/iphone_swiftui/capture.sh buttons
30+
comparison/iphone_swiftui/capture.sh tabs
2931
```
3032

3133
The generated image pairs and environment record live under
@@ -36,8 +38,11 @@ a new baseline on a different device or OS runtime.
3638
| Fixture | Focus | lua-objc composition |
3739
|---|---|---|
3840
| `labels` | Font sizes, weights, secondary text, wrapping, SF Symbol label | `views/Window.etlua` labels branch |
39-
| `buttons` | Automatic, bordered, prominent, plain, symbol, disabled | `views/Window.etlua` buttons branch |
40-
| `stacks` | Flexible horizontal spacing, nested stacks, symbol overlay | `views/Window.etlua` stacks branch |
41+
| `buttons` | Automatic, bordered, prominent, plain, destructive, cancel, symbol, disabled, font sizes | `views/Window.etlua` buttons branch |
42+
| `toggles` | On, off, disabled on, disabled off | `views/Window.etlua` toggles branch |
43+
| `tabs` | Three native tabs with SF Symbols and distinct content | `views/Window.etlua` tabs branch |
44+
| `grid` | Three-column by three-row weather-symbol grid | `views/Window.etlua` grid branch |
45+
| `stacks` | Spacer, nested `VStack`, spaced `HStack` metrics, `ZStack` overlay | `views/Window.etlua` stacks branch |
4146
| `controls` | Text field, toggle, slider, progress | `views/Window.etlua` controls branch |
4247

4348
The status bar is normalized to 9:41 with full signal and battery. Appearance,

‎comparison/iphone_swiftui/capture.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ FIXTURES="${1:-all}"
88
export DEVELOPER_DIR
99

1010
case "$FIXTURES" in
11-
all) set -- labels buttons stacks controls ;;
12-
labels|buttons|stacks|controls) set -- "$FIXTURES" ;;
13-
*) echo "usage: capture.sh [all|labels|buttons|stacks|controls]" >&2; exit 2 ;;
11+
all) set -- labels buttons toggles tabs grid stacks controls ;;
12+
labels|buttons|toggles|tabs|grid|stacks|controls) set -- "$FIXTURES" ;;
13+
*) echo "usage: capture.sh [all|labels|buttons|toggles|tabs|grid|stacks|controls]" >&2; exit 2 ;;
1414
esac
1515

1616
APP="$("$ROOT/comparison/iphone_swiftui/build_reference.sh")"

‎comparison/iphone_swiftui/captures/ios-26.5-iphone-17/capture.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
"screenshots": [
1414
"lua-objc-buttons.png",
1515
"lua-objc-controls.png",
16+
"lua-objc-grid.png",
1617
"lua-objc-labels.png",
1718
"lua-objc-stacks.png",
19+
"lua-objc-tabs.png",
20+
"lua-objc-toggles.png",
1821
"swiftui-buttons.png",
1922
"swiftui-controls.png",
23+
"swiftui-grid.png",
2024
"swiftui-labels.png",
21-
"swiftui-stacks.png"
25+
"swiftui-stacks.png",
26+
"swiftui-tabs.png",
27+
"swiftui-toggles.png"
2228
]
2329
}
21.5 KB
Loading
6.18 KB
Loading
126 KB
Loading

0 commit comments

Comments
 (0)