2023-08-10 15:52:01 -06:00
|
|
|
package layouts
|
|
|
|
|
|
|
|
import "image"
|
|
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
|
|
|
2024-06-11 14:46:04 -06:00
|
|
|
var _ tomo.Layout = ContractVertical
|
|
|
|
|
2024-05-17 01:56:49 -06:00
|
|
|
// 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
|
|
|
|
2024-05-17 01:56:49 -06:00
|
|
|
// ContractVertical is a vertical contracted layout.
|
|
|
|
const ContractVertical Contract = true
|
2023-08-10 15:52:01 -06:00
|
|
|
|
2024-05-17 01:56:49 -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 {
|
2024-06-12 01:15:38 -06:00
|
|
|
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) {
|
2024-06-12 01:15:38 -06:00
|
|
|
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 {
|
2024-06-12 01:15:38 -06:00
|
|
|
return contract.fallback().RecommendedHeight(hints, boxes, width)
|
2024-06-11 15:12:18 -06:00
|
|
|
}
|
|
|
|
|
2024-07-21 09:48:28 -06:00
|
|
|
func (contract Contract) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
2024-06-12 01:15:38 -06:00
|
|
|
return contract.fallback().RecommendedWidth(hints, boxes, height)
|
2024-06-11 15:12:18 -06:00
|
|
|
}
|
|
|
|
|
2024-06-12 01:15:38 -06:00
|
|
|
func (contract Contract) fallback () tomo.Layout {
|
|
|
|
if contract == ContractVertical {
|
|
|
|
return Column { }
|
|
|
|
} else {
|
|
|
|
return Row { }
|
|
|
|
}
|
|
|
|
}
|