From 6c7706d19d5912e87e0c0e818b76fd0d5f5250c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 31 Oct 2015 17:07:55 -0400 Subject: [PATCH] lib/app/ui & platforms: use CompositeControl::remove for Layout MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/ui/native_ui.nit | 2 ++ lib/android/ui/ui.nit | 6 ++++++ lib/app/ui.nit | 4 ++-- lib/linux/ui.nit | 7 +++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/android/ui/native_ui.nit b/lib/android/ui/native_ui.nit index 7e273c4..aaae0bd 100644 --- a/lib/android/ui/native_ui.nit +++ b/lib/android/ui/native_ui.nit @@ -62,6 +62,8 @@ extern class NativeViewGroup in "Java" `{ android.view.ViewGroup `} fun add_view(view: NativeView) in "Java" `{ self.addView(view); `} + fun remove_view(view: NativeView) in "Java" `{ self.removeView(view); `} + fun add_view_with_weight(view: NativeView, weight: Float) in "Java" `{ self.addView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, (float)weight)); diff --git a/lib/android/ui/ui.nit b/lib/android/ui/ui.nit index 1dc6d78..2661d0e 100644 --- a/lib/android/ui/ui.nit +++ b/lib/android/ui/ui.nit @@ -70,6 +70,12 @@ redef class Layout # FIXME abstract the use either homogeneous or weight to balance views size in a layout native.add_view_with_weight(item.native, 1.0) end + + redef fun remove(item) + do + super + if item isa View then native.remove_view item.native + end end redef class HorizontalLayout diff --git a/lib/app/ui.nit b/lib/app/ui.nit index 73c42c1..65bcffe 100644 --- a/lib/app/ui.nit +++ b/lib/app/ui.nit @@ -112,10 +112,10 @@ class CompositeControl protected fun add(item: Control) do items.add item # Remove `item` from `self` - protected fun remove(item: Control) do if has(item) then items.remove item + fun remove(item: Control) do if has(item) then items.remove item # Is `item` in `self`? - protected fun has(item: Control): Bool do return items.has(item) + fun has(item: Control): Bool do return items.has(item) redef fun on_create do for i in items do i.on_create diff --git a/lib/linux/ui.nit b/lib/linux/ui.nit index f3deb77..7c0d6d2 100644 --- a/lib/linux/ui.nit +++ b/lib/linux/ui.nit @@ -83,12 +83,19 @@ redef class Window end redef class View + init do native.show + redef fun enabled do return native.sensitive redef fun enabled=(enabled) do native.sensitive = enabled or else true end redef class Layout redef type NATIVE: GtkBox + redef fun remove(view) + do + super + native.remove view.native + end end redef class HorizontalLayout -- 1.7.9.5