left right
This commit is contained in:
parent
b3713d1fa7
commit
b6263a4955
1 changed files with 20 additions and 17 deletions
|
|
@ -932,38 +932,41 @@ func adjustPadding(obj *d2graph.Object, width, height float64, padding shapePadd
|
||||||
innerRight := int(math.Ceil(width - (innerBox.TopLeft.X + innerBox.Width)))
|
innerRight := int(math.Ceil(width - (innerBox.TopLeft.X + innerBox.Width)))
|
||||||
|
|
||||||
// additional padding for label/icon
|
// additional padding for label/icon
|
||||||
labelHeight := 0
|
var extraTop, extraBottom, extraLeft, extraRight int
|
||||||
if obj.HasLabel() {
|
if obj.HasLabel() && obj.LabelPosition != nil {
|
||||||
labelHeight = obj.LabelDimensions.Height + 2*label.PADDING
|
labelHeight := obj.LabelDimensions.Height + 2*label.PADDING
|
||||||
}
|
labelWidth := obj.LabelDimensions.Width + 2*label.PADDING
|
||||||
iconHeight := 0
|
|
||||||
if obj.Icon != nil && obj.Shape.Value != d2target.ShapeImage {
|
|
||||||
iconHeight = d2target.GetIconSize(innerBox, string(label.InsideTopLeft)) + 2*label.PADDING
|
|
||||||
}
|
|
||||||
|
|
||||||
var extraTop, extraBottom int
|
|
||||||
// TODO left right
|
|
||||||
if obj.LabelPosition != nil {
|
|
||||||
switch label.Position(*obj.LabelPosition) {
|
switch label.Position(*obj.LabelPosition) {
|
||||||
case label.InsideTopLeft, label.InsideTopCenter, label.InsideTopRight:
|
case label.InsideTopLeft, label.InsideTopCenter, label.InsideTopRight:
|
||||||
|
// TODO for corners we only add height, but need to confirm there is enough width
|
||||||
extraTop = labelHeight
|
extraTop = labelHeight
|
||||||
case label.InsideBottomLeft, label.InsideBottomCenter, label.InsideBottomRight:
|
case label.InsideBottomLeft, label.InsideBottomCenter, label.InsideBottomRight:
|
||||||
extraBottom = labelHeight
|
extraBottom = labelHeight
|
||||||
|
case label.InsideMiddleLeft:
|
||||||
|
extraLeft = labelWidth
|
||||||
|
case label.InsideMiddleRight:
|
||||||
|
extraRight = labelWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if obj.IconPosition != nil {
|
if obj.Icon != nil && obj.Shape.Value != d2target.ShapeImage && obj.IconPosition != nil {
|
||||||
|
iconSize := d2target.GetIconSize(innerBox, string(label.InsideTopLeft)) + 2*label.PADDING
|
||||||
|
|
||||||
switch label.Position(*obj.IconPosition) {
|
switch label.Position(*obj.IconPosition) {
|
||||||
case label.InsideTopLeft, label.InsideTopCenter, label.InsideTopRight:
|
case label.InsideTopLeft, label.InsideTopCenter, label.InsideTopRight:
|
||||||
extraTop = go2.Max(extraTop, iconHeight)
|
extraTop = go2.Max(extraTop, iconSize)
|
||||||
case label.InsideBottomLeft, label.InsideBottomCenter, label.InsideBottomRight:
|
case label.InsideBottomLeft, label.InsideBottomCenter, label.InsideBottomRight:
|
||||||
extraBottom = go2.Max(extraBottom, iconHeight)
|
extraBottom = go2.Max(extraBottom, iconSize)
|
||||||
|
case label.InsideMiddleLeft:
|
||||||
|
extraLeft = go2.Max(extraLeft, iconSize)
|
||||||
|
case label.InsideMiddleRight:
|
||||||
|
extraRight = go2.Max(extraRight, iconSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
padding.top = go2.Max(padding.top, innerTop+extraTop)
|
padding.top = go2.Max(padding.top, innerTop+extraTop)
|
||||||
padding.bottom = go2.Max(padding.bottom, innerBottom+extraBottom)
|
padding.bottom = go2.Max(padding.bottom, innerBottom+extraBottom)
|
||||||
padding.left = go2.Max(padding.left, innerLeft)
|
padding.left = go2.Max(padding.left, innerLeft+extraLeft)
|
||||||
padding.right = go2.Max(padding.right, innerRight)
|
padding.right = go2.Max(padding.right, innerRight+extraRight)
|
||||||
|
|
||||||
return padding
|
return padding
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue