Scrollable list of views in a simple list

Introduced properties

init defaultinit(parent: nullable CompositeControl, enabled: nullable Bool)

app :: ListLayout :: defaultinit

protected fun native=(native: NATIVE)

app :: ListLayout :: native=

protected fun native=(native: NATIVE)

app :: ListLayout :: native=

protected fun native=(native: NATIVE)

app :: ListLayout :: native=

fun native_list_box: GtkListBox

app :: ListLayout :: native_list_box

Container inside native
protected fun native_list_box=(native_list_box: GtkListBox)

app :: ListLayout :: native_list_box=

Container inside native
fun native_rows: Map[View, GtkListBoxRow]

app :: ListLayout :: native_rows

GtkListBoxRow used to contains children Views
protected fun native_rows=(native_rows: Map[View, GtkListBoxRow])

app :: ListLayout :: native_rows=

GtkListBoxRow used to contains children Views
fun native_stack_view: UIStackView

app :: ListLayout :: native_stack_view

Real container of the subviews, contained within native
protected fun native_stack_view=(native_stack_view: UIStackView)

app :: ListLayout :: native_stack_view=

Real container of the subviews, contained within native

Redefined properties

redef type NATIVE: GtkScrolledWindow

linux :: ui $ ListLayout :: NATIVE

Type of native
redef type NATIVE: UIScrollView

ios :: ui $ ListLayout :: NATIVE

Type of the native implementation of this control
redef type NATIVE: Android_widget_ListView

android :: ui $ ListLayout :: NATIVE

Type of native
redef type SELF: ListLayout

app $ ListLayout :: SELF

Type of this instance, automatically specialized in every class
redef fun add(view: Control)

ios :: ui $ ListLayout :: add

Add item as a child of self
redef fun add(item: Control)

linux :: ui $ ListLayout :: add

Add item as a child of self
redef fun add(item: Control)

android :: ui $ ListLayout :: add

Add item as a child of self
redef init init

linux :: ui $ ListLayout :: init

redef fun native: NATIVE

ios :: ui $ ListLayout :: native

Native implementation of this control
redef fun native: NATIVE

android :: ui $ ListLayout :: native

The Android element used to implement self
redef fun native: NATIVE

linux :: ui $ ListLayout :: native

The GTK element used to implement self
redef fun parent=(parent: nullable CompositeControl)

ios :: ui $ ListLayout :: parent=

Direct parent Control in the control tree
redef fun remove(item: Control)

linux :: ui $ ListLayout :: remove

Remove item from self

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type NATIVE: NSObject

app :: Control :: NATIVE

Type of the native implementation of this control
type NATIVE: JavaObject

app :: Control :: NATIVE

Type of native
type NATIVE: GtkWidget

app :: Control :: NATIVE

Type of native
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun add(item: Control)

app :: CompositeControl :: add

Add item as a child of self
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun clear

app :: CompositeControl :: clear

Remove all items from self
init defaultinit(parent: nullable CompositeControl, enabled: nullable Bool)

app :: ListLayout :: defaultinit

init defaultinit(parent: nullable CompositeControl, enabled: nullable Bool)

app :: View :: defaultinit

init defaultinit(parent: nullable CompositeControl)

app :: Control :: defaultinit

abstract fun enabled: nullable Bool

app :: View :: enabled

Is this control enabled so the user can interact with it?
abstract fun enabled=(enabled: nullable Bool)

app :: View :: enabled=

Is this control enabled so the user can interact with it?
fun finalize

core :: Finalizable :: finalize

Liberate any resources held by self before the memory holding self is freed
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has(item: Control): Bool

app :: CompositeControl :: has

Is item in self?
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
protected fun items: Array[Control]

app :: CompositeControl :: items

Child controls composing this control
protected fun items=(items: Array[Control])

app :: CompositeControl :: items=

Child controls composing this control
abstract fun native: NATIVE

app :: Control :: native

The GTK element used to implement self
abstract fun native: NATIVE

app :: Control :: native

The Android element used to implement self
abstract fun native: NATIVE

app :: Control :: native

Native implementation of this control
protected fun native=(native: NATIVE)

app :: ListLayout :: native=

protected fun native=(native: NATIVE)

app :: ListLayout :: native=

protected fun native=(native: NATIVE)

app :: ListLayout :: native=

fun native_list_box: GtkListBox

app :: ListLayout :: native_list_box

Container inside native
protected fun native_list_box=(native_list_box: GtkListBox)

app :: ListLayout :: native_list_box=

Container inside native
fun native_rows: Map[View, GtkListBoxRow]

app :: ListLayout :: native_rows

GtkListBoxRow used to contains children Views
protected fun native_rows=(native_rows: Map[View, GtkListBoxRow])

app :: ListLayout :: native_rows=

GtkListBoxRow used to contains children Views
fun native_stack_view: UIStackView

app :: ListLayout :: native_stack_view

Real container of the subviews, contained within native
protected fun native_stack_view=(native_stack_view: UIStackView)

app :: ListLayout :: native_stack_view=

Real container of the subviews, contained within native
fun notify_observers(event: AppEvent)

app :: AppComponent :: notify_observers

Propagate event to all observers by calling AppObserver::on_event
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun observers: HashSet[AppObserver]

app :: AppComponent :: observers

All AppObserver notified of events raised by self
protected fun observers=(observers: HashSet[AppObserver])

app :: AppComponent :: observers=

All AppObserver notified of events raised by self
fun on_create

app :: AppComponent :: on_create

The application is being created
fun on_destroy

app :: AppComponent :: on_destroy

The application is being destroyed
fun on_event(event: AppEvent)

app :: AppObserver :: on_event

Notification of event raised by sender
fun on_pause

app :: AppComponent :: on_pause

The application leaves the active state but is still partially visible
fun on_restart

app :: AppComponent :: on_restart

The application returns to a visible state from a previous on_stop
fun on_restore_state

app :: AppComponent :: on_restore_state

The application is launching, restore its state from a previous on_save_state
fun on_resume

app :: AppComponent :: on_resume

The application enters the active state, it is in the foreground and interactive
fun on_save_state

app :: AppComponent :: on_save_state

The application may be destroyed soon, save its state for a future on_restore_state
fun on_start

app :: AppComponent :: on_start

The application is starting or restarting, it is visible to the user
fun on_stop

app :: AppComponent :: on_stop

The application is completely hidden from the user
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parent: nullable CompositeControl

app :: Control :: parent

Direct parent Control in the control tree
fun parent=(parent: nullable CompositeControl)

app :: Control :: parent=

Direct parent Control in the control tree
fun remove(item: Control)

app :: CompositeControl :: remove

Remove item from self
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
abstract fun signal(sender: GtkWidget, user_data: nullable Object)

gtk :: GtkCallable :: signal

return true to stop event processing, false to let it propagate
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram app::ListLayout ListLayout app::View View app::ListLayout->app::View app::CompositeControl CompositeControl app::ListLayout->app::CompositeControl app::Control Control app::View->app::Control app::CompositeControl->app::Control ...app::Control ... ...app::Control->app::Control

Ancestors

abstract class AppComponent

app :: AppComponent

An element of an application that is notified of the application life cycle
interface AppObserver

app :: AppObserver

Observer of AppEvents raised by AppComponents
class Control

app :: Control

A control implementing the UI
class Finalizable

core :: Finalizable

An object needing finalization
interface GtkCallable

gtk :: GtkCallable

interface Object

core :: Object

The root of the class hierarchy.

Parents

class CompositeControl

app :: CompositeControl

A Control grouping other controls
abstract class View

app :: View

A visible Control

Class definitions

app $ ListLayout
# Scrollable list of views in a simple list
class ListLayout
	super View
	super CompositeControl
end
lib/app/ui.nit:327,1--331,3

ios :: ui $ ListLayout
# On iOS, implemented by a `UIStackView` inside a ` UIScrollView`
redef class ListLayout

	redef type NATIVE: UIScrollView
	redef var native = new UIScrollView

	# Real container of the subviews, contained within `native`
	var native_stack_view = new UIStackView

	redef fun parent=(parent)
	do
		super

		var root_view
		if parent isa Window then
			root_view = parent.native.view
		else if parent isa View then
			root_view = parent.native
		else return

		# Setup scroll view
		var native_scroll_view = native
		native_scroll_view.translates_autoresizing_mask_into_constraits = false
		native_add_constraints(root_view, native_scroll_view)

		# Setup stack_view
		native_stack_view.translates_autoresizing_mask_into_constraits = false
		native_stack_view.axis = new UILayoutConstraintAxis.vertical
		native_scroll_view.add_subview native_stack_view
		native_add_constraints(native_scroll_view, native_stack_view)
		native_lock_vertical_scroll(native_scroll_view, native_stack_view)
	end

	# Add constraints to lock the vertical and horizontal dimensions
	private fun native_add_constraints(root_view: UIView, nested_view: UIView)
	in "ObjC" `{
		[root_view addConstraints:[NSLayoutConstraint
			constraintsWithVisualFormat: @"V:|-0-[nested_view]-0-|"
			options: NSLayoutFormatAlignAllCenterX metrics: nil views: @{@"nested_view": nested_view}]];
		[root_view addConstraints:[NSLayoutConstraint
			constraintsWithVisualFormat: @"H:|-0-[nested_view]-0-|"
			options: NSLayoutFormatAlignAllCenterX metrics: nil views: @{@"nested_view": nested_view}]];
	`}

	# Add a constraint to lock to the scroll vertically
	private fun native_lock_vertical_scroll(scroll_view: UIScrollView, stack_view: UIStackView)
	in "ObjC" `{
		[scroll_view addConstraint: [scroll_view.widthAnchor constraintEqualToAnchor:stack_view.widthAnchor]];
	`}

	redef fun add(view)
	do
		super

		if view isa View then
			native_stack_view.add_arranged_subview view.native
		end
	end
end
lib/ios/ui/ui.nit:438,1--496,3

linux :: ui $ ListLayout
# On GNU/Linux, this is implemented by a `GtkListBox` inside a `GtkScrolledWindow`
redef class ListLayout

	redef type NATIVE: GtkScrolledWindow

	redef var native = new GtkScrolledWindow

	# Container inside `native`
	var native_list_box = new GtkListBox

	# `GtkListBoxRow` used to contains children `View`s
	var native_rows = new Map[View, GtkListBoxRow]

	init do
		native_list_box.selection_mode = new GtkSelectionMode.none
		native.add native_list_box

		# Set the size of the GtkScrolledWindow:
		# use content width and set static height
		native.set_policy(new GtkPolicyType.never, new GtkPolicyType.automatic)
		native.set_size_request(gtk_window_width_request, 640)
	end

	redef fun add(item)
	do
		super
		if item isa View then
			var native_row = new GtkListBoxRow
			#native_row.activable = false # TODO with GTK 3.14
			#native_row.selectable = false
			native_row.add item.native

			native_rows[item] = native_row
			native_list_box.add native_row
			native_row.show
		end
	end

	redef fun remove(item)
	do
		super
		if item isa View then
			var native_row = native_rows.get_or_null(item)
			if native_row == null then
				print_error "Error: {self} does not contains {item}"
				return
			end

			native_list_box.remove native_row
			native_rows.keys.remove item
			native_row.destroy
		end
	end
end
lib/linux/ui.nit:185,1--238,3

android :: ui $ ListLayout
redef class ListLayout
	redef type NATIVE: Android_widget_ListView

	redef var native do
		var layout = new Android_widget_ListView(app.native_activity)
		layout = layout.new_global_ref
		return layout
	end

	private var adapter: Android_widget_ArrayAdapter do
		var adapter = new Android_widget_ArrayAdapter(app.native_activity,
			android_r_layout_simple_list_item_1, self)
		native.set_adapter adapter
		return adapter.new_global_ref
	end

	redef fun add(item)
	do
		super
		if item isa View then adapter.add item.native
	end

	private fun create_view(position: Int): NativeView
	do
		var ctrl = items[position]
		assert ctrl isa View
		return ctrl.native
	end
end
lib/android/ui/ui.nit:177,1--205,3