Files
client/native/ui/settings.slint
T

675 lines
40 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { ComboBox, ScrollView, ListView, AboutSlint } from "std-widgets.slint";
import { Theme } from "theme.slint";
import { ActionButton, TextField, Toggle, Choice } 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],
command-label: string,
section-start: bool, section-end: bool, stacked: bool,
}
export global SettingsBridge {
in-out property <[string]> categories;
in-out property <[string]> category-groups;
in-out property <length> category-label-width;
in-out property <[SettingsRow]> rows;
in-out property <string> identity-export-label;
in-out property <string> identity-export-token;
in-out property <string> identity-copy-label;
in-out property <string> identity-copy-token;
in-out property <[SettingsRow]> server-user-rows;
in-out property <[SettingsRow]> server-channel-rows;
in-out property <bool> appearance-page;
in-out property <int> category;
in-out property <string> title;
in-out property <string> status;
in-out property <string> error;
in-out property <string> back-label;
in-out property <string> apply-label;
in-out property <string> cancel-label;
in-out property <bool> panel-open;
in-out property <bool> subpage;
in-out property <bool> show-slint;
in-out property <string> about-page;
in-out property <string> focus-row;
in-out property <bool> 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();
}
component SettingEditor inherits Rectangle {
in property <SettingsRow> setting;
in property <length> control-height;
in property <bool> compact;
private property <bool> stacked: compact || self.width < 300px;
private property <bool> numeric: setting.kind == 5;
min-width: 0px;
min-height: stacked ? 2 * control-height + 4px : control-height;
preferred-height: self.min-height;
field := TextField {
x: 0px; y: 0px; width: root.stacked ? root.width : max(0px, buttons.x - 8px); height: root.control-height;
text: root.setting.value; placeholder: root.setting.title; secret: root.setting.kind == 8;
enabled: root.setting.enabled; min-height: root.control-height;
edited(value) => { SettingsBridge.draft(root.setting.token, value); }
accepted() => { SettingsBridge.commit(root.setting.token, self.text); }
}
buttons := HorizontalLayout {
spacing: 4px;
width: root.stacked ? root.width : self.preferred-width;
x: root.width - self.width; y: root.stacked ? root.control-height + self.spacing : 0px; height: root.control-height;
if root.numeric: ActionButton {
text: "-"; accessible-label: root.setting.decrease; enabled: root.setting.enabled;
min-width: root.compact ? 44px : root.control-height;
min-height: root.control-height; preferred-height: root.control-height;
clicked => { SettingsBridge.step(root.setting.token, -1); }
}
if root.numeric: ActionButton {
text: "+"; accessible-label: root.setting.increase; enabled: root.setting.enabled;
min-width: root.compact ? 44px : root.control-height;
min-height: root.control-height; preferred-height: root.control-height;
clicked => { SettingsBridge.step(root.setting.token, 1); }
}
ActionButton { text: SettingsBridge.apply-label; enabled: root.setting.enabled;
min-height: root.control-height; preferred-height: root.control-height;
clicked => { SettingsBridge.commit(root.setting.token, field.text); }
}
}
}
component AppearanceTile inherits Rectangle {
in property <string> caption;
in property <int> option-index;
in property <bool> scale-preview;
in property <bool> selected;
in property <bool> enabled;
callback activated();
private property <bool> dark-swatch: !scale-preview && option-index == 0;
private property <bool> light-swatch: !scale-preview && option-index == 1;
private property <color> ink: Theme.high-contrast ? Theme.fg : dark-swatch ? #ffffff : light-swatch ? #1a1a1a : Theme.fg;
private property <color> surface: Theme.high-contrast ? Theme.bg : dark-swatch ? #1c2539 : light-swatch ? #bccbeb : scale-preview ? Theme.shaded : Theme.bg;
border-radius: scale-preview ? 10px : 15px;
background: surface;
opacity: enabled || Theme.high-contrast ? 1 : 0.6;
accessible-role: radio-button;
accessible-label: caption;
accessible-enabled: enabled;
accessible-checkable: true;
accessible-checked: selected;
accessible-item-selectable: true;
accessible-item-selected: selected;
accessible-action-default => { if root.enabled && !root.selected { root.activated(); } }
Text {
x: root.scale-preview && root.width >= 140px ? 20px : 6px;
y: root.scale-preview ? 2px : 0px;
width: max(0px, parent.width - 2 * self.x);
height: root.scale-preview ? parent.height - preview.height - self.y : parent.height;
text: root.caption; color: root.ink; font-family: Theme.font-family; font-size: Theme.font-size - 1px;
wrap: word-wrap;
horizontal-alignment: root.scale-preview ? left : center;
vertical-alignment: center;
accessible-role: none;
}
preview := Rectangle {
visible: root.scale-preview;
private property <length> dot: (9 + root.option-index) * 1px;
private property <length> pitch: root.option-index == 2 ? 19px : root.option-index == 1 ? 16px : 14px;
private property <length> stroke: root.option-index == 2 ? 8px : 7px;
x: root.width >= 140px ? 10px : 4px;
y: root.height - self.height;
width: max(0px, parent.width - 2 * self.x);
height: root.scale-preview ? 96px : 0px;
border-radius: 4px;
background: Theme.bg;
clip: true;
for row in 5: Rectangle {
x: preview.width >= 140px ? 14px : 5px;
y: 10px + row * preview.pitch;
width: max(0px, preview.width - 2 * self.x);
height: preview.dot;
Rectangle { x: 0px; width: preview.dot; height: preview.dot; border-radius: self.width / 2; background: root.ink; }
Rectangle {
x: preview.dot + 7px; y: (parent.height - self.height) / 2;
width: max(0px, parent.width - self.x) * (row == 0 || row == 3 ? 0.52 : row == 4 ? 0.34 : 0.77);
height: preview.stroke; border-radius: 1px; background: root.ink.with-alpha(0.62);
}
}
Rectangle {
y: parent.height - self.height; width: parent.width; height: 20px;
background: @linear-gradient(180deg, root.surface.with-alpha(0), root.surface);
}
}
Rectangle {
background: transparent; border-radius: root.border-radius;
border-width: root.selected ? 2px : (Theme.high-contrast || pointer.has-hover ? 1px : 0px);
border-color: root.selected && !Theme.high-contrast ? Theme.tint-secondary : Theme.outline;
}
if focus.has-focus: Rectangle {
x: 4px; y: 4px; width: max(0px, root.width - 8px); height: max(0px, root.height - 8px);
border-radius: max(0px, root.border-radius - 4px); border-width: 2px; border-color: root.ink;
}
focus := FocusScope {
enabled: root.enabled;
key-pressed(event) => {
if event.text == Key.Return || event.text == " " {
if !root.selected { root.activated(); }
return accept;
}
return reject;
}
}
pointer := TouchArea {
enabled: root.enabled; mouse-cursor: MouseCursor.pointer;
clicked => { focus.focus(); if !root.selected { root.activated(); } }
}
}
component AppearancePicker inherits Rectangle {
in property <SettingsRow> setting;
private property <bool> scale-preview: setting.kind == 11;
private property <length> system-width: min(118px, self.width * 0.28);
min-width: 0px;
min-height: scale-preview ? max(124px, 96px + 2 * (Theme.font-size - 1px)) : max(78px, 32px + 2 * Theme.font-size);
preferred-height: self.min-height;
accessible-role: radio-group;
accessible-label: setting.title;
HorizontalLayout {
spacing: 10px;
for option[index] in root.setting.options: AppearanceTile {
width: root.scale-preview ? max(0px, (root.width - 20px) / 3) : index == 2 ? root.system-width : max(0px, (root.width - root.system-width - 20px) / 2);
caption: option; option-index: index; scale-preview: root.scale-preview;
enabled: root.setting.enabled; selected: index == root.setting.selected;
activated => { SettingsBridge.choice-value(root.setting.token, index); }
}
}
}
component AppearanceSelect inherits Rectangle {
in property <SettingsRow> setting;
in property <length> control-height;
private property <bool> locale: setting.kind == 13;
private property <length> leading: locale ? 44px : 45px;
min-width: 0px;
min-height: max(control-height, caption.preferred-height + 12px);
preferred-height: self.min-height;
background: Theme.bg;
border-radius: 10px;
border-width: input.has-focus || Theme.high-contrast ? 2px : 0px;
border-color: Theme.focus-ring;
opacity: setting.enabled || Theme.high-contrast ? 1 : 0.6;
if root.locale && root.setting.selected >= 0: Rectangle {
x: 18px; y: (parent.height - self.height) / 2; width: 22px; height: 12px;
background: #ffffff; clip: true;
if root.setting.selected == 0: Rectangle {
for stripe in 6: Rectangle { y: stripe * 2px + 1px; width: parent.width; height: 1px; background: #b22234; }
Rectangle { x: 0px; y: 0px; width: 9px; height: 6px; background: #3c3b6e; }
}
if root.setting.selected == 1: Rectangle {
Rectangle { y: 4px; width: parent.width; height: 4px; background: #0039a6; }
Rectangle { y: 8px; width: parent.width; height: 4px; background: #d52b1e; }
}
}
if !root.locale: Rectangle {
x: 24px; y: (parent.height - self.height) / 2;
width: root.setting.selected == 0 ? 8px : 12px;
height: root.setting.selected == 1 ? 5px : 3px;
border-radius: self.height / 2; background: Theme.fg;
}
caption := Text {
x: root.leading; width: max(0px, parent.width - self.x - 22px);
text: root.setting.selected >= 0 ? root.setting.options[root.setting.selected] : "";
color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size;
vertical-alignment: center; wrap: word-wrap;
}
Path {
x: parent.width - 18px; y: (parent.height - self.height) / 2;
width: 10px; height: 5px; commands: "M 0 0 L 10 0 L 5 5 Z";
fill: Theme.high-contrast ? Theme.fg : Theme.tint-secondary;
}
input := ComboBox {
width: parent.width; height: parent.height; opacity: 0;
model: root.setting.options; current-index: root.setting.selected;
enabled: root.setting.enabled; accessible-label: root.setting.title;
selected(value) => {
let index = self.current-index;
self.current-index = root.setting.selected;
SettingsBridge.choice-value(root.setting.token, index);
}
}
changed setting => { input.current-index = root.setting.selected; }
}
component IdentitySelector inherits Rectangle {
in property <SettingsRow> setting;
context := ContextMenuArea {
width: parent.width; height: parent.height;
enabled: root.setting.enabled && SettingsBridge.identity-export-token != "";
Menu {
MenuItem {
title: SettingsBridge.identity-export-label;
activated => { SettingsBridge.invoke(SettingsBridge.identity-export-token); }
}
MenuItem {
title: SettingsBridge.identity-copy-label;
activated => { SettingsBridge.invoke(SettingsBridge.identity-copy-token); }
}
}
parity-identity-selector := FocusScope {
width: parent.width; height: parent.height;
forward-focus: input;
key-pressed(event) => {
if event.text == Key.F10 && event.modifiers.shift && context.enabled {
context.show({ x: 0px, y: self.height });
return accept;
}
return reject;
}
input := Choice {
width: parent.width; height: parent.height;
values: root.setting.options; current-index: root.setting.selected;
enabled: root.setting.enabled; label: root.setting.title;
selected(index) => { SettingsBridge.choice-value(root.setting.token, index); }
}
}
}
}
component SettingCell inherits Rectangle {
in property <SettingsRow> setting;
in property <bool> compact;
in property <bool> appearance;
in property <bool> grid-item;
in property <bool> focus-action;
callback action-focused();
private property <bool> heading: setting.kind == 0;
private property <bool> choice: setting.kind == 3;
private property <bool> field: setting.kind == 4 || setting.kind == 5 || setting.kind == 8;
private property <bool> action: setting.kind == 6;
private property <bool> has-label: (setting.title != "" && (!action || compact)) || setting.subtitle != "";
private property <bool> appearance-select: setting.kind == 13 || setting.kind == 14;
private property <bool> touch: compact || (appearance && Theme.touch-controls);
private property <bool> inline: grid-item || (appearance && setting.kind == 2)
|| (!compact && (setting.kind == 2 || (choice && !setting.stacked && available >= 330px)
|| (appearance-select && available >= 430px) || (field && available >= 540px) || (action && has-label && available >= 420px)));
private property <length> left-inset: right-inset + (setting.inset ? 16px : 0px);
private property <length> right-inset: grid-item ? 10px : (compact || self.width >= 440px ? 20px : 10px);
private property <length> available: max(0px, self.width - left-inset - right-inset);
private property <length> top-padding: grid-item ? 0px : compact ? (heading ? 14px : 8px) : (setting.section-start ? (heading ? 12px : 8px) : 0px);
private property <length> label-spacing: has-label && editor.height > 0px ? (compact || appearance || setting.stacked ? 8px : 4px) : 0px;
private property <length> content-height: inline ? max(details.height, editor.height) : details.height + label-spacing + editor.height;
private property <length> body-height: grid-item ? max(64px, content-height) : content-height;
private property <length> bottom-padding: grid-item ? 0px : compact ? (heading ? 8px : 24px) : (setting.section-end ? 8px : heading ? (appearance ? 16px : 20px) : setting.kind == 11 ? 28px : 24px);
private property <length> error-height: setting.error == "" ? 0px : error-message.preferred-height + (compact ? 8px : 4px);
private property <length> card-height: top-padding + body-height + error-height + bottom-padding;
private property <length> control-height: touch ? max(48px, Theme.touch-target) : appearance-select ? 34px : (setting.stacked ? 33px : 26px);
min-height: compact && heading ? max(48px, card-height) : card-height + (!compact && setting.section-end ? 12px : 0px);
preferred-height: self.min-height;
// A section continues across independently focusable list delegates.
if !root.grid-item && (!root.compact || !root.heading): Rectangle {
x: 0px; y: 0px; width: root.width; height: root.card-height;
background: Theme.header;
border-radius: !root.compact && (root.setting.section-start || root.setting.section-end) ? 15px : 0px;
if !root.compact && root.setting.section-start && !root.setting.section-end: Rectangle {
x: 0px; y: parent.height / 2; width: parent.width; height: parent.height / 2; background: Theme.header;
}
if !root.compact && !root.setting.section-start && root.setting.section-end: Rectangle {
x: 0px; y: 0px; width: parent.width; height: parent.height / 2; background: Theme.header;
}
}
details := VerticalLayout {
x: root.left-inset;
y: root.top-padding + (root.inline ? (root.body-height - self.height) / 2 : 0px);
width: max(0px, root.available - (root.inline ? editor.width + (root.grid-item ? 10px : 20px) : 0px));
height: root.has-label ? self.preferred-height : 0px;
spacing: root.compact ? 8px : 4px;
if root.setting.title != "" && (!root.action || root.compact): Text {
text: root.setting.title; color: Theme.fg; font-family: Theme.font-family;
font-size: root.compact || root.heading ? Theme.font-size : Theme.font-size - 1px;
font-weight: root.heading ? (root.compact ? 700 : 600) : 450;
wrap: word-wrap; accessible-role: text; accessible-label: self.text;
}
if root.setting.subtitle != "": Text {
text: root.setting.subtitle; color: root.appearance && !Theme.high-contrast ? Theme.subtitle : Theme.muted; font-family: Theme.font-family;
font-size: Theme.font-size - (root.compact ? 1px : 2px); wrap: word-wrap;
accessible-role: text; accessible-label: self.text;
}
}
editor := VerticalLayout {
x: root.inline ? root.width - root.right-inset - self.width : root.left-inset;
y: root.top-padding + (root.inline ? (root.body-height - self.height) / 2 : details.height + root.label-spacing);
width: !root.inline ? root.available : root.setting.kind == 2 ? (root.touch ? 48px : (root.appearance ? 40px : 44px)) :
root.appearance-select ? min(root.available * 0.55, max(root.setting.kind == 13 ? 135px : 160px, choice-measure.preferred-width + 80px)
+ (root.setting.command-label != "" ? command-measure.preferred-width + 8px : 0px)) :
root.field ? min(360px, root.available * 0.58) : min(260px, root.available * 0.48);
height: self.preferred-height;
if root.setting.kind == 2: Toggle {
checked: root.setting.checked; enabled: root.setting.enabled; label: root.setting.title;
min-width: 0px; min-height: root.control-height; preferred-height: root.control-height;
toggled(value) => { SettingsBridge.toggle-value(root.setting.token, value); }
}
if root.choice && root.setting.stable-id == "identity-select": IdentitySelector {
setting: root.setting;
min-width: 0px; min-height: root.control-height; preferred-height: root.control-height;
}
if root.choice && root.setting.stable-id != "identity-select": Choice {
values: root.setting.options; current-index: root.setting.selected;
enabled: root.setting.enabled; label: root.setting.title;
min-width: 0px; min-height: root.control-height; preferred-height: root.control-height;
selected(index) => { SettingsBridge.choice-value(root.setting.token, index); }
}
if root.setting.kind == 10 || root.setting.kind == 11: AppearancePicker { setting: root.setting; }
if root.setting.kind == 13: HorizontalLayout {
spacing: 8px;
ActionButton {
horizontal-stretch: 0; text: root.setting.command-label; enabled: root.setting.enabled;
min-height: root.control-height; cross-axis-self-alignment: center;
clicked => { SettingsBridge.invoke(root.setting.token); }
}
AppearanceSelect { setting: root.setting; control-height: root.control-height; horizontal-stretch: 1; }
}
if root.setting.kind == 14: AppearanceSelect { setting: root.setting; control-height: root.control-height; }
if root.field: SettingEditor { setting: root.setting; control-height: root.control-height; compact: root.compact; }
if root.action: HorizontalLayout {
alignment: root.compact ? stretch : (root.inline ? end : start);
ActionButton {
text: root.setting.title; enabled: root.setting.enabled; destructive: root.setting.destructive;
min-width: 0px; preferred-width: self.natural-width; max-width: editor.width;
min-height: root.control-height; preferred-height: root.control-height;
private property <bool> restore-focus: root.focus-action && self.enabled;
init => { if self.restore-focus { self.focus(); } }
changed restore-focus => { if self.restore-focus { self.focus(); } }
changed has-focus => { if self.has-focus { root.action-focused(); } }
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;
x: 0px; y: 0px; background: Theme.success; border-radius: 4px; }
}
if root.setting.kind == 9: RichDocument { rows: root.setting.rich; inert: true; }
}
choice-measure := Text {
visible: false;
text: root.appearance-select && root.setting.selected >= 0 ? root.setting.options[root.setting.selected] : "";
font-family: Theme.font-family; font-size: Theme.font-size;
}
command-measure := Text {
visible: false; text: root.setting.command-label; font-family: Theme.font-family; font-size: Theme.font-size;
}
error-message := Text {
visible: root.setting.error != "";
x: root.left-inset;
y: root.top-padding + root.body-height + (root.compact ? 8px : 4px);
width: root.available; height: self.preferred-height;
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 AppearanceServerGrid inherits Rectangle {
in property <bool> compact;
private property <length> inset: compact || self.width >= 440px ? 20px : 10px;
private property <bool> two-columns: !compact && self.width - 2 * inset >= 540px;
private property <length> column-width: max(0px, (self.width - 2 * inset) / (two-columns ? 2 : 1));
private property <length> column-gap: 16px;
min-height: (two-columns ? max(user-settings.preferred-height, channel-settings.preferred-height)
: user-settings.preferred-height + column-gap + channel-settings.preferred-height) + 24px;
preferred-height: self.min-height;
background: Theme.header;
user-settings := VerticalLayout {
x: root.inset; y: 0px; width: root.column-width; height: self.preferred-height; spacing: root.column-gap;
for row in SettingsBridge.server-user-rows: SettingCell {
setting: row; compact: root.compact; appearance: true; grid-item: true;
}
}
channel-settings := VerticalLayout {
x: root.inset + (root.two-columns ? root.column-width : 0px);
y: root.two-columns ? 0px : user-settings.preferred-height + root.column-gap;
width: root.column-width; height: self.preferred-height; spacing: root.column-gap;
for row in SettingsBridge.server-channel-rows: SettingCell {
setting: row; compact: root.compact; appearance: true; grid-item: true;
}
}
}
component SettingsPath inherits Path {
width: 100%; height: 100%; viewbox-width: 24; viewbox-height: 24;
stroke-width: 1.6px;
}
component CategoryIcon inherits Rectangle {
in property <int> category;
in property <color> ink: Theme.muted;
// Original outline glyphs in a shared 24-unit coordinate system.
if category == -1: SettingsPath { stroke: root.ink; commands: "M9 3H15L16 6 19 6 22 11 20 13 21 16 18 21 15 20 12 22 9 20 6 21 3 16 4 13 2 11 5 6 8 6Z M15.5 12A3.5 3.5 0 1 0 8.5 12 3.5 3.5 0 1 0 15.5 12Z"; }
if category == 0: SettingsPath { stroke: root.ink; commands: "M3 5H21V19H3Z M7 15C7 11 13 11 13 15 M12 10A2 2 0 1 0 8 10 2 2 0 1 0 12 10Z M15 10H19 M15 14H19"; }
if category == 1: SettingsPath { stroke: root.ink; commands: "M12 3L20 6V11C20 16 16 20 12 22 8 20 4 16 4 11V6Z M9 12L11 14 15 10"; }
if category == 2: SettingsPath { stroke: root.ink; commands: "M3 4H21V16H3Z M8 21H16 M12 16V21 M6 12L10 8 13 11 16 8 19 12"; }
if category == 3: SettingsPath { stroke: root.ink; commands: "M4 13V11A8 8 0 0 1 20 11V13 M4 12H7V20H4C2 20 2 12 4 12Z M20 12H17V20H20C22 20 22 12 20 12Z"; }
if category == 4: SettingsPath { stroke: root.ink; commands: "M3 6H15V18H3Z M15 10L21 7V17L15 14"; }
if category == 5: SettingsPath { stroke: root.ink; commands: "M2 6H22V18H2Z M5 10H7 M9 10H11 M13 10H15 M17 10H19 M5 14H7 M9 14H15 M17 14H19"; }
if category == 6: SettingsPath { stroke: root.ink; commands: "M3 4H21V16H11L6 21V16H3Z M7 8H17 M7 12H14"; }
if category == 7: SettingsPath { stroke: root.ink; commands: "M5 15H2V5H17V8 M6 15V19L11 15H14 M9 10H22V19H19V22L15 19H9Z"; }
if category == 8: SettingsPath { stroke: root.ink; commands: "M4 17C7 14 6 11 7 8A5 5 0 0 1 17 8C18 11 17 14 20 17Z M9 20A3 3 0 0 0 15 20"; }
if category == 9: SettingsPath { stroke: root.ink; commands: "M3 4H13L18 9V11 M3 4V20H8 M13 4V9H18 M10 14H21 M18 11L21 14 18 17 M21 20H10 M13 17L10 20 13 23"; }
if category == 10: SettingsPath { stroke: root.ink; commands: "M4 5H20V19H4Z M4 9H20 M7 7H8 M10 7H11 M8 13H16 M8 16H13"; }
if category == 11: SettingsPath { stroke: root.ink; commands: "M21 12A9 9 0 1 0 3 12 9 9 0 1 0 21 12Z M12 11V17 M12 7V9"; }
}
component SettingsCategory inherits Rectangle {
in property <string> label;
in property <int> category;
in property <bool> active;
in property <bool> rail;
private property <length> left: rail ? 10px : 20px;
private property <length> right: rail ? 8px : 30px;
min-width: 0px;
min-height: max(max(44px, Theme.touch-target), caption.preferred-height + 8px);
preferred-height: self.min-height;
vertical-stretch: 0;
accessible-role: button;
accessible-label: label;
accessible-item-selectable: true;
accessible-item-selected: active;
accessible-action-default => { SettingsBridge.category-chosen(root.category); }
Rectangle {
x: root.rail ? 5px : 10px; y: 2px; width: parent.width - self.x - root.right; height: parent.height - 4px;
border-radius: 4px;
background: root.active ? Theme.settings-highlight : pointer.has-hover ? Theme.shaded : transparent;
border-width: keyboard.has-focus || Theme.high-contrast ? 2px : 0px;
border-color: Theme.outline;
}
if active: Rectangle {
x: 0px; y: 6px; width: 4px; height: parent.height - 12px;
border-radius: 2px; background: Theme.tint;
}
CategoryIcon { category: root.category; ink: root.active ? Theme.tint : (Theme.high-contrast ? Theme.fg : Theme.subtitle);
x: root.left; y: (parent.height - self.height) / 2; width: 33px; height: 33px; }
caption := Text {
x: root.left + 43px; width: max(0px, parent.width - self.x - root.right);
text: root.label; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size - 1px;
wrap: word-wrap; vertical-alignment: center;
}
keyboard := FocusScope { key-pressed(event) => {
if event.text == "\n" || event.text == " " { SettingsBridge.category-chosen(root.category); return accept; }
return reject;
} }
pointer := TouchArea { clicked => { keyboard.focus(); SettingsBridge.category-chosen(root.category); } }
}
export component SettingsScreen inherits Rectangle {
background: compact ? Theme.shaded : Theme.bg;
min-width: 0px; min-height: 0px;
preferred-width: 100%; preferred-height: 100%;
in property <length> window-width: self.width;
in property <string> settings-label;
private property <bool> compact: self.width < 600px;
private property <bool> narrow-pc: window-width < 900px;
// Preserve the source's 30–50ch flex basis and its wider localized min-content rail.
private property <length> category-width: narrow-pc ? min(240px, self.width * 0.34) :
clamp(max(30 * digit.preferred-width, SettingsBridge.category-label-width + 153px), window-width * 0.2, 50 * digit.preferred-width);
private property <length> page-offset: compact ? 0px : category-width;
private property <length> page-width: max(0px, self.width - page-offset);
private property <length> page-clearance: compact ? 8px : page-width < 440px ? 10px : 20px;
private property <length> article-width: min(readability, max(0px, page-width - 2 * page-clearance));
private property <length> readability: window-width < 1000px ? 640px : window-width < 1200px ? 800px : window-width < 1400px ? 1000px : window-width < 1800px ? 1200px : 1600px;
digit := Text { text: "0"; font-family: Theme.font-family; font-size: Theme.font-size - 1px; visible: false; }
forward-focus: keyboard;
keyboard := FocusScope {
key-pressed(event) => {
if 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;
}
Rectangle {
width: 100%; height: 100%;
if !root.compact || !SettingsBridge.panel-open: parity-settings-nav := Rectangle {
x: 0px; y: 0px; height: parent.height;
width: root.compact ? parent.width : root.category-width;
background: root.compact ? Theme.bg : root.narrow-pc ? Theme.header : transparent;
VerticalLayout {
padding-top: root.compact ? 12px : 8px; padding-bottom: root.compact ? 12px : 8px;
padding-left: root.compact ? 12px : root.narrow-pc ? 8px : 20px;
padding-right: root.compact ? 12px : 10px; spacing: root.compact ? 4px : 0px;
if root.compact: ActionButton { text: SettingsBridge.back-label; clicked => { SettingsBridge.back(); } min-height: 48px; }
if !root.compact: HorizontalLayout {
min-height: root.narrow-pc ? 36px : 49px; spacing: 10px;
padding-left: root.narrow-pc ? 5px : 8px;
if !root.narrow-pc: Rectangle {
width: 33px;
CategoryIcon { category: -1; width: 33px; height: 33px; y: (parent.height - self.height) / 2; }
}
Text { text: root.settings-label; color: Theme.high-contrast ? Theme.fg : Theme.subtitle; font-family: Theme.font-family;
font-size: Theme.font-size - 1px; wrap: word-wrap; vertical-alignment: center;
horizontal-stretch: 1; accessible-role: text; accessible-label: self.text; }
ActionButton { text: SettingsBridge.back-label; min-width: 0px; min-height: 26px; preferred-height: 26px;
clicked => { SettingsBridge.back(); } }
}
ScrollView {
VerticalLayout { spacing: root.compact ? 4px : 0px;
for category[index] in SettingsBridge.categories: VerticalLayout {
vertical-stretch: 0;
spacing: root.compact ? 4px : 0px;
if index == 0 || index == 2 || index == 11: VerticalLayout {
padding-left: root.compact ? 0px : 10px;
padding-top: root.compact ? 0px : 4px;
Text {
text: SettingsBridge.category-groups[index == 0 ? 0 : index == 2 ? 1 : 2];
color: root.compact ? Theme.muted : (Theme.high-contrast ? Theme.fg : Theme.subtitle);
font-family: Theme.font-family; font-size: Theme.font-size - 2px;
min-height: root.compact ? 32px : 19px; vertical-alignment: center;
accessible-role: text; accessible-label: self.text;
}
}
if root.compact: 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); } }
}
if !root.compact: SettingsCategory { label: category; category: index;
active: index == SettingsBridge.category; rail: root.narrow-pc; }
}
Rectangle { vertical-stretch: 1; }
}
}
}
}
if !root.compact || SettingsBridge.panel-open: parity-settings-panel := Rectangle {
x: root.page-offset; y: 0px; width: root.page-width; height: parent.height;
accessible-role: groupbox;
accessible-label: SettingsBridge.title;
VerticalLayout {
padding-top: root.compact ? 12px : SettingsBridge.appearance-page ? 0px : 20px;
padding-bottom: root.compact ? 12px : SettingsBridge.appearance-page ? 0px : 8px;
spacing: root.compact ? 8px : 4px;
if root.compact || SettingsBridge.subpage || SettingsBridge.error != "" || SettingsBridge.status != "": HorizontalLayout {
alignment: center;
vertical-stretch: 0;
VerticalLayout {
width: root.article-width; spacing: root.compact ? 8px : 4px;
alignment: start;
if root.compact || SettingsBridge.subpage: ActionButton {
text: SettingsBridge.back-label; min-height: root.compact ? 48px : 26px;
vertical-stretch: 0;
private property <string> entry-focus: SettingsBridge.focus-row == "about-back" ? SettingsBridge.about-page : "";
init => { if self.entry-focus != "" { self.focus(); } }
changed entry-focus => { if self.entry-focus != "" { self.focus(); } }
clicked => {
SettingsBridge.back();
if SettingsBridge.about-page == "" || !SettingsBridge.subpage { keyboard.focus(); }
}
}
if root.compact: Text { text: SettingsBridge.title; color: Theme.fg; font-family: Theme.font-family;
vertical-stretch: 0;
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; }
}
}
if SettingsBridge.about-page == "": ListView {
vertical-stretch: 1;
for setting[index] in SettingsBridge.rows: Rectangle {
property <length> top-inset: index == 0 && !root.compact && SettingsBridge.appearance-page ? 20px : 0px;
height: top-inset + article.preferred-height;
article := VerticalLayout {
x: (root.page-width - root.article-width) / 2; y: parent.top-inset;
width: root.article-width; height: self.preferred-height;
if setting.kind == 12: AppearanceServerGrid { compact: root.compact; }
if setting.kind != 12: SettingCell {
setting: setting; compact: root.compact; appearance: SettingsBridge.appearance-page;
}
}
}
}
// A regular scroll layout keeps the bounded bundled inventory's offscreen
// actions alive so Back can focus the actual row even after a long license.
if SettingsBridge.about-page != "": about-scroll := ScrollView {
min-height: 0px;
vertical-stretch: 1;
accessible-role: list;
content-width: self.visible-width;
content-height: about-article.preferred-height;
private property <string> reset-page: SettingsBridge.focus-row == "about-back" ? SettingsBridge.about-page : "";
changed reset-page => { if self.reset-page != "" { self.content-y = 0px; } }
about-article := VerticalLayout {
x: max(0px, (about-scroll.visible-width - self.width) / 2);
width: min(root.article-width, about-scroll.visible-width);
for entry in SettingsBridge.rows: SettingCell {
setting: entry; compact: root.compact;
focus-action: entry.stable-id != "" && entry.stable-id == SettingsBridge.focus-row;
action-focused => {
let previous = about-scroll.content-y;
let bottom = about-scroll.visible-height - self.y - self.height;
let closest = clamp(previous, min(bottom, -self.y), -self.y);
about-scroll.content-y = clamp(closest, min(0px, about-scroll.visible-height - about-scroll.content-height), 0px);
}
}
if SettingsBridge.show-slint && SettingsBridge.subpage: AboutSlint { }
}
}
if SettingsBridge.show-slint && !SettingsBridge.subpage: AboutSlint { }
}
}
}
}
}