// On-screen keyboard in the tvOS style: one horizontal row of characters, // the text field above it and the mode chips below. // // Opens in place of the settings content, which fades out. // Only text and icons are drawn here. The glass (field, key track, focus lens, // chips) comes from `keyboard::glass` in Rust, which mirrors the geometry the // App exports (kb-* properties): keep the two in sync. // // Key row: index 0 = space, 1..n-2 = characters, n-1 = delete. import { SpaceIcon, DeleteIcon } from "icons.slint"; export component KeyboardView inherits Rectangle { in property u; in property pane-x; in property pane-y; in property pane-w; in property pane-h; in property field-x; in property field-y; in property field-w; in property field-h; in property row-x; in property row-y; in property row-h; in property key-w; in property chip-x; in property chip-y; in property chip-w; in property chip-h; in property chip-step; in property <[string]> keys; in property <[string]> chips; in property mode; in property pos; in property cpos; in property keys-active; in property chips-active; in property title; in property subtitle; in property shown-text; in property placeholder; in property hint; in property hint-error; in property can-submit; property n: self.keys.length + 2; // ---- heading ---------------------------------------------------------- Text { x: root.pane-x; y: root.pane-y + 88 * root.u; width: root.pane-w; horizontal-alignment: center; text: root.title; font-weight: 700; font-size: 48 * root.u; letter-spacing: -0.8 * root.u; color: #ffffff; overflow: elide; } Text { x: root.pane-x + 80 * root.u; y: root.pane-y + 160 * root.u; width: root.pane-w - 160 * root.u; horizontal-alignment: center; text: root.subtitle; font-size: 24 * root.u; color: #ffffffa8; overflow: elide; } // ---- text field --------------------------------------------------------- Rectangle { x: root.field-x; y: root.field-y; width: root.field-w; height: root.field-h; clip: true; HorizontalLayout { padding-left: 36 * root.u; padding-right: 36 * root.u; alignment: start; spacing: 4 * root.u; if root.shown-text == "": Text { vertical-alignment: center; text: root.placeholder; font-size: 32 * root.u; color: #ffffff59; } if root.shown-text != "": Text { vertical-alignment: center; text: root.shown-text; font-size: 34 * root.u; font-weight: 500; letter-spacing: 1 * root.u; color: #ffffff; } // Blinking caret. Rectangle { width: 3 * root.u; Rectangle { y: (parent.height - self.height) / 2; width: 100%; height: 44 * root.u; border-radius: self.width / 2; background: #ff9a5c; opacity: mod(animation-tick() / 1000ms, 1) < 0.55 ? 1 : 0; } } } } Text { x: root.field-x; y: root.field-y + root.field-h + 20 * root.u; width: root.field-w; horizontal-alignment: center; text: root.hint; font-size: 22 * root.u; color: root.hint-error ? #ff8278 : #ffffff99; } // ---- key row --------------------------------------------------------------- // Keys grow as the focus lens passes them (fish-eye), like on tvOS. for key[i] in root.keys: Text { property f: max(0, 1 - abs(root.pos - (i + 1))) * root.keys-active; x: root.row-x + (i + 1) * root.key-w - 20 * root.u; y: root.row-y; width: root.key-w + 40 * root.u; height: root.row-h; horizontal-alignment: center; vertical-alignment: center; text: key; font-size: (31 + 17 * self.f) * root.u; font-weight: self.f > 0.5 ? 700 : 500; color: self.f > 0.5 ? #121317 : #ffffffd8; } SpaceIcon { property f: max(0, 1 - abs(root.pos)) * root.keys-active; property size: (30 + 10 * self.f) * root.u; x: root.row-x + (root.key-w - self.size) / 2; y: root.row-y + (root.row-h - self.size) / 2; width: self.size; height: self.size; ink: self.f > 0.5 ? #121317 : #ffffffd8; } DeleteIcon { property f: max(0, 1 - abs(root.pos - (root.n - 1))) * root.keys-active; property size: (32 + 10 * self.f) * root.u; x: root.row-x + (root.n - 1) * root.key-w + (root.key-w - self.size) / 2; y: root.row-y + (root.row-h - self.size) / 2; width: self.size; height: self.size; ink: self.f > 0.5 ? #121317 : #ffffffd8; } // ---- mode and action chips ------------------------------------------------------- for label[i] in root.chips: Text { property f: max(0, 1 - abs(root.cpos - i)) * root.chips-active; property submit: i == root.chips.length - 1; property selected: i < 4 && i == root.mode; x: root.chip-x + i * root.chip-step; y: root.chip-y; width: root.chip-w; height: root.chip-h; horizontal-alignment: center; vertical-alignment: center; text: label; font-size: 24 * root.u; font-weight: self.submit || self.selected ? 700 : 500; color: self.submit ? (root.can-submit ? #ffffff : #ffffff66) : self.f > 0.5 ? #121317 : self.selected ? #ff9a5c : #ffffffc8; } }