Update Cacao README

This commit is contained in:
Shadowfacts 2019-08-08 18:56:06 -04:00
parent 91e40e346b
commit ca3f2328f0
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 42 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package net.shadowfacts.asmr
import net.shadowfacts.cacao.CacaoScreen
import net.shadowfacts.cacao.Window
import net.shadowfacts.cacao.view.*
import net.shadowfacts.cacao.view.button.Button
import net.shadowfacts.cacao.viewcontroller.ViewController
/**
@ -17,16 +18,20 @@ class TestCacaoScreen: CacaoScreen() {
}
override fun viewDidLoad() {
val labelContainer = view.addSubview(View())
val container = view.addSubview(View())
createConstraints {
labelContainer.centerXAnchor equalTo view.centerXAnchor
labelContainer.centerYAnchor equalTo view.centerYAnchor
container.centerXAnchor equalTo view.centerXAnchor
container.centerYAnchor equalTo view.centerYAnchor
}
embedChild(object: ViewController() {
override fun loadView() {
this.view = Label("test child")
val button = Button(Label("test button"))
button.handler = {
println("button clicked")
}
this.view = button
}
}, container = labelContainer)
}, container = container)
}
}
addWindow(Window(viewController))

View File

@ -8,6 +8,7 @@ enum class RedstoneMode {
companion object {
fun localize(value: RedstoneMode): String {
// todo: localize me
return value.name.toLowerCase().capitalize()
}
}

View File

@ -1,3 +1,33 @@
# Cacao
Cacao is a UI framework for Fabric/Minecraft mods based on Apple's [Cocoa](https://en.wikipedia.org/wiki/Cocoa_(API)
UI toolkit.
Cacao is a UI framework for Fabric/Minecraft mods based on Apple's [Cocoa](https://en.wikipedia.org/wiki/Cocoa_(API)) UI toolkit.
## Architecture
### Screen
A [CacaoScreen][] is the object that acts as the interface between Minecraft GUI code and the Cacao framework.
The CacaoScreen draws Cacao views on screen and passes Minecraft input events to the appropriate Views. The CacaoScreen
owns a group of [Window](#window) objects which are displayed on screen, one on top of the other.
[CacaoScreen]: https://git.shadowfacts.net/minecraft/ASMR/src/branch/master/src/main/kotlin/net/shadowfacts/cacao/CacaoScreen.kt
### Window
A [Window][] object has a root [View Controller](#view-controller) that it displays on screen.
The Window occupies the entire screen space and translates events from the screen to the root View Controller's View.
It owns a Solver object that manages layout constraints. The window also handles screen resizing and re-lays out the
view hierarchy.
[Window]: https://git.shadowfacts.net/minecraft/ASMR/src/branch/master/src/main/kotlin/net/shadowfacts/cacao/Window.kt
### View Controller
A [ViewController][] object owns a view, receives lifecycle events for it, and is generally used to control the view.
Each View Controller has a single root [View](#view) which in turn may have subviews.
[ViewController]: https://git.shadowfacts.net/minecraft/ASMR/src/branch/master/src/main/kotlin/net/shadowfacts/cacao/viewcontroller/ViewController.kt
### View
A [View][] object represents a single view on screen. It handles drawing, positioning, and directly handles input.
[View]: https://git.shadowfacts.net/minecraft/ASMR/src/branch/master/src/main/kotlin/net/shadowfacts/cacao/view/View.kt