1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/7guis"#]
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: MIT
4
5import { LineEdit, ScrollView} from "std-widgets.slint";
6
7struct CellContent { value: float, formula: string }
8
9export component MainWindow inherits Window {
10 in property <[[CellContent]]> cells;
11
12 private property <length> cell-height: 32px;
13 private property <length> cell-width: 100px;
14 private property <{r: int, c: int}> active-cell: { r: -1, c: -1 };
15
16 ScrollView {
17 width: 100%;
18 height: 100%;
19 viewport-width: 20px + 26 * root.cell-width;
20 viewport-height: 100 * root.cell-height;
21
22 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 {
23 y:0;
24 x: 20px + idx * root.cell-width;
25 height: root.cell-height;
26 width: root.cell-width;
27 Text { x:0;y:0; text: letter; }
28 }
29 for row[row-idx] in root.cells : Rectangle {
30 y: root.cell-height + row-idx * root.cell-height;
31 height: root.cell-height;
32
33 Text { x:0;y:0; text: row_idx; }
34
35 for cell[col-idx] in row: Rectangle {
36 property <bool> is-active: root.active-cell.r == row-idx && root.active-cell.c == col-idx;
37
38 y:0;
39 height: root.cell-height;
40 width: root.cell-width;
41 border-color: gray;
42 border-width: 1px;
43 x: 20px + col-idx * root.cell-width;
44
45 Text {
46 visible: !is-active && cell.formula != "";
47 text: " " + cell.value;
48 vertical-alignment: center;
49 width: 100%;
50 height: 100%;
51 }
52
53 TouchArea {
54 clicked => {
55 l.text = cell.formula;
56 root.active-cell = {r: row-idx, c: col-idx};
57 l.focus();
58 }
59 }
60
61 l := LineEdit {
62 edited => {
63 cell = { value: self.text.to-float(), formula: self.text };
64 }
65 accepted => {
66 root.active-cell = { r: -1, c: -1};
67 }
68
69 visible: is-active;
70 width: 100%;
71 height: 100%;
72 }
73 }
74 }
75 }
76}
77
78component Cell inherits MainWindow {
79 // initialize the cells with demy value to be viewed in the preview
80 in-out property <[CellContent]> _row: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
81 cells: [
82 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,
83 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,
84 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,
85 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,
86 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,
87 ];
88}
89}
90