import { UiSounds, UiCue } from "audio.slint";
import { Nine, Label, Theme } from "base.slint";
import { Pieces } from "pieces.slint";
import { Checkbox } from "checkbox.slint";
import { Icons } from "icons.slint";
import { Button } from "button.slint";
export component SortArrow {
in property <bool> active: true;
in property <bool> ascending: false;
width: 8px; height: 8px;
Image { width: 8px; height: 8px; image-rendering: pixelated; source: root.ascending ? (root.active ? Icons.sort-up-active : Icons.sort-up-white) : (root.active ? Icons.sort-down-active : Icons.sort-down-white); }
}
export component TableCell {
in property <bool> selected;
in property <string> state: "default";
// Invalid row: the banner's negative_message_frame surface (its derived hover piece under the pointer); selected and held rows show their own.
in property <bool> red;
Nine { width: root.width; height: root.height; // A held row is drawn with the light selected_clicked set whether or not it was selected (game-row-pressed.png).
source: root.red && !root.selected && root.state != "clicked" ? (root.state == "hovered" ? Pieces.negative-message-frame-hovered-base : Pieces.negative-message-frame-default-base) : root.state == "clicked" ? Pieces.table-with-selection-selected-clicked-base : root.selected ? (root.state == "hovered" ? Pieces.table-with-selection-selected-hovered-base : Pieces.table-with-selection-selected-base) : root.state == "hovered" ? Pieces.table-with-selection-hovered-base : Pieces.table-with-selection-default-base; }
}
export component TableRow {
in property <bool> placeholder;
in property <bool> downloading;
in property <bool> failed;
in property <float> fraction;
in property <string> progress-label;
callback cancel();
in property <string> text;
in property <string> version;
in property <bool> checked;
in property <bool> enabled: true;
in property <bool> disabled-text;
in property <bool> pending;
in property <bool> elide-text;
in property <bool> selected;
// Ticked with a missing required dependency: the banner's red surface and warning icon (selected: orange row, icon kept).
in property <bool> red;
callback hover-changed(bool);
in property <string> state: "auto";
in property <length> check-width: 42px;
in property <length> version-width: 61px;
callback selected-row(); callback toggled();
preferred-height: 28px;
property <bool> hovered: touch.has-hover || check.hovered;
property <bool> red-surface: root.red && !root.selected && root.visual != "clicked";
property <length> icon-shift: root.red ? 20px : 0px;
property <color> ink: root.red-surface ? (root.pending ? Theme.pending : Theme.text) : root.selected || root.visual == "hovered" || root.visual == "clicked" ? Theme.black : root.pending ? Theme.pending : root.disabled-text ? #919191 : Theme.text;
property <string> visual: root.state == "auto" ? (touch.pressed ? "clicked" : root.hovered ? "hovered" : "default") : root.state;
TableCell { x: 0px; width: root.check-width; height: root.height; selected: root.selected; state: root.visual; red: root.red; }
TableCell { x: root.check-width; width: root.width - root.check-width - root.version-width; height: root.height; selected: root.selected; state: root.visual; red: root.red; }
TableCell { x: root.width - root.version-width; width: root.version-width; height: root.height; selected: root.selected; state: root.visual; red: root.red; }
if root.pending: Rectangle { x: 0px; y: 1px; width: 3px; height: root.height - 2px; background: Theme.pending-accent; }
changed hovered => { root.hover-changed(root.hovered); }
touch := TouchArea { clicked => { UiSounds.begin(); root.selected-row(); UiSounds.finish(UiCue.selection); } }
check := Checkbox { visible: !root.placeholder; x: 20px; y: (root.height - 14px)/2; checked: root.checked; enabled: root.enabled; dirt: false; toggled => { root.toggled(); } }
if root.red: Image { x: root.check-width + 8px; y: (root.height - 16px)/2; width: 16px; height: 16px; source: Icons.warning; image-rendering: pixelated; colorize: root.red-surface ? transparent : Theme.black; }
Label { x: root.check-width + 8px + root.icon-shift; y: 0px; width: root.elide-text ? max(0px, root.width - root.check-width - root.version-width - 16px - root.icon-shift - (root.downloading ? 250px : 0px)) : self.preferred-width; height: root.height; overflow: root.elide-text ? elide : clip; vertical-alignment: center; text: root.text; color: root.ink; opacity: root.pending && root.disabled-text && !root.selected && root.visual != "hovered" && root.visual != "clicked" ? Theme.disabled-row-opacity : 1; }
if root.downloading: Rectangle {
x: root.width - root.version-width - 240px; y: 8px; width: 200px; height: 12px;
if !root.failed: Nine { width: parent.width; height: parent.height; source: Pieces.progressbar-background-default-base; }
if !root.failed && root.fraction > 0: Nine { width: max(8px, parent.width * clamp(root.fraction, 0, 1)); height: parent.height; source: Pieces.progressbar-fill-default-base; }
Label { x: 4px; y: -8px; width: parent.width - 8px; height: 28px; vertical-alignment: center; horizontal-alignment: center; overflow: elide; text: root.progress-label; color: root.failed ? #ff8e8e : Theme.text; font-size: 12px; }
}
if root.downloading: Button { sound: UiCue.tool; x: root.width - root.version-width - 32px; y: 2px; width: 24px; min-width: 0px; min-height: 24px; height: 24px; text: "X"; transparent-background: true; clicked => { root.cancel(); } }
Label { x: root.width - root.version-width; width: root.version-width; height: root.height; horizontal-alignment: center; vertical-alignment: center; text: root.version; y: 0px; color: root.ink; opacity: root.pending && root.disabled-text && !root.selected && root.visual != "hovered" && root.visual != "clicked" ? Theme.disabled-row-opacity : 1; }
}
export component TableHeader {
in property <[string]> labels: ["Name", "Version"];
in property <length> check-width: 42px;
in property <[length]> widths: [673px,61px];
in property <bool> mixed: true;
in property <bool> checked;
in property <bool> enabled: true;
// The checkbox and its sort target are separate, matching Manage's game header.
in property <bool> arrow: root.enabled;
in property <int> check-sort-column: 2;
in property <string> check-state: "auto";
in property <int> sort-column: -1;
in property <bool> ascending: true;
callback toggle-all(); callback sort(int);
preferred-height: 28px;
TableCell { x: 0px; y: 0px; width: root.check-width; height: root.height; }
if root.arrow: SortArrow { x: 8px; y: (root.height - 8px)/2; active: root.sort-column == root.check-sort-column; ascending: root.sort-column == root.check-sort-column && !root.ascending; }
Checkbox { x: root.arrow ? 20px : 8px; y: (root.height - 14px)/2; mixed: root.mixed; checked: root.checked; enabled: root.enabled; dirt: false; state: root.check-state; toggled => { root.toggle-all(); } }
if root.arrow: TouchArea { x: 0px; y: 0px; width: 18px; height: root.height; clicked => { UiSounds.begin(); root.sort(root.check-sort-column); UiSounds.finish(UiCue.click); } }
HorizontalLayout { x: root.check-width; width: root.width - root.check-width; spacing: 0px;
for label[i] in root.labels: Rectangle {
width: root.widths[i];
clip: root.widths[i] == 0px;
TableCell { width: parent.width; height: parent.height; }
// The game's down chevron denotes ascending list order (game-manage-100.png).
if i == root.sort-column: SortArrow { x: i == 0 ? 8px : parent.width - 10px; y: (parent.height - 8px)/2; ascending: !root.ascending; }
Label { x: i == 0 ? 20px : 0px; width: parent.width - self.x - (i > 0 && root.sort-column == i ? 10px : 0px); height: parent.height; y: -1px; vertical-alignment: center; horizontal-alignment: i == 0 ? left : center; text: label; font-weight: 600; }
TouchArea { clicked => { UiSounds.begin(); root.sort(i); UiSounds.finish(UiCue.click); } }
}
}
}
export component EmptyList {
// mods_scroll_pane: 4px padding, 20px tile + 8px gap (style.lua).
for i in ceil(root.height / 28px): Rectangle {
x: 7px; y: i * 28px + 4px; width: root.width - 14px; height: 16px; clip: true;
Nine { x: -3px; y: -2px; width: parent.width + 6px; height: 20px; source: Pieces.mods-scroll-pane-default-background-base; }
}
}
// Updates table row: check cell, name, local and new version cells, all with the Manage table's per-cell bevels.
export component UpdateTableRow {
in property <bool> downloading;
in property <float> fraction;
in property <bool> check-enabled: true;
in property <string> text;
in property <string> local-version;
in property <string> new-version;
in property <bool> checked;
in property <length> check-width: 30px;
in property <bool> check-arrow;
in property <string> updated;
in property <[length]> widths: [94px, 90px, 118px];
in property <string> state: "auto";
in property <bool> selected;
callback toggled(); callback selected-row();
preferred-height: 28px;
property <bool> hovered: touch.has-hover || check.hovered;
property <string> visual: root.state == "auto" ? (touch.pressed ? "clicked" : root.hovered ? "hovered" : "default") : root.state;
property <color> ink: root.selected || root.visual == "hovered" || root.visual == "clicked" ? Theme.black : Theme.text;
property <length> name-width: root.width - root.check-width - root.widths[0] - root.widths[1] - root.widths[2];
TableCell { x: 0px; width: root.check-width; height: root.height; selected: root.selected; state: root.visual; }
TableCell { x: root.check-width; width: root.name-width; height: root.height; selected: root.selected; state: root.visual; }
TableCell { x: root.check-width + root.name-width; width: root.widths[0]; height: root.height; selected: root.selected; state: root.visual; }
TableCell { x: root.check-width + root.name-width + root.widths[0]; width: root.widths[1]; height: root.height; selected: root.selected; state: root.visual; }
TableCell { x: root.width - root.widths[2]; width: root.widths[2]; height: root.height; selected: root.selected; state: root.visual; }
touch := TouchArea { clicked => { UiSounds.begin(); root.selected-row(); UiSounds.finish(UiCue.selection); } }
check := Checkbox { x: root.check-arrow ? 20px : 8px; y: (root.height - 14px)/2; checked: root.checked; enabled: root.check-enabled; dirt: false; toggled => { root.toggled(); } }
Label { x: root.check-width + 8px; y: 0px; width: max(0px, root.name-width - 16px - (root.downloading ? 112px : 0px)); height: root.height; overflow: elide; vertical-alignment: center; text: root.text; color: root.ink; }
if root.downloading: Rectangle {
x: root.check-width + root.name-width - 108px; y: 10px; width: 96px; height: 8px;
Nine { width: parent.width; height: parent.height; source: Pieces.progressbar-background-default-base; }
if root.fraction > 0: Nine { x: 0px; width: max(8px, parent.width * clamp(root.fraction, 0, 1)); height: parent.height; source: Pieces.progressbar-fill-default-base; }
Nine { x: -4px; y: -4px; width: parent.width + 8px; height: parent.height + 8px; source: Pieces.progressbar-background-default-shadow; }
}
Label { x: root.check-width + root.name-width; y: 0px; width: root.widths[0]; height: root.height; overflow: clip; horizontal-alignment: center; vertical-alignment: center; text: root.local-version; color: root.ink; }
Label { x: root.check-width + root.name-width + root.widths[0]; y: 0px; width: root.widths[1]; height: root.height; horizontal-alignment: center; vertical-alignment: center; text: root.new-version; color: root.ink; }
Label { x: root.width - root.widths[2]; y: 0px; width: root.widths[2]; height: root.height; overflow: elide; horizontal-alignment: center; vertical-alignment: center; text: root.updated; color: root.ink; }
}