Skip to content

Commit

Permalink
examples, ui: comment all bugged code and submit as-is
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Jul 26, 2023
1 parent 259aa3e commit 36b36df
Showing 1 changed file with 89 additions and 22 deletions.
111 changes: 89 additions & 22 deletions examples/ui/ui.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub fn (m &MyUIItem) parent() &ui.Node {
return m.EventArea.parent()
}

pub fn (m &MyUIItem) draw(ui &ui.UI) {
m.EventArea.draw(ui)
pub fn (m &MyUIItem) draw(ui_ &ui.UI) {
m.EventArea.draw(ui_)
}

pub fn (m &MyUIItem) event(e ui.Event) ?&ui.Node {
Expand All @@ -46,8 +46,8 @@ pub fn (m &MyRect) parent() &ui.Node {
return m.Rectangle.parent()
}

pub fn (m &MyRect) draw(ui &ui.UI) {
m.Rectangle.draw(ui)
pub fn (m &MyRect) draw(ui_ &ui.UI) {
m.Rectangle.draw(ui_)
}

pub fn (m &MyRect) event(e ui.Event) ?&ui.Node {
Expand Down Expand Up @@ -78,26 +78,50 @@ pub fn (mut a App) init() ! {
width: 25
height: 25
body: [
/*
&MyRect{
id: 800
width: 20
on_event: [
fn (n &ui.Node, e ui.Event) bool {
node := &&MyRect(n) // TODO this is a weird V quirk
eprintln('MyRect in call: ${ptr_str(n)}')
assert node.id == n.id
// println('MyUIItem on_event reached ${node.id}/${n.id}')
// mut mmui := unsafe { node }
// mmui.width++
// println('${@STRUCT}/MyUIItem on_event was called ${mmui.width}')
// return true
return false
},
]
},
*/
/*
&MyUIItem{
id: 400
width: 10
on_event: [
fn (n &ui.Node, e ui.Event) bool {
node := &&MyUIItem(n) // TODO this is a weird V quirk
eprintln('MyUIItem this in call: ${ptr_str(n)}')
assert node.id == n.id
// println('MyUIItem on_event reached ${node.id}/${n.id}')
mut mmui := unsafe { node }
mmui.width++
// mut mmui := unsafe { node }
// mmui.width++
// println('${@STRUCT}/MyUIItem on_event was called ${mmui.width}')
// return true
return false
},
]
},
},*/
]
},
]
},
/*
&ui.PointerEventArea{
id: 100
x: 50
Expand All @@ -120,14 +144,28 @@ pub fn (mut a App) init() ! {
]*/
on_pointer_event: [
fn (n &ui.Node, e ui.PointerEvent) bool {
// println('ui.EventArea on_event reached ${n.id}')
// println('PointerEventArea on_pointer_event reached ${n.id}')
// TODO BUG V mixes up the pointer here see also `shy/ui/item.v` etc.
// dump(typeof(n))
/*
mut pea := &&ui.PointerEventArea(n)
eprintln('PointerEventArea n in call: ${ptr_str(n)}')
eprintln('PointerEventArea this in call: ${ptr_str(n.this)}')
eprintln('PointerEventArea &n in call: ${ptr_str(&n)}')
eprintln('PointerEventArea pea in call: ${ptr_str(pea)}')
// TODO `n &ui.Node` -> `n` pointer is not the same as in `ui/item.v`????
assert pea.id == n.id, 'HARD TO REPRODUCE V BUG'
println('PointerEventArea ${pea.id} found .x: ${pea.x}')
pea.x += 1
pea := &&ui.PointerEventArea(n)
// assert pea.id == n.id
mut mpea := unsafe { pea }
// mut mpea := unsafe { pea }
// println('PointerEventArea ${mpea.id} found .x: ${mpea.x}')
// mpea.x += 1
// return true
*/
return false
},
]
Expand All @@ -142,8 +180,25 @@ pub fn (mut a App) init() ! {
fn (n &ui.Node, e ui.Event) bool {
// if n is ui.Rectangle {
// ur := &ui.Rectangle(n)
mut mr := &&MyRect(n)
assert mr.id == n.id
if mr.width < 50 {
mr.width += 0.1
}
if mr.height < 50 {
mr.height += 0.1
}
if mr.width >= 50 {
mr.width = 6
}
if mr.height >= 50 {
mr.height = 6
}
// mut mr := unsafe { n }
// println('mr.x: ${mr.x}')
// println('ur.x: ${ur.x} mr.x: ${mr.x}')
Expand All @@ -156,7 +211,7 @@ pub fn (mut a App) init() ! {
]
},
]
},
},*/
]
}
a.ui = ui.new(
Expand Down Expand Up @@ -187,22 +242,34 @@ pub fn (mut a App) event(e shy.Event) {
// Mutability test
a.ui.modify(fn (mut n ui.Node) {
// TODO BUG broken - V doesn't allow for retreiving back the original pointer of a *custom* type implementing ui.Node...
// The horrible thing is that it only works... sometimes :(
// The horrible thing is that it ~works... sometimes :(
// mut maybe := ui.cast[MyRect](n)
mut maybe := &&MyRect(n)
// println('oi ${maybe}')
if maybe.id == 420 {
//

/*
if n.id == 420 {
mut my_rect := &&MyRect(n)
// println('oi ${maybe}')
maybe.x += 0.5
maybe.y += 0.25
my_rect.x += 0.5
my_rect.y += 0.25
}
*/

// mut maybe := &&MyRect(n)
// println('oi ${maybe}')
// if maybe.id == 420 {
// // println('oi ${maybe}')
// maybe.x += 0.5
// maybe.y += 0.25
//}
/*
if mut n is ui.Rectangle {
// mut n := unsafe { node }
if n.id == 42 {
if n.x == 200 {
n.x = 0
if n.x < 200 {
n.x += 1
} else {
n.x = 200
n.x = 0
}
}
// pid := n.parent() or { 0 }.id
Expand All @@ -212,7 +279,7 @@ pub fn (mut a App) event(e shy.Event) {
// ppid := n.parent().id
// println('${pid} vs. ${ppid}')
}
}
}*/
})

/*
Expand Down

0 comments on commit 36b36df

Please sign in to comment.