View

interface View : ColorThemeOverride

A View is similar to a Fragment, but instead of being a reusable group of Components with additional UI logic they represent reusable Screens with additional UI logic. Each View has its own screen that's used to display the contents of the View. Whenever a View is docked Screen.display will be called under the hood which will effectively replace any previously docked View.

Views add some lifecycle methods to the mix:

Docking works like this:

Whenever you create a View you have to extend BaseView and supply a TileGrid and a ColorTheme. For an example that uses best practices take a look at the included sample or a full example in the zircon.jvm.examples project.

Samples

import org.hexworks.zircon.api.Components.header
import org.hexworks.zircon.api.component.ColorTheme
import org.hexworks.zircon.api.component.ComponentAlignment
import org.hexworks.zircon.api.grid.TileGrid
import org.hexworks.zircon.api.view.base.BaseView
fun main() { 
   //sampleStart 
   class WelcomeView(tileGrid: TileGrid, theme: ColorTheme) : BaseView(tileGrid, theme) {

    // we add components to the screen when the view is initialized
    init {
        screen.addComponent(
            header()
                .withAlignmentWithin(screen, ComponentAlignment.CENTER)
                .withText("Hello, Zircon!")
        )
    }

    // used to initialize resources (like network connections) that are resource-intensive
    override fun onDock() {
        println("Docking Initial View.")
    }

    // usually used for cleanup operations
    override fun onUndock() {
        println("Undocking Initial View.")
    }


} 
   //sampleEnd
}

See also

Functions

dock
Link copied to clipboard
common
abstract fun dock()
Docks this View to the screen.
equals
Link copied to clipboard
common
open operator fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open fun hashCode(): Int
onDock
Link copied to clipboard
common
open fun onDock()
Callback that will be executed whenever this View is docked.
onUndock
Link copied to clipboard
common
open fun onUndock()
Callback that will be executed whenever another View is docked.
replaceWith
Link copied to clipboard
common
abstract fun replaceWith(view: View)
Replaces this View with view.
toString
Link copied to clipboard
common
open fun toString(): String

Properties

screen
Link copied to clipboard
common
abstract val screen: Screen
The Screen that's used to display the contents of this View.
theme
Link copied to clipboard
common
abstract override var theme: ColorTheme
The (mutable) ColorTheme.
themeProperty
Link copied to clipboard
common
abstract override val themeProperty: Property<ColorTheme>
A Property that wraps the theme and offers data binding and observability features.

Inheritors

BaseView
Link copied to clipboard

Sources

(source)
Link copied to clipboard