import { ScrollView, ListView, AboutSlint, Slider } from "std-widgets.slint"; import { Theme } from "theme.slint"; import { ActionButton, TextField, Toggle, Choice, RoomIcon, RoomIconButton } from "controls.slint"; import { RichDocument, ChatVisual } from "chat.slint"; export struct SettingsRow { token: string, stable-id: string, title: string, subtitle: string, kind: int, checked: bool, value: string, options: [string], selected: int, enabled: bool, destructive: bool, inset: bool, error: string, meter: float, decrease: string, increase: string, rich: [ChatVisual], swatch: color, red: float, green: float, blue: float, } export global SettingsBridge { in-out property <[string]> categories; in-out property <[string]> category-groups; in-out property <[string]> category-subtitles; in-out property profile-name; in-out property profile-label; in-out property <[SettingsRow]> rows; in-out property category; in-out property title; in-out property status; in-out property error; in-out property back-label; in-out property apply-label; in-out property cancel-label; in-out property panel-open; in-out property subpage; in-out property show-slint; in-out property capturing; callback category-chosen(int); callback back(); callback invoke(string); callback toggle-value(string, bool); callback choice-value(string, int); callback draft(string, string); callback commit(string, string); callback step(string, int); callback capture-lost(); callback color-channel(string, int, float); } component SettingCell inherits Rectangle { in property setting; in property compact; private property secret-draft; private property color-expanded; private property secret-owner: setting.stable-id; changed secret-owner => { root.secret-draft = ""; } callback field-focused(bool); background: Theme.android || setting.kind == 0 ? transparent : Theme.header; min-height: Theme.android ? content.preferred-height : (setting.kind == 0 ? 48px : content.preferred-height + 16px); preferred-height: self.min-height; vertical-stretch: Theme.android ? 0 : 1; VerticalLayout { padding: 0px; content := VerticalLayout { padding-top: root.setting.kind == 0 ? (Theme.android ? 12px : 14px) : 8px; padding-bottom: 8px; padding-left: Theme.android ? (root.setting.inset ? 24px : 12px) : (root.setting.inset ? 36px : 20px); padding-right: Theme.android ? 12px : 20px; spacing: Theme.android ? 6px : 8px; if !Theme.android || (root.setting.title != "" && root.setting.kind != 6 && root.setting.kind != 2): Text { text: root.setting.title; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; font-weight: root.setting.kind == 0 ? 700 : 450; wrap: word-wrap; accessible-role: text; accessible-label: self.text; } if root.setting.subtitle != "" && (!Theme.android || root.setting.kind != 2): Text { text: root.setting.subtitle; color: Theme.muted; font-family: Theme.font-family; font-size: Theme.font-size - 1px; wrap: word-wrap; accessible-role: text; accessible-label: self.text; } if root.setting.kind == 2 && !Theme.android: Toggle { checked: root.setting.checked; enabled: root.setting.enabled; label: root.setting.title; min-height: max(48px, Theme.touch-target); toggled(value) => { self.checked = root.setting.checked; SettingsBridge.toggle-value(root.setting.token, value); } } if root.setting.kind == 2 && Theme.android: HorizontalLayout { spacing: 8px; Text { text: root.setting.title; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; wrap: word-wrap; vertical-alignment: center; horizontal-stretch: 1; min-width: 0px; } Toggle { width: max(48px, Theme.touch-target); horizontal-stretch: 0; checked: root.setting.checked; enabled: root.setting.enabled; label: root.setting.title; toggled(value) => { self.checked = root.setting.checked; SettingsBridge.toggle-value(root.setting.token, value); } } } if Theme.android && root.setting.kind == 2 && root.setting.subtitle != "": Text { text: root.setting.subtitle; color: Theme.muted; wrap: word-wrap; font-family: Theme.font-family; font-size: Theme.font-size - 1px; accessible-role: text; accessible-label: self.text; } if root.setting.kind == 3 && root.setting.stable-id != "palette-presets": Choice { values: root.setting.options; current-index: root.setting.selected; enabled: root.setting.enabled; label: root.setting.title; min-height: max(48px, Theme.touch-target); selected(index) => { self.current-index = root.setting.selected; SettingsBridge.choice-value(root.setting.token, index); } } if root.setting.kind == 3 && root.setting.stable-id == "palette-presets": HorizontalLayout { spacing: 8px; for preset[index] in root.setting.options: ActionButton { text: preset; min-width: 0px; enabled: root.setting.enabled; clicked => { SettingsBridge.choice-value(root.setting.token, index); } } } if root.setting.kind == 4 || root.setting.kind == 5 || root.setting.kind == 8: VerticalLayout { spacing: 4px; field := TextField { text: Theme.android && root.setting.kind == 8 ? root.secret-draft : root.setting.value; placeholder: root.setting.title; secret: root.setting.kind == 8; enabled: root.setting.enabled; min-height: max(48px, Theme.touch-target); min-width: 0px; changed has-focus => { root.field-focused(self.has-focus); } edited(value) => { if Theme.android && root.setting.kind == 8 { root.secret-draft = value; } else { SettingsBridge.draft(root.setting.token, value); } } accepted() => { SettingsBridge.commit(root.setting.token, self.text); if root.setting.kind == 8 { root.secret-draft = ""; } } } HorizontalLayout { spacing: 4px; if root.setting.kind == 5: ActionButton { text: "-"; accessible-label: root.setting.decrease; enabled: root.setting.enabled; min-height: max(48px, Theme.touch-target); clicked => { SettingsBridge.step(root.setting.token, -1); } } if root.setting.kind == 5: ActionButton { text: "+"; accessible-label: root.setting.increase; enabled: root.setting.enabled; min-height: max(48px, Theme.touch-target); clicked => { SettingsBridge.step(root.setting.token, 1); } } ActionButton { text: SettingsBridge.apply-label; enabled: root.setting.enabled; min-height: max(48px, Theme.touch-target); clicked => { SettingsBridge.commit(root.setting.token, field.text); if root.setting.kind == 8 { root.secret-draft = ""; } } } } } if root.setting.kind == 10: VerticalLayout { spacing: 8px; HorizontalLayout { spacing: 8px; TextField { text: root.setting.value; placeholder: "#RRGGBB"; label: root.setting.title + " · #RRGGBB"; enabled: root.setting.enabled; min-width: 0px; horizontal-stretch: 1; changed has-focus => { root.field-focused(self.has-focus); } edited(value) => { SettingsBridge.draft(root.setting.token, value); } accepted => { SettingsBridge.commit(root.setting.token, self.text); } } Rectangle { width: 48px; height: 48px; background: root.setting.swatch; border-radius: 8px; border-width: 1px; border-color: Theme.outline; RoomIconButton { icon: "palette"; label: root.setting.title; enabled: root.setting.enabled; accessible-expandable: true; accessible-expanded: root.color-expanded; clicked => { root.color-expanded = !root.color-expanded; } } } } if root.color-expanded: VerticalLayout { spacing: 8px; for channel[index] in [root.setting.red, root.setting.green, root.setting.blue]: HorizontalLayout { spacing: 8px; Text { text: index == 0 ? "R" : index == 1 ? "G" : "B"; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; width: 24px; vertical-alignment: center; } Slider { minimum: 0; maximum: 255; value: channel; enabled: root.setting.enabled; min-height: 48px; accessible-label: root.setting.title + (index == 0 ? " · R" : index == 1 ? " · G" : " · B"); changed(value) => { SettingsBridge.color-channel(root.setting.token, index, value); } } Text { text: "\{round(channel)}"; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; width: 36px; vertical-alignment: center; } } } } if root.setting.kind == 6: ActionButton { text: root.setting.title; enabled: root.setting.enabled; destructive: root.setting.destructive; primary: Theme.android && root.setting.stable-id == "palette-save"; min-height: max(48px, Theme.touch-target); clicked => { SettingsBridge.invoke(root.setting.token); } } if root.setting.kind == 7: Rectangle { height: 8px; background: Theme.contrast; border-radius: 4px; Rectangle { width: parent.width * clamp(root.setting.meter, 0, 1); height: parent.height; background: Theme.success; border-radius: 4px; } } if root.setting.kind == 9: RichDocument { rows: root.setting.rich; inert: true; } if root.setting.error != "": Text { text: root.setting.error; color: Theme.error; wrap: word-wrap; font-family: Theme.font-family; font-size: Theme.font-size; accessible-role: text; accessible-label: self.text; } } } } component RoomSettingsRow inherits Rectangle { in property category; min-height: max(72px, row-content.preferred-height); vertical-stretch: 0; background: row-touch.pressed ? Theme.bg : transparent; accessible-role: button; accessible-label: SettingsBridge.categories[category] + ". " + SettingsBridge.category-subtitles[category]; accessible-action-default => { SettingsBridge.category-chosen(root.category); } border-width: row-focus.has-focus ? 2px : 0px; border-color: Theme.tint-text; row-content := HorizontalLayout { padding-left: 0px; padding-right: 0px; padding-top: 12px; padding-bottom: 12px; spacing: 16px; RoomIcon { name: root.category == 3 ? "headphones" : root.category == 8 ? "bell" : root.category == 2 ? "palette" : root.category == 0 ? "user" : root.category == 1 ? "shield" : root.category == 4 ? "screen" : root.category == 6 ? "chat" : root.category == 7 ? "users" : root.category == 11 ? "info" : "settings"; ink: Theme.muted; width: 20px; height: 24px; } VerticalLayout { spacing: 4px; alignment: center; Text { text: SettingsBridge.categories[root.category]; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; font-weight: 600; wrap: word-wrap; } Text { text: SettingsBridge.category-subtitles[root.category]; color: Theme.muted; font-family: Theme.font-family; font-size: Theme.font-size * 0.85; wrap: word-wrap; } } RoomIcon { name: "chevron"; ink: Theme.muted; width: 20px; height: 24px; } } Rectangle { y: parent.height - 1px; height: 1px; width: parent.width; background: Theme.outline; } row-focus := FocusScope { key-pressed(event) => { if event.text == Key.Return || event.text == " " { SettingsBridge.category-chosen(root.category); return accept; }return reject; } } row-touch := TouchArea { clicked => { row-focus.focus(); SettingsBridge.category-chosen(root.category); } } } export component SettingsScreen inherits Rectangle { background: Theme.shaded; min-width: 0px; min-height: 0px; preferred-width: 100%; preferred-height: 100%; private property compact: self.width < 600px; private property focused-row-y: -1px; private property focused-row; private property content-title: SettingsBridge.title; changed content-title => { root.focused-row = ""; root.focused-row-y = -1px; } forward-focus: keyboard; keyboard := FocusScope { key-pressed(event) => { if !Theme.android && event.text == Key.Escape && !SettingsBridge.capturing { SettingsBridge.back(); return accept; } if !SettingsBridge.panel-open && event.text == Key.DownArrow { SettingsBridge.category-chosen(SettingsBridge.category < 11 ? SettingsBridge.category + 1 : 0); return accept; } if !SettingsBridge.panel-open && event.text == Key.UpArrow { SettingsBridge.category-chosen(SettingsBridge.category > 0 ? SettingsBridge.category - 1 : 11); return accept; } if !SettingsBridge.panel-open && event.text == Key.Home { SettingsBridge.category-chosen(0); return accept; } if !SettingsBridge.panel-open && event.text == Key.End { SettingsBridge.category-chosen(11); return accept; } return reject; } if !Theme.android: HorizontalLayout { spacing: 0px; if !root.compact || !SettingsBridge.panel-open: Rectangle { width: root.compact ? parent.width : min(280px, root.width * 0.34); background: Theme.bg; VerticalLayout { padding: 12px; spacing: 4px; ActionButton { text: SettingsBridge.back-label; clicked => { SettingsBridge.back(); } min-height: 48px; } ScrollView { VerticalLayout { spacing: 4px; for category[index] in SettingsBridge.categories: VerticalLayout { spacing: 4px; if index == 0 || index == 2 || index == 11: Text { text: SettingsBridge.category-groups[index == 0 ? 0 : index == 2 ? 1 : 2]; color: Theme.muted; font-family: Theme.font-family; font-size: 13px; min-height: 32px; vertical-alignment: center; } Rectangle { min-height: max(48px, Theme.touch-target); background: index == SettingsBridge.category ? Theme.deviant : transparent; border-radius: 4px; ActionButton { text: category; clicked => { SettingsBridge.category-chosen(index); } } } } Rectangle { vertical-stretch: 1; } } } } } if !root.compact || SettingsBridge.panel-open: VerticalLayout { max-width: 680px; horizontal-stretch: 1; padding-left: root.compact ? 8px : 20px; padding-right: root.compact ? 8px : 20px; padding-top: 12px; padding-bottom: 12px; spacing: 8px; if root.compact || SettingsBridge.subpage: ActionButton { text: SettingsBridge.back-label; min-height: 48px; clicked => { SettingsBridge.back(); keyboard.focus(); } } Text { text: SettingsBridge.title; color: Theme.fg; font-family: Theme.font-family; font-size: 24px; font-weight: 700; wrap: word-wrap; accessible-role: text; accessible-label: self.text; } if SettingsBridge.error != "": Text { text: SettingsBridge.error; color: Theme.error; wrap: word-wrap; accessible-role: text; accessible-label: self.text; } if SettingsBridge.status != "": Text { text: SettingsBridge.status; color: Theme.muted; wrap: word-wrap; accessible-role: text; accessible-label: self.text; } settings-list := ListView { for row in SettingsBridge.rows: cell := SettingCell { setting: row; compact: root.compact; } } if SettingsBridge.show-slint: AboutSlint { } } } if Theme.android: VerticalLayout { padding: 20px; spacing: 0px; min-width: 0px; if !SettingsBridge.panel-open: ScrollView { min-height: 0px; min-width: 0px; vertical-stretch: 1; VerticalLayout { spacing: 0px; alignment: start; min-width: 0px; preferred-width: 0px; Rectangle { min-height: max(104px, profile-content.preferred-height); vertical-stretch: 0; accessible-role: button; accessible-label: SettingsBridge.profile-label + ". " + SettingsBridge.profile-name; accessible-action-default => { SettingsBridge.category-chosen(0); } border-width: profile-focus.has-focus ? 2px : 0px; border-color: Theme.tint-text; profile-content := HorizontalLayout { spacing: 14px; padding-top: 12px; padding-bottom: 12px; Rectangle { width: 64px; height: 64px; background: Theme.bg; border-radius: 32px; RoomIcon { name: "user"; ink: Theme.tint-text; x: 16px; y: 16px; width: 32px; height: 32px; } } VerticalLayout { spacing: 4px; alignment: center; Text { text: SettingsBridge.profile-name; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size * 1.25; font-weight: 700; wrap: word-wrap; } Text { text: SettingsBridge.profile-label; color: Theme.muted; font-family: Theme.font-family; font-size: Theme.font-size * 0.85; wrap: word-wrap; } } } profile-focus := FocusScope { key-pressed(event) => { if event.text == Key.Return || event.text == " " { SettingsBridge.category-chosen(0); return accept; }return reject; } } TouchArea { clicked => { profile-focus.focus(); SettingsBridge.category-chosen(0); } } } for category[index] in [3, 8, 2, 0, 1, 4, 5, 6, 7, 9, 10, 11]: VerticalLayout { spacing: 0px; vertical-stretch: 0; min-width: 0px; preferred-width: 0px; if index == 0 || index == 2 || index == 5: Text { text: SettingsBridge.category-groups[index == 0 ? 0 : index == 2 ? 1 : 2]; color: Theme.muted; font-family: Theme.font-family; font-size: Theme.font-size * 0.85; font-weight: 600; min-height: 48px; vertical-alignment: center; wrap: word-wrap; } RoomSettingsRow { category: category; min-width: 0px; } } } } if SettingsBridge.panel-open: phone-list := ScrollView { min-height: 0px; min-width: 0px; vertical-stretch: 1; changed visible-height => { if root.focused-row-y >= 0px { self.content-y = clamp(-root.focused-row-y, min(0px, self.visible-height - self.content-height), 0px); } } VerticalLayout { spacing: 4px; alignment: start; min-width: 0px; preferred-width: 0px; if SettingsBridge.error != "": Text { text: SettingsBridge.error; color: Theme.error; wrap: word-wrap; font-family: Theme.font-family; font-size: Theme.font-size; accessible-role: text; accessible-label: self.text; accessible-live-region: assertive; } if SettingsBridge.status != "": Text { text: SettingsBridge.status; color: Theme.muted; wrap: word-wrap; font-family: Theme.font-family; font-size: Theme.font-size; accessible-role: text; accessible-label: self.text; } for row[index] in SettingsBridge.rows: phone-row := VerticalLayout { spacing: 0px; vertical-stretch: 0; min-width: 0px; preferred-width: 0px; changed y => { if root.focused-row == row.stable-id { root.focused-row-y = self.y; phone-list.content-y = clamp(-self.y, min(0px, phone-list.visible-height - phone-list.content-height), 0px); } } if row.stable-id == "palette-cancel": HorizontalLayout { spacing: 8px; ActionButton { text: row.title; enabled: row.enabled; clicked => { SettingsBridge.invoke(row.token); } } ActionButton { text: SettingsBridge.rows[index + 1].title; primary: true; enabled: SettingsBridge.rows[index + 1].enabled; clicked => { SettingsBridge.invoke(SettingsBridge.rows[index + 1].token); } } } if (row.kind != 0 || row.title != SettingsBridge.title) && row.stable-id != "palette-cancel" && row.stable-id != "palette-save": SettingCell { setting: row; compact: true; min-width: 0px; preferred-width: 0px; vertical-stretch: 0; field-focused(focused) => { if focused { root.focused-row = row.stable-id; root.focused-row-y = phone-row.y; phone-list.content-y = clamp(-phone-row.y, min(0px, phone-list.visible-height - phone-list.content-height), 0px); } else if root.focused-row == row.stable-id { root.focused-row = ""; root.focused-row-y = -1px; } } } } if SettingsBridge.show-slint: AboutSlint { } } } } } }