Skip to content

Commit 521b96d

Browse files
committed
Use embed_file for resources
1 parent c656e1b commit 521b96d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

test.png

-3.83 KB
Loading

toolbar.v

+21-8
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,26 @@ fn create_img_button(mut win ui.Window, path string, x int, y int, w int, h int)
157157
return pen_btn
158158
}
159159

160+
fn create_img_button_(mut win ui.Window, img_data []u8, x int, y int, w int, h int) &ui.Image {
161+
mut pen_btn := ui.image_from_byte_array_with_size(mut win, img_data, 32, 32)
162+
pen_btn.z_index = 8
163+
164+
if x != 0 {
165+
pen_btn.set_bounds(x, y, w, h)
166+
}
167+
return pen_btn
168+
}
169+
160170
fn setup_brush_choices(mut win ui.Window) {
161171
mut hbox := ui.hbox(win)
162172
hbox.set_bounds(16, 32, 40 * 3, 23)
163173
hbox.z_index = 7
164174

165-
mut pencil_btn := create_img_button(mut win, 'icons8-pencil-drawing-48.png', 0, 0,
166-
0, 0)
175+
embed_pencil := $embed_file('resources/icons8-pencil-drawing-48.png')
176+
embed_pen := $embed_file('resources/icons8-pen-48.png')
177+
embed_spray := $embed_file('resources/icons8-paint-sprayer-48.png')
178+
179+
mut pencil_btn := create_img_button_(mut win, embed_pencil.to_bytes(), 0, 0, 0, 0)
167180
pencil_btn.draw_event_fn = fn (mut win ui.Window, com &ui.Component) {
168181
if com.is_mouse_rele {
169182
mut this := *com
@@ -178,7 +191,7 @@ fn setup_brush_choices(mut win ui.Window) {
178191
}
179192
hbox.add_child(pencil_btn)
180193

181-
mut pen_btn := create_img_button(mut win, 'icons8-pen-48.png', 0, 0, 0, 0)
194+
mut pen_btn := create_img_button_(mut win, embed_pen.to_bytes(), 0, 0, 0, 0)
182195
pen_btn.draw_event_fn = fn (mut win ui.Window, com &ui.Component) {
183196
if com.is_mouse_rele {
184197
mut this := *com
@@ -189,8 +202,7 @@ fn setup_brush_choices(mut win ui.Window) {
189202
}
190203
hbox.add_child(pen_btn)
191204

192-
mut spray_btn := create_img_button(mut win, 'icons8-paint-sprayer-48.png', 0, 0, 0,
193-
0)
205+
mut spray_btn := create_img_button_(mut win, embed_spray.to_bytes(), 0, 0, 0, 0)
194206
spray_btn.draw_event_fn = fn (mut win ui.Window, com &ui.Component) {
195207
if com.is_mouse_rele {
196208
mut this := *com
@@ -221,8 +233,9 @@ fn make_toolbar(mut win ui.Window) {
221233

222234
setup_brush_choices(mut win)
223235

224-
mut picker_btn := create_img_button(mut win, 'icons8-color-wheel-2-48.png', 1, 22,
225-
48, 48)
236+
embed_picker := $embed_file('resources/icons8-color-wheel-2-48.png')
237+
mut picker_btn := create_img_button_(mut win, embed_picker.to_bytes(), 1, 22, 48,
238+
48)
226239
picker_btn.set_id(mut win, 'picker_btn')
227240
picker_btn.draw_event_fn = fn (mut win ui.Window, com &ui.Component) {
228241
if com.is_mouse_rele {
@@ -239,7 +252,7 @@ fn make_toolbar(mut win ui.Window) {
239252
mut picker_btn := &ui.Image(win.get_from_id('picker_btn'))
240253
size := gg.window_size()
241254

242-
picker_btn.x = size.width - picker_btn.width //- 23
255+
picker_btn.x = size.width - picker_btn.width
243256

244257
com.x = 0
245258
com.y = 25

vpaint.v

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ fn main() {
3939
win.extra_map['save_path'] = path
4040
}
4141

42+
if !os.exists(path) {
43+
mut blank_png := $embed_file('test.png')
44+
os.write_file_array(path, blank_png.to_bytes()) or {}
45+
}
46+
4247
mut png_file := read(path) or { panic(err) }
4348
win.bar = ui.menubar(win, win.theme)
4449

@@ -189,7 +194,7 @@ fn save_as_click(mut win ui.Window, com ui.MenuItem) {
189194
mut path := ui.textfield(win, '')
190195
path.set_id(mut win, 'save-as-path')
191196
path.set_bounds(140, 70, 300, 25)
192-
//path.multiline = false
197+
// path.multiline = false
193198

194199
if 'save_path' in win.extra_map {
195200
path.text = win.extra_map['save_path']

0 commit comments

Comments
 (0)