Files
client/native/ui/dialogs.slint
T
bit9992 8d25224816
android-ci / android-arm64 (push) Failing after 1m29s
Automate isolated Android APK builds and fix phone onboarding
2026-11-11 22:07:47 +03:00

149 lines
10 KiB
Plaintext

import { ScrollView, TextEdit } from "std-widgets.slint";
import { Theme } from "theme.slint";
import { ActionButton, TextField, Choice, Toggle } from "controls.slint";
import { ShellBridge, ShellCommand } from "shell.slint";
export struct ShellField { id: string, label: string, section: string, hint: string, kind: int, value: string, checked: bool, choices: [string], choice-index: int, enabled: bool, advanced: bool, error: string }
export global DialogBridge {
in-out property <bool> visible;
in-out property <bool> onboarding;
in-out property <string> title;
in-out property <string> description;
in-out property <[ShellField]> fields;
in-out property <[ShellCommand]> actions;
in-out property <string> error;
in-out property <bool> busy;
in-out property <bool> destructive;
in-out property <string> confirmation-label;
in-out property <string> confirmation;
in-out property <string> submit-label;
in-out property <string> cancel-label;
in-out property <string> advanced-label;
in-out property <string> loading-label;
callback edit(string, string);
callback choose(string, int);
callback confirm(string);
callback submit();
callback cancel();
}
// Android first-run is a page, not a small modal with its required fields hidden in a scroller.
component AndroidOnboarding inherits Rectangle {
background: Theme.shaded;
accessible-role: form;
accessible-label: DialogBridge.title;
property <bool> typing: Theme.ime-inset > 0px;
VerticalLayout {
padding: root.typing ? 12px : 24px;
spacing: root.typing ? 6px : 16px;
Text { text: DialogBridge.title; color: Theme.fg; font-size: Theme.font-size * (root.typing ? 1.25 : 1.8); font-weight: 700; wrap: word-wrap; }
if !root.typing: Text { text: DialogBridge.description; color: Theme.fg; font-size: Theme.font-size; wrap: word-wrap; }
for field in DialogBridge.fields: VerticalLayout {
spacing: 4px;
vertical-stretch: 0;
Text { text: field.label; color: Theme.fg; font-size: Theme.font-size; }
if field.kind == 0: TextField {
height: Theme.touch-target; vertical-stretch: 0;
text: field.value; placeholder: field.label; enabled: field.enabled && !DialogBridge.busy;
edited(value) => { DialogBridge.edit(field.id,value); }
accepted => { DialogBridge.submit(); }
}
if field.kind == 6: HorizontalLayout {
spacing: 8px; height: Theme.touch-target; vertical-stretch: 0;
for label[index] in field.choices: ActionButton {
text: label; primary: field.choice-index == index; enabled: field.enabled && !DialogBridge.busy;
horizontal-stretch: 1; clicked => { DialogBridge.choose(field.id,index); }
}
}
if field.error != "": Text { text: field.error; color: Theme.error; wrap: word-wrap; accessible-live-region: assertive; }
}
if DialogBridge.error != "": Text { text: DialogBridge.error; color: Theme.error; wrap: word-wrap; accessible-live-region: assertive; }
if DialogBridge.busy: Text { text: DialogBridge.loading-label; color: Theme.fg; }
Rectangle { vertical-stretch: 1; min-height: 0px; }
if !root.typing: VerticalLayout {
spacing: 4px;
vertical-stretch: 0;
for action in DialogBridge.actions: ActionButton { text: action.label; enabled: action.enabled && !DialogBridge.busy; destructive: action.destructive; clicked => { ShellBridge.invoke(action.id); } }
}
ActionButton { height: Theme.touch-target; vertical-stretch: 0; text: DialogBridge.submit-label; primary: true; enabled: !DialogBridge.busy; clicked => { DialogBridge.submit(); } }
ActionButton { height: Theme.touch-target; vertical-stretch: 0; text: DialogBridge.cancel-label; enabled: !DialogBridge.busy; clicked => { DialogBridge.cancel(); } }
}
}
export component ShellDialog inherits Rectangle {
background: Theme.contrast.with-alpha(0.75);
property <bool> fullscreen-onboarding: Theme.android && DialogBridge.onboarding;
// An overlay blocks background pointer input without turning Cancel into a submit.
TouchArea { }
if root.fullscreen-onboarding: AndroidOnboarding { width: root.width; height: root.height; }
if !root.fullscreen-onboarding: dialog := Rectangle {
width: min(parent.width - 24px, 640px);
height: min(parent.height - 24px, layout.preferred-height);
x: (parent.width - self.width)/2;
y: (parent.height - self.height)/2;
background: Theme.contrast;
border-color: Theme.outline;
border-width: 1px;
border-radius: 8px;
accessible-role: form;
accessible-label: DialogBridge.title;
property <bool> advanced: false;
property <length> focused-y: 0px;
layout := VerticalLayout {
padding: 20px; spacing: 12px;
if !Theme.android: Text { text: DialogBridge.title; font-size: Theme.font-size * 1.6; font-weight: 700; color: Theme.fg; wrap: word-wrap; }
if !Theme.android && DialogBridge.description != "": Text { text: DialogBridge.description; color: Theme.muted; wrap: word-wrap; }
form-scroll := ScrollView {
min-height: Theme.android ? min(80px, max(0px, root.height - 112px)) : 80px; max-height: 600px;
changed visible-height => { if Theme.android { self.content-y = clamp(-dialog.focused-y, min(0px, self.visible-height - self.content-height), 0px); } }
VerticalLayout {
spacing: 12px;
if Theme.android: Text { text: DialogBridge.title; font-size: Theme.font-size * 1.6; font-weight: 700; color: Theme.fg; wrap: word-wrap; }
if Theme.android && DialogBridge.description != "": Text { text: DialogBridge.description; color: Theme.muted; wrap: word-wrap; }
for field in DialogBridge.fields: field-row := Rectangle {
visible: !field.advanced || dialog.advanced;
height: self.visible ? row.preferred-height : 0px;
row := VerticalLayout {
spacing: 4px;
Text { text: field.label; color: Theme.fg; wrap: word-wrap; }
if field.kind == 0 || field.kind == 1 || field.kind == 3 || field.kind == 4: TextField {
text: field.value; placeholder: field.label; secret: field.kind == 1; enabled: field.enabled && !DialogBridge.busy;
edited(value) => { DialogBridge.edit(field.id,value); }
changed has-focus => { if self.has-focus { dialog.focused-y = field-row.y; form-scroll.content-y = clamp(-field-row.y,min(0px,form-scroll.visible-height - form-scroll.content-height),0px); } }
}
if field.kind == 2: TextEdit {
text: field.value; enabled: field.enabled && !DialogBridge.busy; wrap: word-wrap; min-height: 110px;
accessible-label: field.label;
edited => { DialogBridge.edit(field.id,self.text); }
changed has-focus => { if self.has-focus { dialog.focused-y = field-row.y; form-scroll.content-y = clamp(-field-row.y,min(0px,form-scroll.visible-height - form-scroll.content-height),0px); } }
}
if field.kind == 5: Toggle { checked: field.checked; label: field.label; enabled: field.enabled && !DialogBridge.busy; toggled(value) => { DialogBridge.edit(field.id,value ? "true" : "false"); } }
if field.kind == 6: Choice { values: field.choices; current-index: field.choice-index; label: field.label; enabled: field.enabled && !DialogBridge.busy; selected(index) => { DialogBridge.choose(field.id,index); } }
if field.hint != "": Text { text: field.hint; color: Theme.muted; wrap: word-wrap; }
if field.error != "": Text { text: field.error; color: Theme.error; wrap: word-wrap; accessible-role: text; }
}
}
for action in DialogBridge.actions: ActionButton { text: action.label; enabled: action.enabled && !DialogBridge.busy; destructive: action.destructive; clicked => { ShellBridge.invoke(action.id); } }
ActionButton { text: DialogBridge.advanced-label; clicked => { dialog.advanced = !dialog.advanced; } }
if DialogBridge.confirmation-label != "": Text { text: DialogBridge.confirmation-label; color: Theme.warning; wrap: word-wrap; }
if DialogBridge.confirmation-label != "": TextField { text: DialogBridge.confirmation; placeholder: DialogBridge.confirmation-label; enabled: !DialogBridge.busy; edited(value) => { DialogBridge.confirm(value); } }
if Theme.android && DialogBridge.error != "": Text { text: DialogBridge.error; color: Theme.error; wrap: word-wrap; accessible-live-region: assertive; }
if Theme.android && DialogBridge.busy: Text { text: DialogBridge.loading-label; color: Theme.muted; }
}
}
if !Theme.android && DialogBridge.error != "": Text { text: DialogBridge.error; color: Theme.error; wrap: word-wrap; accessible-live-region: assertive; }
if !Theme.android && DialogBridge.busy: Text { text: DialogBridge.loading-label; color: Theme.muted; }
if !Theme.android: HorizontalLayout {
alignment: end; spacing: 8px;
ActionButton { text: DialogBridge.cancel-label; clicked => { DialogBridge.cancel(); } }
ActionButton { text: DialogBridge.submit-label; primary: true; destructive: DialogBridge.destructive; enabled: !DialogBridge.busy; clicked => { DialogBridge.submit(); } }
}
if Theme.android: HorizontalLayout {
spacing: 8px;
ActionButton { min-width: 48px; horizontal-stretch: 1; text: DialogBridge.cancel-label; clicked => { DialogBridge.cancel(); } }
ActionButton { min-width: 48px; horizontal-stretch: 1; text: DialogBridge.submit-label; primary: true; destructive: DialogBridge.destructive; enabled: !DialogBridge.busy; clicked => { DialogBridge.submit(); } }
}
}
}
}