import { Frame, FrameTitle, RibStrip, ShallowPanel } from "frame.slint";
import { Label, Theme } from "base.slint";
import { BackButton, ConfirmButton } from "dialog-button.slint";
import { Scrollbar } from "scrollbar.slint";
export component OperationDialog {
in property <string> title;
in property <[string]> lines;
in property <bool> confirmable;
callback accepted();
callback back();
Rectangle { width: root.width; height: root.height; background: #00000080; }
TouchArea { width: root.width; height: root.height; }
Frame {
x: (root.width - self.width) / 2; y: (root.height - self.height) / 2;
width: min(660px, root.width - 48px); height: min(root.height - 80px, max(230px, content.preferred-height + 136px));
heading := FrameTitle { x: 12px; y: 5px; text: root.title; }
RibStrip { x: heading.x + heading.width + 12px; y: 8px; width: max(0px, parent.width - self.x - 12px); height: 24px; header: true; }
ShallowPanel {
x: 12px; y: 40px; width: parent.width - 24px; height: parent.height - 100px;
body := Flickable {
x: 12px; y: 12px; width: parent.width - 36px; height: parent.height - 24px;
content-width: self.width; content-height: content.preferred-height;
content := VerticalLayout {
width: parent.width; spacing: 12px;
for line in root.lines: Label { text: line; wrap: word-wrap; color: line.starts-with("Failed:") ? #ff5555 : line.starts-with("Warning:") || line.starts-with("Optional") ? Theme.orange : Theme.text; }
}
}
if body.content-height > body.height: Scrollbar {
x: parent.width - 12px; y: 4px; width: 12px; height: parent.height - 8px;
thumb-height: max(24px, self.height * body.height / body.content-height);
thumb-position: -body.content-y / max(1px, body.content-height - body.height) * (self.height - self.thumb-height);
scroll(delta) => { body.content-y = clamp(body.content-y + delta, -max(0px, body.content-height - body.height), 0px); }
moved(y) => { body.content-y = -clamp((y - self.thumb-height / 2) / max(1px, self.height - self.thumb-height), 0, 1) * max(0px, body.content-height - body.height); }
}
}
BackButton { x: 12px; y: parent.height - 44px; width: 112px; height: 32px; text: "Back"; clicked => { root.back(); } }
RibStrip { x: 132px; y: parent.height - 44px; width: parent.width - 316px; height: 32px; }
ConfirmButton { x: parent.width - 172px; y: parent.height - 44px; width: 160px; height: 32px; text: "Confirm"; enabled: root.confirmable; clicked => { root.accepted(); } }
}
}