diff --git a/crates/tunal/ui/components/rename-field.slint b/crates/tunal/ui/components/rename-field.slint index a680f0a..19299b0 100644 --- a/crates/tunal/ui/components/rename-field.slint +++ b/crates/tunal/ui/components/rename-field.slint @@ -1,5 +1,5 @@ import { Theme } from "../theme.slint"; -import { Motion } from "../motion.slint"; +import { ScrollInput } from "scroll-input.slint"; // A name edited in place of its label: a framed text input that takes the focus when it // appears, with the first `select-end` bytes (the name without its extension) selected. @@ -25,7 +25,7 @@ export component RenameField inherits Rectangle { } } - min-height: input.preferred-height + 2 * Theme.space-1; + min-height: input.min-height + 2 * Theme.space-1; background: Theme.surface; border-radius: Theme.corner-xs; border-width: Theme.focus-ring-width; @@ -49,20 +49,13 @@ export component RenameField inherits Rectangle { reject } - input := TextInput { + input := ScrollInput { x: Theme.space-2; width: parent.width - 2 * Theme.space-2; height: parent.height; - vertical-alignment: center; text: root.text; - color: Theme.on-surface; - selection-background-color: Theme.primary-container; - selection-foreground-color: Theme.on-primary-container; - font-size: Theme.body-medium.size; - font-weight: Theme.body-medium.weight; - horizontal-alignment: root.alignment; - single-line: true; - accessible-label: "Name"; + alignment: root.alignment; + label: "Name"; accepted => { root.finish(true); } diff --git a/crates/tunal/ui/components/scroll-input.slint b/crates/tunal/ui/components/scroll-input.slint new file mode 100644 index 0000000..eeef63e --- /dev/null +++ b/crates/tunal/ui/components/scroll-input.slint @@ -0,0 +1,61 @@ +import { Theme } from "../theme.slint"; + +// One line of editable text that scrolls so the cursor stays in view. Draws no frame. +export component ScrollInput inherits Rectangle { + in-out property text <=> input.text; + in property enabled <=> input.enabled; + in property alignment <=> input.horizontal-alignment; + in property input-type <=> input.input-type; + in property ink: Theme.on-surface; + in property label; + in property placeholder; + out property has-focus: input.has-focus; + callback edited(text: string); + callback accepted(text: string); + + public function select-all() { + input.select-all(); + } + + public function set-selection-offsets(anchor: int, focus: int) { + input.set-selection-offsets(anchor, focus); + } + + // Room kept between the cursor and the edge it scrolls at. + property margin: min(Theme.space-4, self.width / 4); + // A clipped input of no width can't take the focus. + min-width: 1px; + min-height: input.preferred-height; + clip: true; + forward-focus: input; + + input := TextInput { + property shift; + x: min(0px, max(parent.width - self.width, self.shift)); + // The whole text, so a short one can still be centred and clicked anywhere. + width: max(parent.width, self.preferred-width + self.text-cursor-width); + height: parent.height; + single-line: true; + vertical-alignment: center; + color: root.ink; + selection-background-color: Theme.primary-container; + selection-foreground-color: Theme.on-primary-container; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + accessible-label: root.label; + accessible-placeholder-text: root.placeholder; + cursor-position-changed(at) => { + if at.x + self.x < root.margin { + self.shift = min(0px, root.margin - at.x); + } else if at.x + self.x > root.width - root.margin - self.text-cursor-width { + self.shift = root.width - root.margin - self.text-cursor-width - at.x; + } + } + edited => { + root.edited(self.text); + } + accepted => { + root.accepted(self.text); + } + } +} diff --git a/crates/tunal/ui/components/text-field.slint b/crates/tunal/ui/components/text-field.slint index 15bba91..54e12de 100644 --- a/crates/tunal/ui/components/text-field.slint +++ b/crates/tunal/ui/components/text-field.slint @@ -1,3 +1,4 @@ +import { ScrollInput } from "scroll-input.slint"; import { Theme } from "../theme.slint"; import { Motion } from "../motion.slint"; import { Icons } from "icon.slint"; @@ -110,20 +111,14 @@ export component TextField { overflow: elide; } - input := TextInput { + input := ScrollInput { width: 100%; text <=> root.text; - accessible-label: root.label; - accessible-placeholder-text: root.placeholder; + label: root.label; + placeholder: root.placeholder; enabled: root.enabled; - single-line: true; input-type: root.secret ? InputType.password : InputType.text; - color: root.enabled ? Theme.on-surface : root.disabled; - selection-background-color: Theme.primary-container; - selection-foreground-color: Theme.on-primary-container; - font-size: Theme.body-medium.size; - font-weight: Theme.body-medium.weight; - vertical-alignment: center; + ink: root.enabled ? Theme.on-surface : root.disabled; edited => { root.edited(self.text); } diff --git a/crates/tunal/ui/shell/breadcrumb.slint b/crates/tunal/ui/shell/breadcrumb.slint index 62e0151..214ba27 100644 --- a/crates/tunal/ui/shell/breadcrumb.slint +++ b/crates/tunal/ui/shell/breadcrumb.slint @@ -2,6 +2,7 @@ import { Theme } from "../theme.slint"; import { Motion } from "../motion.slint"; import { Icon, Icons } from "../components/icon.slint"; import { StateLayer } from "../components/state-layer.slint"; +import { ScrollInput } from "../components/scroll-input.slint"; import { DropTarget, DropZone } from "../components/drop-menu.slint"; // One segment of the path: the root (glyph and name) or a folder. @@ -227,15 +228,10 @@ export component Breadcrumb inherits Rectangle { reject } - input := TextInput { - single-line: true; - color: Theme.on-surface; - selection-background-color: Theme.primary-container; - selection-foreground-color: Theme.on-primary-container; - font-size: Theme.body-medium.size; - font-weight: Theme.body-medium.weight; - vertical-alignment: center; - accessible-label: "Location"; + input := ScrollInput { + width: 100%; + height: 100%; + label: "Location"; edited => { root.highlight = -1; root.edited(self.text); diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 6184136..ff9a896 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -313,5 +313,10 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, - Verified: clippy on tunal + tunal-devices, release build; the user's USB stick opened, unmounted and mounted again under Xvfb. - Not done: Safely remove not run (needs a replug); inner disks, cards and discs not tried; locked (LUKS) drives are not listed; no test run. +## Text fields scroll (user bug) +- Done: `components/scroll-input.slint` (one-line input that keeps the cursor in view) in the rename field, every text field and the location bar; Slint's bare `TextInput` doesn't scroll. +- Verified: release build; rename of a long name in the grid and the location bar under Xvfb. +- Not done: no test run; password fields and arrow / Home / End keys not tried. + ## Later -