forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (59 loc) · 2.81 KB
/
main.cpp
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
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
#include "gallery.h"
#ifdef HAVE_GETTEXT
# include <locale>
# include <libintl.h>
#endif
int main()
{
#ifdef HAVE_GETTEXT
bindtextdomain("gallery", SRC_DIR "/lang/");
std::locale::global(std::locale(""));
#endif
auto demo = App::create();
auto row_data = std::make_shared<
slint::VectorModel<std::shared_ptr<slint::Model<slint::StandardListViewItem>>>>();
for (int r = 1; r < 101; r++) {
auto items = std::make_shared<slint::VectorModel<slint::StandardListViewItem>>();
for (int c = 1; c < 5; c++) {
slint::SharedString text("item");
text = text + slint::SharedString::from_number(c) + slint::SharedString(".")
+ slint::SharedString::from_number(r);
items->push_back(slint::StandardListViewItem { text });
}
row_data->push_back(items);
}
demo->global<TableViewPageAdapter>().set_row_data(row_data);
demo->global<TableViewPageAdapter>().on_sort_ascending([row_data,
demo = slint::ComponentWeakHandle(
demo)](int index) {
auto demo_lock = demo.lock();
(*demo_lock)
->global<TableViewPageAdapter>()
.set_row_data(std::make_shared<slint::SortModel<
std::shared_ptr<slint::Model<slint::StandardListViewItem>>>>(
row_data, [index](auto lhs, auto rhs) {
auto c_lhs = lhs->row_data(index);
auto c_rhs = rhs->row_data(index);
return c_lhs->text < c_rhs->text;
}));
});
demo->global<TableViewPageAdapter>().on_sort_descending([row_data,
demo = slint::ComponentWeakHandle(
demo)](int index) {
auto demo_lock = demo.lock();
(*demo_lock)->global<TableViewPageAdapter>().set_row_data(row_data);
(*demo_lock)
->global<TableViewPageAdapter>()
.set_row_data(std::make_shared<slint::SortModel<
std::shared_ptr<slint::Model<slint::StandardListViewItem>>>>(
(*demo_lock)->global<TableViewPageAdapter>().get_row_data(),
[index](auto lhs, auto rhs) {
auto c_lhs = lhs->row_data(index);
auto c_rhs = rhs->row_data(index);
return c_rhs->text < c_lhs->text;
}));
});
demo->run();
}