lib/app/ui & platforms: use CompositeControl::remove for Layout
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 31 Oct 2015 21:07:55 +0000 (17:07 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 10 Nov 2015 19:04:33 +0000 (14:04 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/ui/native_ui.nit
lib/android/ui/ui.nit
lib/app/ui.nit
lib/linux/ui.nit

index 7e273c4..aaae0bd 100644 (file)
@@ -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));
index 1dc6d78..2661d0e 100644 (file)
@@ -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
index 73c42c1..65bcffe 100644 (file)
@@ -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
 
index f3deb77..7c0d6d2 100644 (file)
@@ -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