slint/examples/7guis/cells.slint
Florian Blasius 520df46998
Update examples to new syntax (#2067)
* run slint-updater on examples
* manual syntax updates
2023-01-16 12:11:25 +00:00

86 lines
3.9 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
import { LineEdit, ScrollView} from "std-widgets.slint";
struct CellContent { value: float, formula: string }
export component MainWindow inherits Window {
private property<length> cell-height: 32px;
private property<length> cell-width: 100px;
in property <[[CellContent]]> cells;
private property <{r: int, c: int}> active-cell: { r: -1, c: -1 };
ScrollView {
width: 100%;
height: 100%;
viewport-width: 20px + 26 * root.cell-width;
viewport-height: 100 * root.cell-height;
for letter[idx] in ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ] : Rectangle {
y:0;
x: 20px + idx * root.cell-width;
height: root.cell-height;
width: root.cell-width;
Text { x:0;y:0; text: letter; }
}
for row[row-idx] in root.cells : Rectangle {
y: root.cell-height + row-idx * root.cell-height;
height: root.cell-height;
Text { x:0;y:0; text: row_idx; }
for cell[col-idx] in row: Rectangle {
y:0;
height: root.cell-height;
width: root.cell-width;
border-color: gray;
border-width: 1px;
x: 20px + col-idx * root.cell-width;
property <bool> is-active: root.active-cell.r == row-idx && root.active-cell.c == col-idx;
Text {
visible: !is-active && cell.formula != "";
text: " " + cell.value;
vertical-alignment: center;
width: 100%;
height: 100%;
}
TouchArea {
clicked => {
l.text = cell.formula;
root.active-cell = {r: row-idx, c: col-idx};
l.focus();
}
}
l := LineEdit {
visible: is-active;
width: 100%;
height: 100%;
edited => {
cell = { value: self.text.to-float(), formula: self.text };
}
accepted => {
root.active-cell = { r: -1, c: -1};
}
}
}
}
}
}
component Cell inherits MainWindow {
// initialize the cells with demy value to be viewed in the preview
in-out property <[CellContent]> _row: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
cells: [
root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row,
root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row,
root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row,
root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row,
root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row,
];
}