Tunal/crates/tunal/ui/shell/pane.slint
2026-11-18 20:48:34 -06:00

184 lines
7.2 KiB
Text

import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon } from "../components/icon.slint";
import { DetailRow, FolderState, NavKey, SortColumn } from "../views/details-view.slint";
import { GridRow } from "../views/grid-view.slint";
import { FolderView } from "../views/view-switch.slint";
import { DropTarget, DropZone } from "../components/drop-menu.slint";
// One pane of a tab, set from Rust (shell/pane.rs).
export struct PaneData {
rows: [DetailRow],
// The grid view's lines over the same rows.
lines: [GridRow],
folder: FolderState,
// Folder name and glyph, for the split-view header and the tab.
title: string,
glyph: string,
}
// A folder view with its header. In split view the header names the folder and marks the
// active pane: the one the toolbar, breadcrumb and shortcuts act on.
export component Pane inherits Rectangle {
in property <PaneData> data;
in property <bool> active;
in property <bool> split;
// Index in the tab, for drag and drop.
in property <int> index;
out property <bool> hovered: touch.has-hover;
// The pointer or keyboard went here: make this the active pane.
callback activated();
callback sort-by(SortColumn);
callback open-sort-menu(length, length);
callback filter-typed(string);
callback filter-edited(string);
callback toggle-hidden();
callback row-clicked(int, bool, bool);
callback row-activated(int);
callback select-all();
callback clear-selection();
callback navigate(NavKey, bool, int) -> int;
callback columns-changed(int);
callback motion-settled();
callback row-renamed(int, string);
callback rename-cancelled();
callback context-menu(int, length, length);
callback viewport-changed(length, length, length, length);
// The view keeps the focus away from a name being edited.
public function focus-view() {
if root.data.folder.edit-row < 0 {
details.focus-view();
}
}
property <length> header-height: root.split ? 32px : 0;
border-radius: root.split ? Theme.corner-lg : 0;
clip: true;
background: Theme.surface;
// Clicks the view leaves alone (empty space, the header) still activate the pane; the
// hover is for the mouse back and forward buttons, which go to the pane under the pointer.
// Dropping on the background (or on a file) goes into the pane's folder.
DropZone {
target: DropTarget.pane;
a: root.index;
radius: root.border-radius;
touch := TouchArea {
clicked => {
root.activated();
root.focus-view();
}
pointer-event(event) => {
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
root.activated();
root.context-menu(-1, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
}
}
VerticalLayout {
if root.split: Rectangle {
height: root.header-height;
background: root.active ? Theme.secondary-container : Theme.surface-container;
animate background { duration: Motion.time(Motion.short4); easing: Motion.standard; }
HorizontalLayout {
padding-left: Theme.space-3;
padding-right: Theme.space-3;
spacing: Theme.space-2;
VerticalLayout {
alignment: center;
Icon {
glyph: root.data.glyph;
size: 18px;
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
}
}
Text {
horizontal-stretch: 1;
text: root.data.title;
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
font-size: Theme.label-large.size;
font-weight: Theme.label-large.weight;
vertical-alignment: center;
overflow: elide;
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
}
}
}
details := FolderView {
pane: root.index;
rows: root.data.rows;
lines: root.data.lines;
state: root.data.folder;
columns-changed(n) => {
root.columns-changed(n);
}
motion-settled => {
root.motion-settled();
}
viewport-changed(top, height, row, cell) => {
root.viewport-changed(top, height, row, cell);
}
row-renamed(row, text) => {
root.row-renamed(row, text);
}
rename-cancelled => {
root.rename-cancelled();
}
context-menu(row, x, y) => {
root.activated();
root.context-menu(row, x, y);
}
sort-by(column) => {
root.activated();
root.sort-by(column);
}
open-sort-menu(x, y) => {
root.activated();
root.open-sort-menu(x, y);
}
filter-typed(text) => {
root.activated();
root.filter-typed(text);
}
filter-edited(text) => {
root.activated();
root.filter-edited(text);
}
toggle-hidden => {
root.activated();
root.toggle-hidden();
}
row-clicked(row, ctrl, shift) => {
root.activated();
root.row-clicked(row, ctrl, shift);
}
row-activated(row) => {
root.activated();
root.row-activated(row);
}
select-all => {
root.activated();
root.select-all();
}
clear-selection => {
root.activated();
root.clear-selection();
}
navigate(key, shift, page) => {
root.activated();
root.navigate(key, shift, page)
}
}
}
}
}
}