1
0
Fork 0
mirror of synced 2024-06-27 10:30:37 +12:00
czkawka/krokiet/ui/selectable_tree_view.slint

153 lines
6.6 KiB
Plaintext
Raw Normal View History

2023-11-13 01:54:59 +13:00
import { Button, VerticalBox , HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox, ScrollView} from "std-widgets.slint";
2023-10-22 23:18:41 +13:00
import {TypeOfOpenedItem} from "common.slint";
2023-10-29 05:20:46 +13:00
import {ColorPalette} from "color_palette.slint";
2023-10-29 07:08:14 +13:00
import {MainListModel} from "common.slint";
2023-11-12 21:09:15 +13:00
import {Callabler} from "callabler.slint";
2023-11-13 01:54:59 +13:00
import {GuiState} from "gui_state.slint";
2023-10-18 08:31:08 +13:00
export component SelectableTableView inherits Rectangle {
2023-10-22 23:18:41 +13:00
callback item_opened(string);
2023-10-18 08:31:08 +13:00
in property <[string]> columns;
2023-10-29 07:08:14 +13:00
in-out property <[MainListModel]> values;
2023-10-22 23:18:41 +13:00
in-out property <[length]> column_sizes;
2023-10-22 22:32:13 +13:00
private property <int> column_number: column-sizes.length + 1;
2023-10-22 23:18:41 +13:00
// This idx, starts from zero, but since first is always a checkbox, and is not in model.val values, remove 1 from idx
in-out property <int> parentPathIdx;
in-out property <int> fileNameIdx;
2023-10-22 10:33:29 +13:00
in-out property <int> selected_item: -1;
2023-11-17 20:20:24 +13:00
out property <length> list_view_width: max(self.width - 20px, column_sizes[0] + column_sizes[1] + column_sizes[2] + column_sizes[3] + column_sizes[4] + column_sizes[5] + column_sizes[6] + column_sizes[7] + column_sizes[8] + column_sizes[9] + column_sizes[10] + column_sizes[11]);
2023-10-23 09:12:59 +13:00
forward-focus: focus_item;
2023-10-27 07:57:17 +13:00
// TODO not works
2023-10-23 09:12:59 +13:00
focus_item := FocusScope {
key-released(event) => {
2023-11-17 20:20:24 +13:00
debug(event);
2023-10-23 09:12:59 +13:00
accept
}
}
2023-11-14 09:47:02 +13:00
VerticalBox {
padding: 0px;
forward-focus: focus-item;
ScrollView {
height: 30px;
viewport-x <=> list_view.viewport-x;
vertical-stretch: 0;
2023-11-13 04:00:55 +13:00
HorizontalLayout {
spacing: 5px;
for title [idx] in root.columns: HorizontalLayout {
width: root.column-sizes[idx];
Text {
overflow: elide;
text: title;
}
2023-10-22 10:33:29 +13:00
2023-11-13 04:00:55 +13:00
Rectangle {
width: 1px;
background: gray;
2023-10-23 09:12:59 +13:00
forward-focus: focus-item;
2023-11-13 04:00:55 +13:00
TouchArea {
width: 5px;
x: (parent.width - self.width) / 2;
property <length> cached;
forward-focus: focus-item;
pointer-event(event) => {
if (event.button == PointerEventButton.left && event.kind == PointerEventKind.down) {
self.cached = root.column_sizes[idx];
}
2023-10-18 08:31:08 +13:00
}
2023-11-13 04:00:55 +13:00
moved => {
if (self.pressed) {
root.column_sizes[idx] += (self.mouse-x - self.pressed-x);
if (root.column_sizes[idx] < 20px) {
root.column_sizes[idx] = 20px;
}
2023-10-18 08:31:08 +13:00
}
}
2023-11-13 04:00:55 +13:00
mouse-cursor: ew-resize;
2023-10-18 08:31:08 +13:00
}
}
}
}
2023-11-14 09:47:02 +13:00
}
2023-11-11 05:11:32 +13:00
2023-11-14 09:47:02 +13:00
list_view := ListView {
padding: 0px;
min-width: 100px;
forward-focus: focus-item;
for r [idx] in root.values: Rectangle {
2023-11-16 05:00:09 +13:00
width: list_view_width;
2023-11-14 09:47:02 +13:00
border-radius: 5px;
2023-10-23 09:12:59 +13:00
forward-focus: focus-item;
2023-11-14 09:47:02 +13:00
height: 20px;
background: r.header-row ? ColorPalette.list_view_normal_header_color : (touch-area.has-hover ? (r.selected_row ? ColorPalette.list-view-normal-selected-header : ColorPalette.list_view_normal_color) : (r.selected_row ? ColorPalette.list-view-normal-selected-header : ColorPalette.list_view_normal_color));
touch_area := TouchArea {
2023-10-23 09:12:59 +13:00
forward-focus: focus-item;
2023-11-14 09:47:02 +13:00
clicked => {
if (!r.header_row) {
r.selected_row = !r.selected_row;
if (root.selected-item == -1) {
root.selected-item = idx;
} else {
if (r.selected_row == true) {
root.values[root.selected-item].selected_row = false;
2023-10-22 10:33:29 +13:00
root.selected-item = idx;
} else {
2023-11-14 09:47:02 +13:00
root.selected-item = -1;
2023-10-22 10:33:29 +13:00
}
2023-11-14 09:47:02 +13:00
}
2023-11-13 01:54:59 +13:00
2023-11-14 09:47:02 +13:00
if (root.selected_item != -1) {
Callabler.load_image_preview(r.val[root.parentPathIdx - 1] + "/" + r.val[root.fileNameIdx - 1]);
} else {
GuiState.preview-visible = false;
2023-11-13 01:54:59 +13:00
}
2023-10-21 19:36:56 +13:00
}
2023-11-14 09:47:02 +13:00
}
pointer-event(event) => {
// TODO this should be clicked by double-click
if (event.button == PointerEventButton.right && event.kind == PointerEventKind.up) {
Callabler.item_opened(r.val[root.parentPathIdx - 1])
} else if (event.button == PointerEventButton.middle && event.kind == PointerEventKind.up) {
Callabler.item_opened(r.val[root.parentPathIdx - 1] + "/" + r.val[root.fileNameIdx - 1])
2023-10-22 23:18:41 +13:00
}
}
2023-11-14 09:47:02 +13:00
}
2023-10-18 08:31:08 +13:00
2023-11-14 09:47:02 +13:00
HorizontalLayout {
forward-focus: focus-item;
CheckBox {
visible: !r.header-row;
checked: r.checked && !r.header-row;
width: root.column-sizes[0];
2023-10-23 09:12:59 +13:00
forward-focus: focus-item;
2023-11-14 09:47:02 +13:00
toggled => {
r.checked = self.checked;
2023-10-20 08:39:48 +13:00
}
2023-11-14 09:47:02 +13:00
}
2023-10-18 08:31:08 +13:00
2023-11-14 09:47:02 +13:00
HorizontalLayout {
spacing: 5px;
for f [idx] in r.val: Text {
width: root.column-sizes[idx + 1];
text: f;
font-size: 12px;
forward-focus: focus-item;
vertical-alignment: center;
overflow: elide;
2023-10-18 08:31:08 +13:00
}
}
}
}
}
}
2023-11-13 04:00:55 +13:00
public function deselect_selected_item() {
if (root.selected_item != -1) {
root.values[root.selected-item].selected_row = false;
root.selected-item = -1;
}
}
2023-11-11 05:11:32 +13:00
}