View
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
Properties
Inheritors
BaseView
Link copied to clipboard
Sources
(source)
Link copied to clipboard