objects/layouts/contract.go

41 lines
1.2 KiB
Go
Raw Normal View History

2023-08-10 15:52:01 -06:00
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
2023-08-10 15:52:01 -06:00
// ContractVertical is a vertical contracted layout.
const ContractVertical Contract = true
2023-08-10 15:52:01 -06:00
// ContractHorizontal is a horizontal contracted layout.
const ContractHorizontal Contract = false
2023-08-10 15:52:01 -06:00
2024-07-21 09:48:28 -06:00
func (contract Contract) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
return contract.fallback().MinimumSize(hints, boxes)
2023-08-10 15:52:01 -06:00
}
2024-07-21 09:48:28 -06:00
func (contract Contract) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
contract.fallback().Arrange(hints, boxes)
2023-08-10 15:52:01 -06:00
}
2024-07-21 09:48:28 -06:00
func (contract Contract) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
return contract.fallback().RecommendedHeight(hints, boxes, width)
}
2024-07-21 09:48:28 -06:00
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 { }
}
}