Skip to content

Commit 7a768a3

Browse files
authoredFeb 16, 2024··
ci: fix notices with latest V 0.4.4 1d3147e (#570)
1 parent da77554 commit 7a768a3

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed
 

‎src/interface_action.v

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ pub fn (mut s Actionable) add_action(action string, context voidptr, action_fn A
3030

3131
// TODO: documentation
3232
pub fn (s &Actionable) run_action(action string) {
33-
if action in s.actions {
34-
action_ := s.actions[action]
35-
action_.action_fn(action_.context)
33+
if a := s.actions[action] {
34+
a.action_fn(a.context)
3635
}
3736
}

‎src/interface_shortcut.v

+9-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ pub fn (mut s Shortcutable) add_shortcut(shortcut string, key_fn ShortcutFn) {
2929
pub fn (mut s Shortcutable) add_shortcut_context(shortcut string, context voidptr) {
3030
_, code, key := parse_shortcut(shortcut)
3131
if code == 0 {
32-
s.shortcuts.chars[key].context = context
32+
unsafe {
33+
s.shortcuts.chars[key].context = context
34+
}
3335
} else {
34-
s.shortcuts.keys[code].context = context
36+
unsafe {
37+
s.shortcuts.keys[code].context = context
38+
}
3539
}
3640
}
3741

@@ -69,8 +73,7 @@ pub fn char_shortcut(e KeyEvent, shortcuts Shortcuts, context voidptr) {
6973
s = rune(96 + e.codepoint).str()
7074
}
7175
}
72-
if s in shortcuts.chars {
73-
sc := shortcuts.chars[s]
76+
if sc := shortcuts.chars[s] {
7477
if has_key_mods(e.mods, sc.mods) {
7578
if sc.context != unsafe { nil } {
7679
sc.key_fn(sc.context)
@@ -84,8 +87,8 @@ pub fn char_shortcut(e KeyEvent, shortcuts Shortcuts, context voidptr) {
8487
// TODO: documentation
8588
pub fn key_shortcut(e KeyEvent, shortcuts Shortcuts, context voidptr) {
8689
// println("key_shortcut ${int(e.key)}")
87-
if int(e.key) in shortcuts.keys {
88-
sc := shortcuts.keys[int(e.key)]
90+
ikey := int(e.key)
91+
if sc := shortcuts.keys[ikey] {
8992
if has_key_mods(e.mods, sc.mods) {
9093
if sc.context != unsafe { nil } {
9194
sc.key_fn(sc.context)

‎src/picture.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn (mut pic Picture) init(parent Layout) {
9393
eprintln('V UI: picture file "${pic.path}" not found')
9494
}
9595
if !pic.use_cache && pic.path in u.resource_cache {
96-
pic.image = u.resource_cache[pic.path]
96+
pic.image = unsafe { u.resource_cache[pic.path] }
9797
} else if mut pic.ui.dd is DrawDeviceContext {
9898
mut dd := pic.ui.dd
9999
if img := dd.create_image(pic.path) {

‎src/ui.v

+6-3
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,18 @@ fn (mut gui UI) load_imgs() {
145145
// complete the drawing system
146146
pub fn (mut gui UI) load_img(id string, b []u8, path string) {
147147
if mut gui.dd is DrawDeviceContext {
148-
if img := gui.dd.create_image_from_byte_array(b) {
148+
if mut img := gui.dd.create_image_from_byte_array(b) {
149+
img.path = path
149150
gui.imgs[id] = img
150-
gui.imgs[id].path = path
151151
}
152152
}
153153
}
154154

155155
pub fn (gui &UI) img(id string) gg.Image {
156-
return gui.imgs[id]
156+
if img := gui.imgs[id] {
157+
return img
158+
}
159+
panic('img with id: `${id}` not found')
157160
}
158161

159162
pub fn (gui &UI) has_img(id string) bool {

0 commit comments

Comments
 (0)
Please sign in to comment.