Needs S016's Bridge::elevation() and tunal-elevate to build. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
105 lines
4.2 KiB
Text
105 lines
4.2 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Shapes, ShapeKind } from "../shapes.slint";
|
|
import { Icon, Icons } from "icon.slint";
|
|
|
|
export { ShapeKind }
|
|
|
|
// The container of an entry's glyph, by file category: folders are cookies, media get the
|
|
// tertiary role, other files the secondary one. Selected entries morph to `active-shape`.
|
|
export global FileShapes {
|
|
public pure function shape(glyph: string) -> ShapeKind {
|
|
glyph == Icons.folder ? ShapeKind.cookie9
|
|
: glyph == Icons.audio ? ShapeKind.clover
|
|
: glyph == Icons.image ? ShapeKind.cookie6
|
|
: glyph == Icons.video ? ShapeKind.cookie4
|
|
: glyph == Icons.archive ? ShapeKind.cookie12
|
|
: glyph == Icons.program ? ShapeKind.scallop
|
|
: ShapeKind.circle
|
|
}
|
|
public pure function active-shape(glyph: string) -> ShapeKind {
|
|
glyph == Icons.folder ? ShapeKind.cookie4 : ShapeKind.cookie9
|
|
}
|
|
public pure function fill(glyph: string) -> color {
|
|
glyph == Icons.folder ? Theme.primary-container
|
|
: glyph == Icons.audio || glyph == Icons.image || glyph == Icons.video ? Theme.tertiary-container
|
|
: Theme.secondary-container
|
|
}
|
|
public pure function ink(glyph: string) -> color {
|
|
glyph == Icons.folder ? Theme.on-primary-container
|
|
: glyph == Icons.audio || glyph == Icons.image || glyph == Icons.video ? Theme.on-tertiary-container
|
|
: Theme.on-secondary-container
|
|
}
|
|
}
|
|
|
|
// A shaped glyph container (M3 Expressive). `active` morphs it from `shape` to
|
|
// `active-shape` (e.g. circle → cookie9 when selected); the morph runs only while `active`
|
|
// changes and is instant under reduced motion.
|
|
export component Shape {
|
|
in property <ShapeKind> shape: ShapeKind.circle;
|
|
in property <ShapeKind> active-shape: root.shape;
|
|
in property <bool> active;
|
|
// Degrees the outline is turned; the active outline turns a little more as it morphs.
|
|
in property <float> turn;
|
|
in property <brush> fill: Theme.secondary-container;
|
|
in property <brush> active-fill: root.fill;
|
|
in property <string> glyph;
|
|
// An image drawn in place of the glyph (a folder's own icon).
|
|
in property <image> picture;
|
|
in property <bool> has-picture;
|
|
in property <color> glyph-color: Theme.on-secondary-container;
|
|
in property <length> size: 40px;
|
|
// Glyph size as a share of the container.
|
|
in property <float> glyph-ratio: 0.55;
|
|
|
|
// 0 = `shape`, 1 = `active-shape`.
|
|
property <float> t: root.active ? 1 : 0;
|
|
animate t {
|
|
duration: Motion.time(Motion.medium2);
|
|
easing: Motion.emphasized;
|
|
}
|
|
|
|
width: root.size;
|
|
height: root.size;
|
|
|
|
// A square in the middle (a layout that squeezes one side must not cut the outline), with
|
|
// a margin round the 100-unit outline: the software renderer cuts a path flat where it
|
|
// meets its element's left and right edges.
|
|
property <length> side: min(root.width, root.height);
|
|
Path {
|
|
width: root.side * (1 + 2 * Theme.shape-margin);
|
|
height: self.width;
|
|
x: (root.width - self.width) / 2;
|
|
y: (root.height - self.height) / 2;
|
|
viewbox-x: -100 * Theme.shape-margin;
|
|
viewbox-y: -100 * Theme.shape-margin;
|
|
viewbox-width: 100 * (1 + 2 * Theme.shape-margin);
|
|
viewbox-height: self.viewbox-width;
|
|
fill: root.active ? root.active-fill : root.fill;
|
|
commands: Shapes.path(root.shape, root.active-shape, root.t, root.turn + root.t * Theme.shape-morph-turn);
|
|
animate fill {
|
|
duration: Motion.time(Motion.short4);
|
|
easing: Motion.standard;
|
|
}
|
|
}
|
|
|
|
if root.has-picture: Image {
|
|
x: (root.width - self.width) / 2;
|
|
y: (root.height - self.height) / 2;
|
|
width: root.size * root.glyph-ratio * 1.3;
|
|
height: self.width;
|
|
source: root.picture;
|
|
image-fit: contain;
|
|
}
|
|
|
|
if root.glyph != "" && !root.has-picture: Icon {
|
|
x: (root.width - self.width) / 2;
|
|
y: (root.height - self.height) / 2;
|
|
glyph: root.glyph;
|
|
size: root.size * root.glyph-ratio;
|
|
color: root.glyph-color;
|
|
}
|
|
|
|
// Overlays such as a link badge.
|
|
@children
|
|
}
|