objects/layouts/contract.go

41 lines
1.2 KiB
Go

package layouts
import "image"
import "git.tebibyte.media/tomo/tomo"
var _ tomo.Layout = ContractVertical
// Contract is a layout that arranges boxes in a simple row or column according
// to their minimum sizes.
type Contract bool
// ContractVertical is a vertical contracted layout.
const ContractVertical Contract = true
// ContractHorizontal is a horizontal contracted layout.
const ContractHorizontal Contract = false
func (contract Contract) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
return contract.fallback().MinimumSize(hints, boxes)
}
func (contract Contract) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
contract.fallback().Arrange(hints, boxes)
}
func (contract Contract) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
return contract.fallback().RecommendedHeight(hints, boxes, width)
}
func (contract Contract) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
return contract.fallback().RecommendedWidth(hints, boxes, height)
}
func (contract Contract) fallback () tomo.Layout {
if contract == ContractVertical {
return Column { }
} else {
return Row { }
}
}