1 | module main |
2 | |
3 | import os |
4 | import gg |
5 | import gx |
6 | import sokol.sapp |
7 | |
8 | const ( |
9 | max_files = 12 |
10 | text = 'Drag&Drop here max ${max_files} files.' |
11 | text_size = 16 |
12 | ) |
13 | |
14 | struct App { |
15 | mut: |
16 | gg &gg.Context = unsafe { nil } |
17 | dropped_file_list []string = []string{} |
18 | } |
19 | |
20 | fn main() { |
21 | mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf')) |
22 | mut app := &App{ |
23 | gg: 0 |
24 | } |
25 | app.gg = gg.new_context( |
26 | bg_color: gx.rgb(174, 198, 255) |
27 | width: 600 |
28 | height: 400 |
29 | window_title: 'Drag and drop' |
30 | frame_fn: frame |
31 | font_path: font_path |
32 | user_data: app |
33 | event_fn: my_event_manager |
34 | // drag & drop |
35 | enable_dragndrop: true |
36 | max_dropped_files: max_files |
37 | max_dropped_file_path_length: 2048 |
38 | ) |
39 | app.gg.run() |
40 | } |
41 | |
42 | fn my_event_manager(mut ev gg.Event, mut app App) { |
43 | // drag&drop event |
44 | if ev.typ == .files_dropped { |
45 | num_dropped := sapp.get_num_dropped_files() |
46 | app.dropped_file_list.clear() |
47 | for i in 0 .. num_dropped { |
48 | app.dropped_file_list << sapp.get_dropped_file_path(i) |
49 | } |
50 | } |
51 | } |
52 | |
53 | fn frame(mut app App) { |
54 | app.gg.begin() |
55 | |
56 | mut txt_conf := gx.TextCfg{ |
57 | color: gx.black |
58 | align: .left |
59 | size: int(text_size * app.gg.scale + 0.5) |
60 | } |
61 | app.gg.draw_text(12, 12, text, txt_conf) |
62 | |
63 | mut y := 40 |
64 | for c, f in app.dropped_file_list { |
65 | app.gg.draw_text(12, y, '[${c}] ${f}', txt_conf) |
66 | y += text_size |
67 | } |
68 | |
69 | app.gg.end() |
70 | } |