diff --git a/examples/ui/ui.v b/examples/ui/ui.v index 8e203ac..59e167e 100644 --- a/examples/ui/ui.v +++ b/examples/ui/ui.v @@ -121,7 +121,7 @@ pub fn (mut a App) init() ! { }, ] }, - /* + /* &ui.PointerEventArea{ id: 100 x: 50 diff --git a/ui/item.v b/ui/item.v index e95d224..87a0187 100644 --- a/ui/item.v +++ b/ui/item.v @@ -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 } } @@ -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 } } diff --git a/ui/node.v b/ui/node.v index a581ed3..f44e683 100644 --- a/ui/node.v +++ b/ui/node.v @@ -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 { diff --git a/ui/ui.v b/ui/ui.v index e980714..812a727 100644 --- a/ui/ui.v +++ b/ui/ui.v @@ -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 { @@ -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) }