From 7eae2e57a2b506ebfe9a8e8bc0781dff50d2f33f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 23 Jun 2016 18:09:44 -0400 Subject: [PATCH] app.nit: events are propagated to parents of controls MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/app/ui.nit | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/app/ui.nit b/lib/app/ui.nit index cb45ac2..996629f 100644 --- a/lib/app/ui.nit +++ b/lib/app/ui.nit @@ -107,11 +107,17 @@ class Control # Direct parent `Control` in the control tree # + # The parents (direct and indirect) receive all events from `self`, + # like the `observers`. + # # If `null` then `self` is at the root of the tree, or not yet attached. var parent: nullable CompositeControl = null is private writable(set_parent) # Direct parent `Control` in the control tree # + # The parents (direct and indirect) receive all events from `self`, + # like the `observers`. + # # Setting `parent` calls `remove` on the old parent and `add` on the new one. fun parent=(parent: nullable CompositeControl) is autoinit do @@ -124,12 +130,25 @@ class Control set_parent parent end + + # Also notify the parents (both direct and indirect) + redef fun notify_observers(event) + do + super + + var p = parent + while p != null do + p.on_event event + p = p.parent + end + end end # A `Control` grouping other controls class CompositeControl super Control + # Child controls composing this control protected var items = new Array[Control] # Add `item` as a child of `self` -- 1.7.9.5