Update code for layouts, objects
This commit is contained in:
@@ -17,21 +17,21 @@ const FlowVertical Flow = true
|
||||
// FlowHorizontal is a horizontal flow layout.
|
||||
const FlowHorizontal Flow = false
|
||||
|
||||
func (flow Flow) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
||||
func (flow Flow) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||
// TODO: write down somewhere that layout minimums aren't taken into
|
||||
// account when the respective direction is overflowed
|
||||
return flow.fallback().MinimumSize(hints, boxes)
|
||||
}
|
||||
|
||||
func (flow Flow) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
func (flow Flow) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||
if flow.v() && !hints.OverflowY || flow.h() && !hints.OverflowX {
|
||||
flow.fallback().Arrange(hints, boxes)
|
||||
}
|
||||
|
||||
// find a minor size value that will fit all boxes
|
||||
minorSize := 0
|
||||
for _, box := range boxes {
|
||||
boxSize := flow.minor(box.MinimumSize())
|
||||
for index := 0; index < boxes.Len(); index ++ {
|
||||
boxSize := flow.minor(boxes.MinimumSize(index))
|
||||
if boxSize > minorSize { minorSize = boxSize }
|
||||
}
|
||||
if minorSize == 0 { return }
|
||||
@@ -43,17 +43,16 @@ func (flow Flow) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
// arrange
|
||||
point := hints.Bounds.Min
|
||||
index := 0
|
||||
for index < len(boxes) {
|
||||
for index < boxes.Len() {
|
||||
// get a slice of boxes for this major step
|
||||
stepIndexEnd := index + minorSteps
|
||||
if stepIndexEnd > len(boxes) { stepIndexEnd = len(boxes) }
|
||||
step := boxes[index:stepIndexEnd]
|
||||
if stepIndexEnd > boxes.Len() { stepIndexEnd = boxes.Len() }
|
||||
index += minorSteps
|
||||
|
||||
// find a major size that will fit all boxes on this major step
|
||||
majorSize := 0
|
||||
for _, box := range step {
|
||||
boxSize := flow.major(box.MinimumSize())
|
||||
for index := index; index < stepIndexEnd; index ++ {
|
||||
boxSize := flow.major(boxes.MinimumSize(index))
|
||||
if boxSize > majorSize { majorSize = boxSize }
|
||||
}
|
||||
if majorSize == 0 { continue }
|
||||
@@ -62,9 +61,9 @@ func (flow Flow) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
var size image.Point
|
||||
size = flow.incrMajor(size, majorSize)
|
||||
size = flow.incrMinor(size, minorSize)
|
||||
for _, box := range step {
|
||||
for index := index; index < stepIndexEnd; index ++ {
|
||||
bounds := image.Rectangle { Min: point, Max: point.Add(size) }
|
||||
box.SetBounds(bounds)
|
||||
boxes.SetBounds(index, bounds)
|
||||
|
||||
point = flow.incrMinor(point, minorSize + flow.minor(hints.Gap))
|
||||
}
|
||||
@@ -125,12 +124,12 @@ func (flow Flow) fallback () tomo.Layout {
|
||||
return Contract(flow)
|
||||
}
|
||||
|
||||
func (flow Flow) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
||||
func (flow Flow) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||
// TODO
|
||||
return 0
|
||||
}
|
||||
|
||||
func (flow Flow) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
||||
func (flow Flow) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||
// TODO
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user