forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cells.slint
86 lines (73 loc) · 3.89 KB
/
cells.slint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright © SixtyFPS GmbH <[email protected]>
// 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,
];
}