Skip to content

Commit

Permalink
ui: submit as-is, warn about instability
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Jul 26, 2023
1 parent 36b36df commit f2bd59d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/ui/ui.v
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn (mut a App) init() ! {
},
]
},
/*
/*
&ui.PointerEventArea{
id: 100
x: 50
Expand Down
27 changes: 23 additions & 4 deletions ui/item.v
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub fn (i &Item) event(e Event) ?&Node {
}
for on_event in i.on_event {
assert !isnil(on_event)
// If `on_event` returns true, it means
// a listener on *this* item has accepted the event
if on_event(i, e) {
// If `on_event` returns true, it means
// a listener on *this* item has accepted the event
return i
}
}
Expand Down Expand Up @@ -164,9 +164,28 @@ pub fn (pea &PointerEventArea) event(e Event) ?&Node {
y: ey
}

// If `on_pointer_event` returns true, it means
// a listener on *this* item has accepted the event
// TODO BUG pea pointer address is not the same in userspace callbacks?!
/*
eprintln('${@STRUCT}.${@FN} ea: ${ptr_str(pea.EventArea)}')
eprintln('${@STRUCT}.${@FN} ea.this: ${ptr_str(pea.EventArea.this)}')
eprintln('${@STRUCT}.${@FN} pea: ${ptr_str(pea)}')
eprintln('${@STRUCT}.${@FN} id: ${pea.id}')
eprintln('${@STRUCT}.${@FN} this: ${ptr_str(pea.this)}')
//unsafe { pea.this = pea }
//if on_pointer_event(pea.EventArea, pe) {
mut copy := &PointerEventArea{...pea}
unsafe { copy.this = copy }
eprintln('${@STRUCT}.${@FN} copy ea: ${ptr_str(copy.EventArea)}')
eprintln('${@STRUCT}.${@FN} copy ea.this: ${ptr_str(copy.EventArea.this)}')
eprintln('${@STRUCT}.${@FN} copy pea: ${ptr_str(copy)}')
eprintln('${@STRUCT}.${@FN} copy id: ${copy.id}')
eprintln('${@STRUCT}.${@FN} copy this: ${ptr_str(copy.this)}')
*/

if on_pointer_event(pea, pe) {
// If `on_pointer_event` returns true, it means
// a listener on *this* item has accepted the event
return pea
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/node.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn (n &Node) collect(mut nodes []&Node, filter fn (n &Node) bool) {
// modify visits all `Node`s in a Breath-First search (BFS),
// calling `func` with each `Node` as an argument.
pub fn (n &Node) modify(func fn (mut n Node)) {
assert n != unsafe { nil }
assert n != unsafe { nil }, 'Node is null'
mut mn := unsafe { n }
func(mut mn)
for mut node in mn.body {
Expand Down
3 changes: 2 additions & 1 deletion ui/ui.v
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mut:
// init initializes the UI.
fn (mut u UI) init() ! {
u.root.parent = shy.null

eprintln('[WIP] UI module is still subject to change, use at own risk :)')
// Traverse the tree, root to leaves, set all `parent` fields.
u.modify(fn (mut n Node) {
for mut node in n.body {
Expand Down Expand Up @@ -141,6 +141,7 @@ pub fn (u &UI) draw(dt f64) {
unsafe {
u.dt = dt
}
// TODO surround in a separate render pass?
u.root.draw(u)
}

Expand Down

0 comments on commit f2bd59d

Please sign in to comment.