hasIcon restore label+icon height adjustment

This commit is contained in:
Gavin Nishizawa 2023-12-12 16:01:48 -08:00
parent eca0febf84
commit 9f63c305a9
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 13 additions and 2 deletions

View file

@ -565,6 +565,10 @@ func (obj *Object) HasLabel() bool {
}
}
func (obj *Object) HasIcon() bool {
return obj.Icon != nil && obj.Shape.Value != d2target.ShapeImage
}
func (obj *Object) AbsID() string {
if obj.Parent != nil && obj.Parent.ID != "" {
return obj.Parent.AbsID() + "." + obj.ID
@ -1989,7 +1993,7 @@ func (obj *Object) SpacingOpt(labelPadding, iconPadding float64, maxIconSize boo
}
}
if obj.Icon != nil && obj.Shape.Value != d2target.ShapeImage {
if obj.HasIcon() {
var position label.Position
if obj.IconPosition != nil {
position = label.FromString(*obj.IconPosition)

View file

@ -257,6 +257,13 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
}
}
if obj.HasLabel() && obj.HasIcon() && obj.IconPosition != nil {
if !label.FromString(*obj.IconPosition).IsOutside() {
// this gives shapes extra height for their label if they also have an icon
obj.Height += float64(obj.LabelDimensions.Height + label.PADDING)
}
}
margin, _ := obj.SpacingOpt(2*label.PADDING, 0, false)
width := margin.Left + obj.Width + margin.Right
height := margin.Top + obj.Height + margin.Bottom
@ -1050,7 +1057,7 @@ func adjustPadding(obj *d2graph.Object, width, height float64, padding shapePadd
extraRight = labelWidth
}
}
if obj.Icon != nil && obj.Shape.Value != d2target.ShapeImage && obj.IconPosition != nil {
if obj.HasIcon() && obj.IconPosition != nil {
iconSize := d2target.MAX_ICON_SIZE + 2*label.PADDING
switch label.FromString(*obj.IconPosition) {
case label.InsideTopLeft, label.InsideTopCenter, label.InsideTopRight: