Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

66.1 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2026 Jareer Abdullah and Concat contributors

import { I18n } from "../i18n.slint";
import { Theme } from "../theme/theme.slint";
import { Fmt } from "../util.slint";
import { Glyph, Icon } from "../icons.slint";
import { Editor } from "../editor.slint";
import { Lanes } from "../timeline/lanes.slint";
import { ClipField, ClipKind, SelectedClipData } from "../timeline/model.slint";
import { Param, ParamFormat, SwitchRow } from "../inspector/controls.slint";
import { PreviewPane } from "../workspace/preview-pane.slint";
import { ContextMenu } from "../primitives/context-menu.slint";
import {
    CategoryPillBar, GroupPillBar, MediaCard, MediaItemData, PresetGrid, ShelfGrid, ShelfSearch,
} from "../workspace/media-pane.slint";
import {
    AdjustPanel, AudioPanel, EnhancePanel, FilterPanel, Library, PresetStack, ProcessorRows,
    SpeedPanel, VideoPanel,
} from "../inspector/clip-inspector.slint";
import { TextPanel } from "../inspector/text-panel.slint";
import { RoundButton, ToolItem, ToolStrip } from "controls.slint";
import { PhoneSheet } from "sheet.slint";
import { PhoneCanvas } from "canvas.slint";
import { Sounds, SoundList, VoiceList } from "../workspace/audio-page.slint";

// The editor as a phone shows it: one screen, held upright, driven by a
// finger. Shown in place of the title strip and the dock wherever the
// window is a phone's - see `App.phone` and `platform::phone` - and never
// beside them: the desk's layout is the desk's, and this one is not a
// squeezed copy of it but the shape every phone editor has arrived at,
// because a thumb and a portrait screen leave no other.
//
// Top to bottom:
//
//   - a bar with the way out, the project's name, Settings and Export;
//   - the monitor, which takes whatever height the rest leaves;
//   - the transport: where the playhead is, a frame back, Play, a frame
//     on, undo and redo;
//   - the lanes, with the playhead held at their middle and the cut
//     sliding under it - a drag scrubs and a throw glides on, two fingers
//     pinch the zoom, a tap on a clip selects it where it is, a tap on
//     empty lane lets go, a clip dragged moves (see `finger` in
//     lanes.slint, `centred` in the timeline pane on the Rust side, and
//     the glide beside it);
//   - the bar of tools. With nothing selected it is the library's pages
//     and the project's verbs; with a clip selected it is the clip's
//     verbs, with a way back at its head.
//
// Every tool that has more to say than a press opens a sheet over the
// lanes and the bar (sheet.slint) holding the same panel the desk shows
// for it - the inspector's page, the library's shelf - so the phone and
// the desk edit through one set of controls and one set of callbacks.
// Everything read and everything reported goes through the Editor global,
// the way the seats do it; there is no phone-only state on the Rust side
// beyond the two facts named above.

/// A grid of the bin's cards for a finger. A tap picks a card or lets it
/// go, and a picked card wears its place in the order - 1, 2, 3 - the way
/// every phone editor's picker numbers them, since that is the order Add
/// lays them down in. Five photos are five taps and an Add, not five trips
/// in and out of the sheet; there is nowhere to drag a card to.
component PhoneMediaGrid inherits Rectangle {
    in property <[MediaItemData]> items;

    callback picked(id: int);

    property <length> gap: 8px;
    property <length> min-card: 100px;
    property <int> cols: Math.max(1,
        Math.floor((root.width + root.gap) / (root.min-card + root.gap)));
    property <length> card-w: (root.width - (root.cols - 1) * root.gap) / root.cols;
    property <length> card-h: root.card-w * 9 / 16 + 4px + 14px;
    property <int> rows: Math.ceil(root.items.length / root.cols);

    height: root.rows > 0 ? root.rows * (root.card-h + root.gap) - root.gap : 0px;

    for entry[index] in root.items: MediaCard {
        x: Math.mod(index, root.cols) * (root.card-w + root.gap);
        y: Math.floor(index / root.cols) * (root.card-h + root.gap);
        width: root.card-w;
        height: root.card-h;
        item: entry;
        removable: false;

        // A second tap toggles back; a double tap is two taps, not a third
        // thing.
        clicked(additive) => { root.picked(entry.id); }
    }

    // The pick's mark, over the picture's corner. Draws only: the card under
    // it takes the tap. Empty for a card not picked, so it reads as
    // something to tap.
    for entry[index] in root.items: Rectangle {
        x: Math.mod(index, root.cols) * (root.card-w + root.gap) + root.card-w - self.width - 6px;
        y: Math.floor(index / root.cols) * (root.card-h + root.gap) + 6px;
        width: 24px;
        height: 24px;
        border-radius: 12px;
        background: entry.pick > 0 ? Theme.accent : #00000059;
        border-width: entry.pick > 0 ? 0px : 1.5px;
        border-color: #ffffffd9;

        if entry.pick > 0: Text {
            text: entry.pick;
            color: Theme.on-accent;
            font-size: Theme.fs-sm;
            font-weight: Theme.weight-title;
            horizontal-alignment: center;
            vertical-alignment: center;
        }
    }
}

/// A worded button the width of its sheet: Import, Add a title, Modify.
component SheetButton inherits Rectangle {
    in property <string> label;
    in property <Glyph> glyph;
    in property <bool> primary;
    in property <bool> enabled: true;

    callback clicked();

    height: 44px;
    border-radius: Theme.r;
    opacity: root.enabled ? 1.0 : 0.5;
    background: root.primary
        ? (touch.pressed ? Theme.accent-hover : Theme.accent)
        : (touch.pressed ? Theme.field-active : Theme.field);

    animate background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }

    HorizontalLayout {
        alignment: center;
        spacing: 8px;
        padding-left: 16px;
        padding-right: 16px;

        VerticalLayout {
            alignment: center;
            Icon {
                glyph: root.glyph;
                size: 16px;
                tint: root.primary ? Theme.on-accent : Theme.fg;
            }
        }

        Text {
            text: root.label;
            color: root.primary ? Theme.on-accent : Theme.fg;
            font-size: Theme.fs-lg;
            font-weight: Theme.weight-title;
            vertical-alignment: center;
        }
    }

    touch := TouchArea {
        enabled: root.enabled;
        clicked => { root.clicked(); }
    }
}

/// A line of quiet words in a sheet: what a page is for, or why it is
/// empty.
component SheetNote inherits Text {
    color: Theme.fg-dim;
    font-size: Theme.fs;
    wrap: word-wrap;
}

/// The phone's Mask: the shapes as a row of tiles to thumb along, the way
/// every phone editor lays them out, and under it the numbers a finger
/// cannot drag on the monitor - the softness, the turn, a rectangle's
/// corners - and the invert. Where and how big is dragged on the monitor
/// with the grips the stage draws; the sliders for those are the desk's.
component PhoneMaskPanel inherits VerticalLayout {
    in property <SelectedClipData> selected;

    callback set(field: ClipField, value: float);
    callback commit();

    property <int> mask: root.selected.mask;
    property <float> feather: root.selected.mask-feather;
    property <float> turn: root.selected.mask-rotation;
    property <float> roundness: root.selected.mask-roundness;

    function pick(index: int) {
        root.set(ClipField.mask-shape, index);
        root.commit();
    }

    spacing: 6px;

    ToolStrip {
        height: 74px;
        ToolItem {
            glyph: Glyph.close;
            label: I18n.t("common.none");
            current: root.mask < 0;
            clicked => { root.pick(-1); }
        }
        ToolItem {
            glyph: Glyph.mask-linear;
            label: I18n.t("mask.linear");
            current: root.mask == 0;
            clicked => { root.pick(0); }
        }
        ToolItem {
            glyph: Glyph.mask-mirror;
            label: I18n.t("mask.mirror");
            current: root.mask == 1;
            clicked => { root.pick(1); }
        }
        ToolItem {
            glyph: Glyph.mask-circle;
            label: I18n.t("mask.circle");
            current: root.mask == 2;
            clicked => { root.pick(2); }
        }
        ToolItem {
            glyph: Glyph.mask-rectangle;
            label: I18n.t("mask.rectangle");
            current: root.mask == 3;
            clicked => { root.pick(3); }
        }
        ToolItem {
            glyph: Glyph.mask-heart;
            label: I18n.t("mask.heart");
            current: root.mask == 4;
            clicked => { root.pick(4); }
        }
        ToolItem {
            glyph: Glyph.mask-star;
            label: I18n.t("mask.star");
            current: root.mask == 5;
            clicked => { root.pick(5); }
        }
    }

    if root.mask < 0: SheetNote {
        text: I18n.t("mask.phoneHint");
    }

    if root.mask >= 0: SheetNote {
        text: I18n.t("mask.phoneDrag");
    }

    if root.mask >= 0: SwitchRow {
        label: I18n.t("mask.invert");
        checked: root.selected.mask-invert;
        toggled(on) => { root.set(ClipField.mask-invert, on ? 1 : 0); root.commit(); }
    }

    if root.mask >= 0: Param {
        label: I18n.t("clipInspector.feather");
        keyable: true;
        field: ClipField.mask-feather;
        value <=> root.feather;
        minimum: 0;
        maximum: 1;
        step: 0.01;
        default-value: 0;
        fmt: ParamFormat.fraction;
        unit: "%";
        unit-scale: 100;
        changed(v) => { root.set(ClipField.mask-feather, v); root.commit(); }
    }

    if root.mask >= 0: Param {
        label: I18n.t("common.rotation");
        keyable: true;
        field: ClipField.mask-rotation;
        value <=> root.turn;
        minimum: -180;
        maximum: 180;
        step: 1;
        default-value: 0;
        fmt: ParamFormat.degrees;
        unit: "°";
        changed(v) => { root.set(ClipField.mask-rotation, v); root.commit(); }
    }

    if root.mask == 3: Param {
        label: I18n.t("mask.roundness");
        keyable: true;
        field: ClipField.mask-roundness;
        value <=> root.roundness;
        minimum: 0;
        maximum: 1;
        step: 0.01;
        default-value: 0;
        fmt: ParamFormat.fraction;
        unit: "%";
        unit-scale: 100;
        changed(v) => { root.set(ClipField.mask-roundness, v); root.commit(); }
    }
}

/// One of the project's facts: the label, then the value against the
/// trailing edge.
component Fact inherits HorizontalLayout {
    in property <string> label;
    in property <string> value;

    spacing: 12px;
    min-height: 30px;

    Text {
        text: root.label;
        color: Theme.fg-muted;
        font-size: Theme.fs;
        vertical-alignment: center;
    }

    Text {
        horizontal-stretch: 1;
        text: root.value;
        color: Theme.fg;
        font-family: Theme.font-technical;
        font-size: Theme.fs;
        horizontal-alignment: right;
        vertical-alignment: center;
        wrap: word-wrap;
    }
}

/// A round chip over the lanes: the zoom, for a thumb that has no second
/// finger free to pinch with.
component LaneChip inherits Rectangle {
    in property <Glyph> glyph;
    in property <string> label;

    callback clicked();

    width: 34px;
    height: 34px;
    border-radius: 17px;
    background: touch.pressed ? Theme.field-active : Theme.raised;
    border-width: 1px;
    border-color: Theme.line-strong;

    Icon {
        x: (parent.width - self.width) / 2;
        y: (parent.height - self.height) / 2;
        glyph: root.glyph;
        size: 14px;
        tint: Theme.fg;
    }

    touch := TouchArea {
        clicked => { root.clicked(); }
    }
}

/// Whether a sheet is up in the phone editor, and a way to ask it down:
/// Android's Back, which the window hears, closes it before it leaves the
/// project - with Effects open, Back saved and went back to the projects.
export global PhoneSheets {
    in-out property <bool> open;
    in-out property <int> close-asked;
}

export component PhoneEditor inherits Rectangle {
    in property <string> project-name;
    /// "saved", "saving…": the little truth under the name.
    in property <string> status;

    callback export-clicked();
    callback open-settings();
    /// Back to the launch screen; the window saves on the way.
    callback close-project();

    /// Which sheet is up, by name, or empty for none. The names are the
    /// library's pages - "media", "text", "effects", "filters",
    /// "adjustments", "transitions" - the project's own, and a "clip-" page
    /// of the inspector for the selected clip.
    property <string> sheet;
    // Back closes the sheet on top before it leaves the editor; the window
    // hears the key, so the sheet's state is told it through PhoneSheets.
    changed sheet => { PhoneSheets.open = root.sheet != ""; }
    property <int> close-asked: PhoneSheets.close-asked;
    changed close-asked => { root.hide(); }
    /// The Audio sheet's shelf: 0 my sounds, 1 voices, 2 styles.
    property <int> audio-shelf;
    /// The Media sheet was opened from the lanes' plus: Add goes after the
    /// main lane's last clip rather than at the playhead.
    property <bool> media-at-end;
    /// The sheet up is one of the clip's, and goes with the clip.
    property <bool> sheet-needs-clip;

    property <bool> has-clip: Editor.selected-clip.present;
    property <ClipKind> kind: Editor.selected-clip.kind;
    property <bool> is-video: !Editor.selected-clip.batch-volume && root.kind == ClipKind.video;
    property <bool> is-audio: Editor.selected-clip.batch-volume || root.kind == ClipKind.audio;
    property <bool> is-image: root.kind == ClipKind.image;
    property <bool> is-text: root.kind == ClipKind.text;
    property <bool> is-layer: root.kind == ClipKind.filter;
    /// A shape has a placement and nothing else a picture has: no colour
    /// to adjust, no chain, no transition, no frame to freeze.
    property <bool> is-shape: root.kind == ClipKind.shape;
    /// A picture: what has a placement, a colour and a chain of effects.
    property <bool> is-picture: root.is-video || root.is-image;

    // A clip's sheet closes with the clip - deleted, or let go of by a tap
    // on the floor - rather than staying up over a selection it no longer
    // describes.
    changed has-clip => {
        if (!root.has-clip && root.sheet-needs-clip) {
            root.hide();
        }
    }

    function show(name: string, needs-clip: bool) {
        root.sheet = name;
        root.sheet-needs-clip = needs-clip;
    }
    function hide() {
        root.sheet = "";
        root.sheet-needs-clip = false;
    }
    /// The bin, with nothing picked yet.
    function show-media(at-end: bool) {
        Editor.media-clear-picks();
        root.media-at-end = at-end;
        root.show("media", false);
    }

    pure function sheet-title(name: string) -> string {
        return name == "media" ? I18n.t("common.media")
            : name == "audio" ? I18n.t("common.audio")
            : name == "text" || name == "clip-text" ? I18n.t("common.text")
            : name == "effects" || name == "clip-effects" ? I18n.t("common.effects")
            : name == "filters" ? I18n.t("mediaPane.filters")
            : name == "adjustments" ? I18n.t("mediaPane.adjustments")
            : name == "transitions" ? I18n.t("mediaPane.transitions")
            : name == "project" ? I18n.t("phone.project")
            : name == "canvas" || name == "clip-canvas" ? I18n.t("phone.canvas")
            : name == "clip-video" ? I18n.t("phone.edit")
            : name == "clip-speed" ? I18n.t("common.speed")
            : name == "clip-audio" ? I18n.t("common.audio")
            : name == "clip-audio-effects" ? I18n.t("configPane.audioEffects")
            : name == "clip-adjust" ? I18n.t("common.adjust")
            : name == "clip-enhance" ? I18n.t("common.enhance")
            : name == "clip-layer" ? I18n.t("configPane.filter")
            : name == "clip-mask" ? I18n.t("mask.title")
            : "";
    }

    background: Theme.page;

    // Placed rather than laid out. The lanes take a share of the screen's
    // height, and a layout that read the height of the thing it is sizing
    // is a binding loop - the launch screen has the same note. Five rows,
    // each at a height of its own: the bar and the lanes are measured up
    // from the foot, the top bar and the transport down from the head, and
    // the monitor is what is left between.
    property <length> top-h: 48px;
    property <length> transport-h: 60px;
    /// A third of the screen, and never less than a ruler and two lanes.
    property <length> lanes-h: Math.max(170px, root.height * 0.3);
    property <length> bar-h: 74px;
    property <length> lanes-y: root.height - root.bar-h - root.lanes-h;
    property <length> transport-y: root.lanes-y - root.transport-h;
    /// How tall the sheet is when one is up. The bin's is lower: it is a
    /// grid to pick from, and the picture is what the picks are judged in.
    property <length> sheet-h: root.sheet == "media" ? root.height * 0.52 : root.height * 0.6;
    /// The foot of the monitor: the transport's head, or the sheet's while
    /// one is up - the monitor shrinks to the room left above the sheet
    /// rather than going under it, so the whole picture stays in view
    /// while a sheet works on it.
    property <length> monitor-foot: root.sheet != ""
        ? Math.min(root.transport-y, root.height - root.sheet-h)
        : root.transport-y;
    /// The Add bar under the bin while something is picked.
    property <length> add-bar-h: 68px;

    // ── the top bar ──────────────────────────────────────────────────
    Rectangle {
        x: 0;
        y: 0;
        width: root.width;
        height: root.top-h;

        HorizontalLayout {
            padding-left: 4px;
            padding-right: 8px;
            spacing: 2px;

            VerticalLayout {
                alignment: center;
                RoundButton {
                    glyph: Glyph.close;
                    label: I18n.t("studio.closeProject");
                    clicked => { root.close-project(); }
                }
            }

            VerticalLayout {
                horizontal-stretch: 1;
                alignment: center;
                spacing: 1px;

                Text {
                    text: root.project-name;
                    color: Theme.fg;
                    font-size: Theme.fs-lg;
                    font-weight: Theme.weight-title;
                    horizontal-alignment: center;
                    overflow: elide;
                }
                Text {
                    text: root.status;
                    color: Theme.fg-dim;
                    font-size: Theme.fs-xs;
                    horizontal-alignment: center;
                }
            }

            VerticalLayout {
                alignment: center;
                RoundButton {
                    glyph: Glyph.settings;
                    label: I18n.t("common.settings");
                    clicked => { root.open-settings(); }
                }
            }

            // The one filled control on the bar: what the edit is for.
            VerticalLayout {
                alignment: center;
                padding-left: 4px;

                Rectangle {
                    width: export-label.preferred-width + export-icon.width + 32px;
                    height: 36px;
                    border-radius: Theme.r;
                    background: export-touch.pressed ? Theme.accent-hover : Theme.accent;

                    animate background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }

                    HorizontalLayout {
                        alignment: center;
                        spacing: 6px;
                        VerticalLayout {
                            alignment: center;
                            export-icon := Icon {
                                glyph: Glyph.export;
                                size: 14px;
                                tint: Theme.on-accent;
                            }
                        }
                        export-label := Text {
                            text: I18n.t("common.export");
                            color: Theme.on-accent;
                            font-size: Theme.fs-lg;
                            font-weight: Theme.weight-title;
                            vertical-alignment: center;
                        }
                    }

                    export-touch := TouchArea {
                        clicked => { root.export-clicked(); }
                    }
                }
            }
        }
    }

    // ── the monitor ──────────────────────────────────────────────────
    //
    // The pane's stage alone, with 8px of the ground either side so it
    // reads as a card on the page like the lanes under it. The stage
    // keeps its gestures: a drag moves the selected picture, a press
    // on the well pans the view, a double tap fits it again.
    Rectangle {
        x: 0;
        y: root.top-h;
        width: root.width;
        height: Math.max(0px, root.monitor-foot - root.top-h);

        monitor := PreviewPane {
            x: 8px;
            y: 0;
            width: parent.width - 16px;
            height: parent.height;
            bare: true;

            output-width: Editor.output-width;
            output-height: Editor.output-height;
            frame-rate: Editor.frame-rate;
            ratio-index: Editor.ratio-index;
            quality-index: Editor.quality-index;
            playhead: Editor.playhead;
            duration: Editor.preview-duration;
            playhead-free: Editor.playhead-free;
            playing: Editor.playing;
            has-picture: Editor.has-picture;
            clip-name: Editor.preview-clip-name;
            frame: Editor.preview-frame;
            see-through: Editor.see-through;
            stage-items: Editor.stage-items;
            stage-guides: Editor.stage-guides;
            stroke-path: Editor.stroke-path;
            stroke-width: Editor.stroke-width;
            stroke-erase: Editor.stroke-erase;
            painting: Editor.painting && Editor.selected-clip.cutout == 2;

            play-toggled => { Editor.play-toggled(); }
            seek(seconds) => { Editor.seek(seconds); }
            step(frames) => { Editor.step-frames(frames); }
            ratio-changed(index) => { Editor.ratio-changed(index); }
            quality-changed(index) => { Editor.quality-changed(index); }
            stage-pressed(x, y, additive) => {
                Editor.blur();
                Editor.stage-pressed(x, y, additive);
            }
            stage-grip-pressed(id, grip, x, y) => {
                Editor.blur();
                Editor.stage-grip-pressed(id, grip, x, y);
            }
            stage-dragged(x, y, snap) => { Editor.stage-dragged(x, y, snap); }
            stage-released => { Editor.stage-released(); }
        }
    }

    // ── the transport ────────────────────────────────────────────────
    //
    // Where the playhead is on the leading edge, the view's way back
    // and the history's two steps on the trailing one, and Play in the
    // middle of the row with a frame back and a frame on either side of
    // it - placed against the whole row rather than laid out, so they
    // stay under the thumb whatever the timecode's width. Measured for a
    // 360px screen, the narrowest phone in common use: the middle three
    // and the trailing three meet with a few pixels to spare.
    //
    // The frame steps are for the cut a drag cannot land on: a finger
    // lifting off the glass nudges the lanes a little, and a frame is a
    // pixel or less at most zooms (#244). Held, they keep stepping.
    property <int> frames: Math.round(Math.max(0, Editor.playhead) * Editor.frame-rate);
    property <int> rate: Math.max(1, Math.round(Editor.frame-rate));

    Rectangle {
        x: 0;
        y: root.transport-y;
        width: root.width;
        height: root.transport-h;

        HorizontalLayout {
            padding-left: 16px;
            padding-right: 4px;
            spacing: 0px;

            // The playhead to the frame, since the buttons step by one,
            // over the length of the cut.
            VerticalLayout {
                horizontal-stretch: 1;
                alignment: center;
                spacing: 1px;

                Text {
                    text: Fmt.short-duration(Math.floor(root.frames / root.rate))
                        + ":" + Fmt.pad2(Math.mod(root.frames, root.rate));
                    color: Theme.fg;
                    font-family: Theme.font-technical;
                    font-size: Theme.fs-lg;
                }
                Text {
                    text: Fmt.short-duration(Editor.preview-duration);
                    color: Theme.fg-dim;
                    font-family: Theme.font-technical;
                    font-size: Theme.fs-xs;
                }
            }

            VerticalLayout {
                alignment: center;
                RoundButton {
                    glyph: Glyph.fit;
                    label: I18n.t("previewPane.fitFramePane");
                    size: 36px;
                    icon-size: 16px;
                    clicked => { monitor.fit-view(); }
                }
            }
            VerticalLayout {
                alignment: center;
                RoundButton {
                    glyph: Glyph.undo;
                    label: I18n.t("phone.undo");
                    enabled: Editor.can-undo;
                    size: 36px;
                    icon-size: 17px;
                    clicked => { Editor.undo(); }
                }
            }
            VerticalLayout {
                alignment: center;
                RoundButton {
                    glyph: Glyph.redo;
                    label: I18n.t("phone.redo");
                    enabled: Editor.can-redo;
                    size: 36px;
                    icon-size: 17px;
                    clicked => { Editor.redo(); }
                }
            }
        }

        RoundButton {
            x: play.x - self.width - 2px;
            y: (parent.height - self.height) / 2;
            size: 36px;
            icon-size: 16px;
            repeats: true;
            enabled: root.frames > 0;
            glyph: Glyph.step-back;
            label: I18n.t("previewPane.previousFrame");
            clicked => { Editor.step-frames(-1); }
        }

        // The same size as its neighbours, and ten pixels of air above and
        // below: the fill is what makes it the one to reach for, not bulk.
        play := RoundButton {
            x: (parent.width - self.width) / 2;
            y: (parent.height - self.height) / 2;
            size: 40px;
            icon-size: 18px;
            accent: true;
            glyph: Editor.playing ? Glyph.pause : Glyph.play;
            label: Editor.playing ? I18n.t("previewPane.pause") : I18n.t("previewPane.play");
            clicked => { Editor.play-toggled(); }
        }

        RoundButton {
            x: play.x + play.width + 2px;
            y: (parent.height - self.height) / 2;
            size: 36px;
            icon-size: 16px;
            repeats: true;
            glyph: Glyph.step-forward;
            label: I18n.t("previewPane.nextFrame");
            clicked => { Editor.step-frames(1); }
        }
    }

    // ── the lanes ────────────────────────────────────────────────────
    //
    // No lane headers: a lane is untyped and its switches are the desk's
    // business; the clips are the whole of what a thumb needs here.
    stack := Rectangle {
        x: 0;
        y: root.lanes-y;
        width: root.width;
        height: root.lanes-h;

        // The stack scrolls here rather than in Rust, as it does in the
        // timeline pane and for the same reason: it is a property of
        // looking at the lanes, not of the edit. Measured up from the
        // foot, where the main lane is: CapCut's main track is the row
        // always in view, with the overlays stacked above it, and a stack
        // read from its head left the main lane - the video, and every
        // picture added to it - below the card once there were four lanes.
        // Clamped on read, so a stack that gets shorter cannot leave the
        // view parked past its end.
        property <length> lift;
        property <length> stack-h: Editor.tracks.length > 0
            ? Editor.tracks[Editor.tracks.length - 1].top
                + Editor.tracks[Editor.tracks.length - 1].height
            : 0px;
        property <length> overflow: Math.max(0px,
            self.stack-h - Math.max(0px, lanes.height - lanes.ruler-height));
        property <length> at: Math.max(0px, self.overflow - Math.min(self.overflow, self.lift));

        Rectangle {
            x: 8px;
            y: 0;
            width: parent.width - 16px;
            height: parent.height;
            background: Theme.panel;
            border-radius: Theme.r-lg;
            clip: true;

            lanes := Lanes {
                x: 0;
                y: 0;
                width: parent.width;
                height: parent.height;

                finger: true;
                edge-grab: 14px;
                ruler-height: 24px;
                track-scroll: stack.at;

                tracks: Editor.tracks;
                clips: Editor.clips;
                key-marks: Editor.key-marks;
                tool: Editor.tool;
                playhead: Editor.playhead;
                frame-rate: Editor.frame-rate;
                scroll-left: Editor.scroll-left;
                seconds-per-pixel: Editor.seconds-per-pixel;
                pan-mode: false;
                preview-axis: false;
                drop: Editor.drop;
                menu-items: Editor.menu-items;
                menu-height: Editor.menu-height;
                menu-token: Editor.menu-token;

                scrubbed(seconds) => {
                    Editor.blur();
                    Editor.scrubbed(seconds);
                }
                finger-held => { Editor.finger-held(); }
                finger-lifted => { Editor.finger-lifted(); }
                key-mark-moved(from, to) => { Editor.key-mark-moved(from, to); }
                key-mark-opened => { Editor.key-mark-opened(); }
                hovered(seconds) => { Editor.hovered(seconds); }
                hover-ended => { Editor.hover-ended(); }
                floor-pressed => { Editor.blur(); }
                clip-pressed(id, additive, edge) => {
                    Editor.blur();
                    Editor.clip-pressed(id, additive, edge);
                }
                clip-dragged(seconds, pixels) => { Editor.clip-dragged(seconds, pixels); }
                clip-released => { Editor.clip-released(); }
                clip-context(id) => { Editor.clip-context(id); }
                menu-selected(id) => { Editor.menu-selected(id); }
                band-selected(a, b, c, d, additive) => {
                    Editor.band-selected(a, b, c, d, additive);
                }
                scrolled(seconds) => { Editor.scrolled(seconds); }
                track-scrolled(pixels) => {
                    stack.lift = Math.max(0px,
                        Math.min(stack.overflow, stack.overflow - stack.at - pixels));
                }
                zoomed(factor, anchor) => { Editor.zoom(factor, anchor); }
                drag-hovered(payload, seconds, row) => {
                    Editor.drag-hovered(payload, seconds, row);
                }
                dropped(payload, seconds, row) => { Editor.dropped(payload, seconds, row); }
                // How wide the lanes are decides which clips Rust sends,
                // and where their middle is.
                changed width => { Editor.lanes-resized(self.width / 1px); }
                init => { Editor.lanes-resized(self.width / 1px); }
            }

            // An empty cut says where to start. Takes no presses, so the
            // lanes under it still do.
            if Editor.clips.length == 0: Text {
                x: 16px;
                y: lanes.ruler-height + 14px;
                width: parent.width - 32px;
                text: I18n.t("phone.emptyLanes");
                color: Theme.fg-dim;
                font-size: Theme.fs;
                horizontal-alignment: center;
                wrap: word-wrap;
            }

            // The way in from the lanes: CapCut's plus at the end of the
            // main track. The bin, and Add lays the picks after the main
            // lane's last clip, wherever the playhead is.
            add-media := Rectangle {
                x: parent.width - self.width - 8px;
                y: lanes.ruler-height
                    + Math.max(4px, (parent.height - lanes.ruler-height - 50px - self.height) / 2);
                width: 44px;
                height: 44px;
                border-radius: Theme.r;
                background: add-touch.pressed ? Theme.accent-hover : Theme.accent;
                drop-shadow-blur: 8px;
                drop-shadow-color: #00000066;

                Icon {
                    x: (parent.width - self.width) / 2;
                    y: (parent.height - self.height) / 2;
                    glyph: Glyph.plus;
                    size: 20px;
                    weight: 2.4;
                    tint: Theme.on-accent;
                }

                add-touch := TouchArea {
                    clicked => { root.show-media(true); }
                }
            }

            // The zoom, about the playhead - which is the middle, so the
            // cut grows and shrinks around what is under it.
            HorizontalLayout {
                x: parent.width - self.preferred-width - 8px;
                y: parent.height - 34px - 8px;
                width: self.preferred-width;
                height: 34px;
                spacing: 6px;

                LaneChip {
                    glyph: Glyph.minus;
                    label: I18n.t("common.zoomOut");
                    clicked => { Editor.zoom(1.4, Editor.playhead); }
                }
                LaneChip {
                    glyph: Glyph.plus;
                    label: I18n.t("common.zoomIn");
                    clicked => { Editor.zoom(1 / 1.4, Editor.playhead); }
                }
            }
        }
    }

    // ── the bar ──────────────────────────────────────────────────────
    Rectangle {
        x: 0;
        y: root.height - root.bar-h;
        width: root.width;
        height: root.bar-h;

        Rectangle {
            x: 0;
            y: 0;
            width: parent.width;
            height: 1px;
            background: Theme.line;
        }

        // Nothing selected: what can be brought into the cut, and the
        // project's own verbs.
        if !root.has-clip: ToolStrip {
            x: 0;
            y: 1px;
            width: parent.width;
            height: parent.height - 1px;

            ToolItem {
                glyph: Glyph.film;
                label: I18n.t("common.media");
                current: root.sheet == "media";
                clicked => { root.show-media(false); }
            }
            // Beside Media, as CapCut keeps it: the user's own sounds.
            ToolItem {
                glyph: Glyph.music;
                label: I18n.t("common.audio");
                current: root.sheet == "audio";
                clicked => { root.show("audio", false); }
            }
            ToolItem {
                glyph: Glyph.text-mark;
                label: I18n.t("common.text");
                current: root.sheet == "text";
                clicked => { root.show("text", false); }
            }
            ToolItem {
                glyph: Glyph.sparkle;
                label: I18n.t("common.effects");
                current: root.sheet == "effects";
                clicked => { root.show("effects", false); }
            }
            ToolItem {
                glyph: Glyph.filter;
                label: I18n.t("mediaPane.filters");
                current: root.sheet == "filters";
                clicked => { root.show("filters", false); }
            }
            // CapCut's Adjust, beside Filters: a layer that grades the
            // whole picture beneath it, and the user's LUTs.
            ToolItem {
                glyph: Glyph.sun;
                label: I18n.t("mediaPane.adjustments");
                current: root.sheet == "adjustments";
                clicked => { root.show("adjustments", false); }
            }
            ToolItem {
                glyph: Glyph.transition;
                label: I18n.t("mediaPane.transitions");
                current: root.sheet == "transitions";
                clicked => { root.show("transitions", false); }
            }
            ToolItem {
                glyph: Glyph.waveform;
                label: I18n.t("phone.captions");
                clicked => { Editor.captions(); }
            }
            ToolItem {
                glyph: Glyph.volume;
                label: I18n.t("phone.speak");
                clicked => { Editor.speak(); }
            }
            // The voiceover panel, which stands at the foot of the screen
            // over this bar; the same press puts it away, or stops a take.
            ToolItem {
                glyph: Glyph.mic;
                label: I18n.t("phone.voiceover");
                current: Editor.recording;
                clicked => {
                    root.hide();
                    Editor.record-voiceover();
                }
            }
            // What fills a tall frame beside a wide shot, for the whole
            // timeline: CapCut's Canvas, where a phone editor keeps it.
            ToolItem {
                glyph: Glyph.frame;
                label: I18n.t("phone.canvas");
                current: root.sheet == "canvas";
                clicked => { root.show("canvas", false); }
            }
            ToolItem {
                glyph: Glyph.info;
                label: I18n.t("phone.project");
                current: root.sheet == "project";
                clicked => { root.show("project", false); }
            }
        }

        // A clip selected: its verbs, in the order they are reached for,
        // with the way back at the head. Which appear depends on what
        // the clip is - a still has no speed, a sound no picture, a
        // title only its words and its effects - the same rule the
        // inspector's tabs follow.
        if root.has-clip: ToolStrip {
            x: 0;
            y: 1px;
            width: parent.width;
            height: parent.height - 1px;

            ToolItem {
                glyph: Glyph.chevron-left;
                label: I18n.t("phone.back");
                clicked => {
                    root.hide();
                    Editor.shortcut("deselect");
                }
            }
            ToolItem {
                glyph: Glyph.split;
                label: I18n.t("phone.split");
                clicked => { Editor.shortcut("split-selected"); }
            }
            ToolItem {
                glyph: Glyph.trash;
                label: I18n.t("common.delete");
                clicked => { Editor.delete-selected(); }
            }
            if root.is-picture || root.is-shape: ToolItem {
                glyph: Glyph.fit;
                label: I18n.t("phone.edit");
                current: root.sheet == "clip-video";
                clicked => { root.show("clip-video", true); }
            }
            // The clip's own Canvas: Fit and Fill, and its background.
            if root.is-picture: ToolItem {
                glyph: Glyph.frame;
                label: I18n.t("phone.canvas");
                current: root.sheet == "clip-canvas";
                clicked => { root.show("clip-canvas", true); }
            }
            if root.is-text: ToolItem {
                glyph: Glyph.text-mark;
                label: I18n.t("common.text");
                current: root.sheet == "clip-text";
                clicked => { root.show("clip-text", true); }
            }
            if root.is-layer: ToolItem {
                glyph: Glyph.filter;
                label: I18n.t("configPane.filter");
                current: root.sheet == "clip-layer";
                clicked => { root.show("clip-layer", true); }
            }
            // An adjustment layer is graded as a clip is: the same colour
            // sheet, and its chain, for everything beneath it.
            if root.is-layer: ToolItem {
                glyph: Glyph.sun;
                label: I18n.t("common.adjust");
                current: root.sheet == "clip-adjust";
                clicked => { root.show("clip-adjust", true); }
            }
            if root.is-layer: ToolItem {
                glyph: Glyph.sparkle;
                label: I18n.t("common.effects");
                current: root.sheet == "clip-effects";
                clicked => { root.show("clip-effects", true); }
            }
            if (root.is-video || root.is-audio) && !Editor.selected-clip.batch-volume: ToolItem {
                glyph: Glyph.clock;
                label: I18n.t("common.speed");
                current: root.sheet == "clip-speed";
                clicked => { root.show("clip-speed", true); }
            }
            if root.is-video || root.is-audio: ToolItem {
                glyph: Glyph.volume;
                label: I18n.t("common.audio");
                current: root.sheet == "clip-audio";
                clicked => { root.show("clip-audio", true); }
            }
            // The desk's Audio › Audio effects: the sound's chain and its
            // library on a sheet of their own, not under the level.
            if (root.is-video || root.is-audio) && !Editor.selected-clip.batch-volume: ToolItem {
                glyph: Glyph.waveform;
                label: I18n.t("configPane.audioEffects");
                current: root.sheet == "clip-audio-effects";
                clicked => { root.show("clip-audio-effects", true); }
            }
            // CapCut's Mask, on a sheet of its own.
            if root.is-picture: ToolItem {
                glyph: Glyph.mask-circle;
                label: I18n.t("mask.title");
                current: root.sheet == "clip-mask";
                clicked => { root.show("clip-mask", true); }
            }
            if root.is-picture: ToolItem {
                glyph: Glyph.sun;
                label: I18n.t("common.adjust");
                current: root.sheet == "clip-adjust";
                clicked => { root.show("clip-adjust", true); }
            }
            // The desk's Video > Enhance, on a sheet of its own: the same
            // panel, settings, preview and all.
            if root.is-picture: ToolItem {
                glyph: Glyph.maximize;
                label: I18n.t("common.enhance");
                current: root.sheet == "clip-enhance";
                clicked => { root.show("clip-enhance", true); }
            }
            if root.is-picture || root.is-text: ToolItem {
                glyph: Glyph.sparkle;
                label: I18n.t("common.effects");
                current: root.sheet == "clip-effects";
                clicked => { root.show("clip-effects", true); }
            }
            if root.is-picture: ToolItem {
                glyph: Glyph.transition;
                label: I18n.t("mediaPane.transitions");
                current: root.sheet == "transitions";
                clicked => { root.show("transitions", true); }
            }
            ToolItem {
                glyph: Glyph.copy;
                label: I18n.t("phone.duplicate");
                clicked => { Editor.shortcut("duplicate"); }
            }
            if root.is-picture: ToolItem {
                glyph: Glyph.frame;
                label: I18n.t("timelinePane.freeze");
                enabled: Editor.freezable;
                clicked => { Editor.shortcut("freeze"); }
            }
            if root.is-video || root.is-audio: ToolItem {
                glyph: Glyph.reverse;
                label: I18n.t("common.reverse");
                enabled: Editor.reversible;
                clicked => { Editor.shortcut("reverse"); }
            }
            if root.is-picture || root.is-shape: ToolItem {
                glyph: Glyph.flip-h;
                label: I18n.t("timelinePane.mirror");
                enabled: Editor.picture-selected;
                clicked => { Editor.shortcut("mirror"); }
            }
            if root.is-picture || root.is-shape: ToolItem {
                glyph: Glyph.rotate;
                label: I18n.t("timelinePane.rotate");
                enabled: Editor.picture-selected;
                clicked => { Editor.shortcut("rotate"); }
            }
            if Editor.sound-selected: ToolItem {
                glyph: Glyph.waveform;
                label: I18n.t("phone.captions");
                clicked => { Editor.captions(); }
            }
            if Editor.title-selected: ToolItem {
                glyph: Glyph.volume;
                label: I18n.t("phone.speak");
                clicked => { Editor.speak(); }
            }
            // The rest of the clip's menu - copy, paste, its sound taken
            // off its picture - as the menu itself, hung over the bar.
            ToolItem {
                glyph: Glyph.chevron-up;
                label: I18n.t("phone.more");
                clicked => {
                    more-menu.request-x = self.absolute-position.x - root.absolute-position.x;
                    more-menu.request-y = root.height - 74px;
                    Editor.clip-context(Editor.selected-clip.id);
                }
            }
        }
    }

    // ── the sheet ────────────────────────────────────────────────────────
    //
    // One sheet, one body, chosen by name. Each page is the desk's own
    // panel bound to the Editor global the way the seats bind it; the
    // library's pages close themselves once something is placed, so what
    // was placed is seen, and the inspector's stay up to be worked in.
    sheet := PhoneSheet {
        x: 0;
        y: 0;
        width: root.width;
        height: root.height;
        sheet-height: root.sheet-h;
        open: root.sheet != "";
        title: root.sheet-title(root.sheet);
        closed => { root.hide(); }

        // ── the bin ──
        if root.sheet == "media": VerticalLayout {
            padding: 12px;
            spacing: 12px;

            SheetButton {
                glyph: Glyph.import;
                primary: true;
                enabled: !Editor.importing;
                label: Editor.importing ? I18n.t("mediaPane.importing") : I18n.t("phone.importMedia");
                clicked => { Editor.import-media(); }
            }
            SheetNote {
                text: Editor.media.length == 0 ? I18n.t("phone.noMediaYet")
                    : root.media-at-end ? I18n.t("phone.pickToAddAtEnd")
                    : I18n.t("phone.pickToAdd");
            }
            PhoneMediaGrid {
                items: Editor.media;
                picked(id) => { Editor.media-select(id, true); }
            }
            // Room under the last row for the Add bar over it.
            if Editor.media-selected-count > 0: Rectangle {
                height: root.add-bar-h - 12px;
            }
        }

        // ── the user's own sounds: brought in from the phone's files,
        // played with a tap, laid at the playhead with the plus ──
        if root.sheet == "audio": VerticalLayout {
            padding: 12px;
            spacing: 12px;

            // Three shelves, as chips across the top: the user's sounds,
            // the voices, the styles.
            HorizontalLayout {
                spacing: 6px;
                alignment: start;
                for shelf[index] in [I18n.t("sounds.mine"), I18n.t("voices.voices"), I18n.t("voices.styles")]: Rectangle {
                    height: 32px;
                    width: chip-text.preferred-width + 28px;
                    border-radius: 16px;
                    background: root.audio-shelf == index ? Theme.accent : Theme.field;
                    chip-text := Text {
                        text: shelf;
                        color: root.audio-shelf == index ? Theme.on-accent : Theme.fg-muted;
                        font-size: Theme.fs;
                        vertical-alignment: center;
                        horizontal-alignment: center;
                    }
                    TouchArea { clicked => { root.audio-shelf = index; } }
                }
            }

            if root.audio-shelf > 0: VoiceList {
                styles: root.audio-shelf == 2;
                touch-sized: true;
                opened => { root.hide(); }

                // A recording from the phone's files kept as a voice. The
                // sheet stays up under the New voice sheet, so the voice
                // is there to see once it is saved.
                if root.audio-shelf == 1: VerticalLayout {
                    padding-top: 6px;
                    padding-bottom: 8px;
                    SheetButton {
                        glyph: Glyph.import;
                        primary: true;
                        label: I18n.t("voices.importVoice");
                        clicked => { Sounds.voice-import(); }
                    }
                }
            }

            if root.audio-shelf == 0: SheetButton {
                glyph: Glyph.import;
                primary: true;
                enabled: !Sounds.importing;
                label: Sounds.importing ? I18n.t("mediaPane.importing") : I18n.t("sounds.importSounds");
                clicked => { Sounds.import(); }
            }
            if root.audio-shelf == 0: SheetNote {
                text: Sounds.mine.length == 0
                    ? I18n.t("sounds.noSoundsYet") : I18n.t("sounds.mineHintPhone");
            }
            if root.audio-shelf == 0: SoundList {
                items: Sounds.mine;
                touch-sized: true;
                added => { root.hide(); }
            }
        }

        // ── titles ──
        if root.sheet == "text": VerticalLayout {
            padding: 12px;
            spacing: 12px;

            SheetButton {
                glyph: Glyph.plus;
                primary: true;
                label: I18n.t("phone.addATitle");
                clicked => {
                    Editor.library-add-text("default");
                    root.hide();
                }
            }
            SheetNote { text: I18n.t("phone.looks"); }
            PresetGrid {
                items: Editor.text-presets;
                applied(id) => {
                    Editor.library-add-text(id);
                    root.hide();
                }
            }
        }

        // ── effects, with nothing selected ──
        if root.sheet == "effects": VerticalLayout {
            padding: 12px;
            spacing: 8px;

            if !root.has-clip: SheetNote { text: I18n.t("phone.selectClipFirst"); }
            ShelfSearch {
                shelf: 1;
                placeholder: I18n.t1("common.searchKind", I18n.t("common.effect"));
            }
            CategoryPillBar {
                current: Library.view(1).category;
                picked(cat) => { Library.category-changed(1, cat); }
            }
            ShelfGrid {
                entries: Editor.catalogue-effects;
                glyph: Glyph.sparkle;
                auditions: false;
                applied(id, label) => { Editor.library-apply-effect(id); }
            }
        }

        // ── the selected clip's effects: its chain, then the shelf ──
        if root.sheet == "clip-effects": VerticalLayout {
            spacing: 0px;

            PresetStack {
                noun: I18n.t("common.effect");
                library-title: I18n.t("common.effects");
                library: false;
                empty-note: I18n.t("phone.noEffectYet");
                shelf: 1;
                group-labels: Editor.effect-groups;
                catalogue: Editor.catalogue-effects;
                applied: Editor.applied-visual;
                params: Editor.visual-params;
                wheel-groups: Editor.visual-wheels;
                curve-groups: Editor.visual-curves;
                colours: Editor.visual-colours;

                add(id) => { Editor.chain-add(false, id); }
                toggle(index) => { Editor.chain-toggle(false, index); }
                move-by(index, delta) => { Editor.chain-move-by(false, index, delta); }
                remove(index) => { Editor.chain-remove(false, index); }
                set-param(index, key, value) => {
                    Editor.chain-set-param(false, index, key, value);
                }
                set-colour(index, key, value) => {
                    Editor.chain-set-colour(index, key, value);
                }
                curve-point(index, key, point, x, y) => {
                    Editor.curve-point(index, key, point, x, y);
                }
                curve-remove(index, key, point) => {
                    Editor.curve-remove(index, key, point);
                }
                commit => { Editor.clip-commit(); }
            }

            Rectangle {
                height: 1px;
                background: Theme.line;
            }

            VerticalLayout {
                padding: 12px;
                spacing: 8px;

                ShelfSearch {
                    shelf: 1;
                    placeholder: I18n.t1("common.searchKind", I18n.t("common.effect"));
                }
                CategoryPillBar {
                    current: Library.view(1).category;
                    picked(cat) => { Library.category-changed(1, cat); }
                }
                ShelfGrid {
                    entries: Editor.catalogue-effects;
                    glyph: Glyph.sparkle;
                    auditions: false;
                    applied(id, label) => { Editor.library-apply-effect(id); }
                }
            }
        }

        // ── filters: a look laid over the cut at the playhead ──
        if root.sheet == "filters": VerticalLayout {
            padding: 12px;
            spacing: 8px;

            ShelfSearch {
                shelf: 0;
                placeholder: I18n.t1("common.searchKind", I18n.t("mediaPane.filter"));
            }
            GroupPillBar {
                shelf: 0;
                groups: Editor.filter-groups;
            }
            ShelfGrid {
                entries: Editor.catalogue-filters;
                auditions: false;
                applied(id, label) => {
                    Editor.library-apply-filter(id, label);
                    root.hide();
                }
            }
        }

        // ── adjustments: a layer that grades everything beneath it, and
        // the user's LUTs - imported from the phone's files, put down as
        // a layer at the playhead ──
        if root.sheet == "adjustments": VerticalLayout {
            padding: 12px;
            spacing: 12px;

            SheetButton {
                glyph: Glyph.plus;
                primary: true;
                label: I18n.t("mediaPane.addAdjustmentLayer");
                clicked => {
                    Editor.library-add-adjustment(I18n.t("mediaPane.adjustment"));
                    root.hide();
                }
            }
            SheetNote { text: I18n.t("mediaPane.adjustmentLayerHint"); }
            SheetNote { text: I18n.t("mediaPane.luts"); }
            SheetButton {
                glyph: Glyph.import;
                label: I18n.t("mediaPane.importALut");
                clicked => { Editor.library-import-lut(); }
            }
            if Editor.catalogue-luts.length == 0: SheetNote {
                text: I18n.t("mediaPane.noLutsYet");
            }
            ShelfGrid {
                entries: Editor.catalogue-luts;
                glyph: Glyph.sun;
                auditions: false;
                applied(id, label) => {
                    Editor.library-apply-lut(id, label);
                    root.hide();
                }
            }
        }

        // ── transitions: onto the cut into the selected clip ──
        if root.sheet == "transitions": VerticalLayout {
            padding: 12px;
            spacing: 8px;

            if !root.has-clip: SheetNote { text: I18n.t("phone.selectClipFirst"); }
            ShelfSearch {
                shelf: 3;
                placeholder: I18n.t1("common.searchKind", I18n.t("mediaPane.transition"));
            }
            GroupPillBar {
                shelf: 3;
                groups: Editor.transition-groups;
            }
            ShelfGrid {
                entries: Editor.catalogue-transitions;
                glyph: Glyph.transition;
                auditions: false;
                applied(id, label) => { Editor.library-apply-transition(id); }
            }
        }

        // ── the inspector's pages ──
        if root.sheet == "canvas": PhoneCanvas { own: false; }
        if root.sheet == "clip-canvas": PhoneCanvas { own: true; }

        if root.sheet == "clip-mask": PhoneMaskPanel {
            selected: Editor.selected-clip;
            set(field, value) => { Editor.clip-set(field, value); }
            commit => { Editor.clip-commit(); }
        }

        if root.sheet == "clip-video": VideoPanel {
            // Fit, Fill and the background have the Canvas sheet here, and
            // the mask its own tool and sheet.
            canvas: false;
            mask-section: false;
            selected: Editor.selected-clip;
            applied: Editor.applied-visual;
            params: Editor.visual-params;
            colours: Editor.visual-colours;
            brush-tool: Editor.brush-tool;
            brush-size: Editor.brush-size;
            painting: Editor.painting;
            set(field, value) => { Editor.clip-set(field, value); }
            commit => { Editor.clip-commit(); }
            chain-add(id) => { Editor.chain-add(false, id); }
            chain-remove(index) => { Editor.chain-remove(false, index); }
            chain-set-param(index, key, value) => {
                Editor.chain-set-param(false, index, key, value);
            }
            chain-set-colour(index, key, value) => {
                Editor.chain-set-colour(index, key, value);
            }
            cutout-mode(mode) => { Editor.cutout-mode(mode); }
            cutout-tool(index) => { Editor.cutout-tool(index); }
            cutout-size(size) => { Editor.cutout-size(size); }
            cutout-painting(on) => { Editor.cutout-painting(on); }
            cutout-subject(index) => { Editor.cutout-subject(index); }
            cutout-clear => { Editor.cutout-clear(); }
        }

        if root.sheet == "clip-speed": SpeedPanel {
            selected: Editor.selected-clip;
            set(field, value) => { Editor.clip-set(field, value); }
            commit => { Editor.clip-commit(); }
        }

        if root.sheet == "clip-audio": VerticalLayout {
            AudioPanel {
                selected: Editor.selected-clip;
                audio-tracks: Editor.audio-tracks;
                set(field, value) => { Editor.clip-set(field, value); }
                commit => { Editor.clip-commit(); }
            }
            if !Editor.selected-clip.batch-volume: ProcessorRows {
                applied: Editor.applied-audio;
                params: Editor.audio-params;
                add(id) => { Editor.chain-add(true, id); }
                remove(index) => { Editor.chain-remove(true, index); }
                set-param(index, key, value) => {
                    Editor.chain-set-param(true, index, key, value);
                }
                commit => { Editor.clip-commit(); }
            }
        }

        if root.sheet == "clip-audio-effects": VerticalLayout {
            if !Editor.selected-clip.batch-volume: PresetStack {
                noun: I18n.t("common.audioEffect");
                library-title: I18n.t("configPane.audioEffects");
                shelf: 2;
                hidden: ["concat.loudness", "concat.denoise", "concat.enhance-voice"];
                group-labels: Editor.audio-groups;
                catalogue: Editor.catalogue-audio;
                applied: Editor.applied-audio;
                params: Editor.audio-params;

                add(id) => { Editor.chain-add(true, id); }
                toggle(index) => { Editor.chain-toggle(true, index); }
                move-by(index, delta) => { Editor.chain-move-by(true, index, delta); }
                remove(index) => { Editor.chain-remove(true, index); }
                set-param(index, key, value) => {
                    Editor.chain-set-param(true, index, key, value);
                }
                commit => { Editor.clip-commit(); }
            }
        }

        if root.sheet == "clip-adjust": AdjustPanel {
            params: Editor.adjust-params;
            wheels: Editor.adjust-wheels;
            curves: Editor.adjust-curves;
            set(key, value) => { Editor.adjust-set(key, value); }
            curve-point(key, point, x, y) => { Editor.curve-point(-1, key, point, x, y); }
            curve-remove(key, point) => { Editor.curve-remove(-1, key, point); }
            commit => { Editor.clip-commit(); }
        }

        if root.sheet == "clip-enhance": EnhancePanel {
            selected: Editor.selected-clip;
            enhance-set(on) => { Editor.clip-enhance-set(on); }
            enhance-size(index) => { Editor.clip-enhance-size(index); }
            enhance-strength(strength) => { Editor.clip-enhance-strength(strength); }
            enhance-preview => { Editor.clip-enhance-preview(); }
            enhance-run => { Editor.clip-enhance-run(); }
        }

        if root.sheet == "clip-text": TextPanel {
            selected: Editor.selected-clip;
            families: Editor.font-families;
            set(field, value) => { Editor.clip-set(field, value); }
            set-text(field, value) => { Editor.clip-set-text(field, value); }
            set-words(text, caret) => { Editor.clip-set-words(text, caret); }
            select-words(anchor, cursor) => { Editor.clip-select-words(anchor, cursor); }
            reset-words => { Editor.clip-reset-words(); }
            set-colour(field, value) => { Editor.clip-set-colour(field, value); }
            commit => { Editor.clip-commit(); }
            import-font => { Editor.import-font(); }
            set-default => { Editor.text-style-default(); }
        }

        if root.sheet == "clip-layer": FilterPanel {
            selected: Editor.selected-clip;
            set(field, value) => { Editor.clip-set(field, value); }
            commit => { Editor.clip-commit(); }
        }

        // ── the project's facts, and the sheet that changes them ──
        if root.sheet == "project": VerticalLayout {
            padding: 16px;
            spacing: 0px;

            Fact { label: I18n.t("common.name"); value: Editor.project-name; }
            Fact { label: I18n.t("configPane.folder"); value: Editor.project-folder; }
            Fact { label: I18n.t("configPane.timeline"); value: Editor.timeline-name; }
            Fact { label: I18n.t("common.frame"); value: Editor.project-output; }
            Fact { label: I18n.t("common.rate"); value: Editor.project-rate; }
            Fact { label: I18n.t("common.duration"); value: Editor.project-duration; }
            Fact { label: I18n.t("common.media"); value: "\{Editor.count-media}"; }
            Fact { label: I18n.t("configPane.tracks"); value: "\{Editor.count-tracks}"; }
            Fact { label: I18n.t("configPane.clips"); value: "\{Editor.count-clips}"; }


            Rectangle { height: 16px; }

            SheetButton {
                glyph: Glyph.settings;
                label: I18n.t("configPane.modify");
                clicked => {
                    root.hide();
                    Editor.modify-project();
                }
            }
        }
    }

    // ── the Add bar ──────────────────────────────────────────────────
    //
    // Pinned to the foot of the bin while anything is picked, over the
    // grid rather than in its scroll, so it is under the thumb however far
    // down the picks are; it follows the sheet when the sheet is dragged.
    if root.sheet == "media" && Editor.media-selected-count > 0: Rectangle {
        x: 0;
        y: root.height - root.add-bar-h + sheet.drag;
        width: root.width;
        height: root.add-bar-h;
        background: Theme.panel;

        Rectangle {
            x: 0;
            y: 0;
            width: parent.width;
            height: 1px;
            background: Theme.line;
        }

        // Swallows the presses around the button, so they do not fall
        // through to the grid under the bar.
        TouchArea { }

        HorizontalLayout {
            padding-left: 12px;
            padding-right: 12px;
            padding-top: 12px;
            padding-bottom: 12px;

            SheetButton {
                horizontal-stretch: 1;
                glyph: Glyph.plus;
                primary: true;
                label: I18n.t1("phone.addPicked", Editor.media-selected-count);
                clicked => {
                    Editor.media-add-picked(root.media-at-end);
                    root.hide();
                }
            }
        }
    }

    // ── the clip's menu ──────────────────────────────────────────────────
    //
    // Over everything, so it can hang above the bar. Opened by the token
    // Rust bumps once it has filled the rows; the lanes' own copy of this
    // menu stays shut, since it opens only for a request it made itself.
    more-menu := ContextMenu {
        x: 0;
        y: 0;
        width: root.width;
        height: root.height;
        items: Editor.menu-items;
        menu-height: Editor.menu-height;
        token: Editor.menu-token;
        selected(id) => { Editor.menu-selected(id); }
    }
}