fix class dimensions

This commit is contained in:
Gavin Nishizawa 2023-01-23 17:19:38 -08:00
parent 0311a3f7d7
commit 6f26167beb
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
3 changed files with 8 additions and 7 deletions

View file

@ -750,7 +750,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
return nil, fmt.Errorf("dimensions for class field %#v not found", f.Text())
}
lineWidth := fdims.Width
if maxWidth < lineWidth {
if lineWidth > maxWidth {
maxWidth = lineWidth
}
}
@ -760,11 +760,11 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
return nil, fmt.Errorf("dimensions for class method %#v not found", m.Text())
}
lineWidth := mdims.Width
if maxWidth < lineWidth {
if lineWidth > maxWidth {
maxWidth = lineWidth
}
}
dims.Width = maxWidth
dims.Width = d2target.PrefixPadding + d2target.PrefixWidth + maxWidth + d2target.CenterPadding + d2target.TypePadding
// All rows should be the same height
var anyRowText *d2target.MText
@ -774,8 +774,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
anyRowText = obj.Class.Methods[0].Text()
}
if anyRowText != nil {
// 10px of padding top and bottom so text doesn't look squished
rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + 20
rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + d2target.VerticalPadding
dims.Height = rowHeight * (len(obj.Class.Fields) + len(obj.Class.Methods) + 2)
} else {
dims.Height = go2.Max(12, labelDims.Height)

View file

@ -9,6 +9,9 @@ import (
const (
PrefixPadding = 10
PrefixWidth = 20
CenterPadding = 50
// 10px of padding top and bottom so text doesn't look squished
VerticalPadding = 20
)
type Class struct {

View file

@ -21,6 +21,5 @@ func NewClass(box *geo.Box) Shape {
}
func (s shapeClass) GetDefaultPadding() (paddingX, paddingY float64) {
// TODO fix class row width measurements (see SQL table)
return 100, 0
return 0, 0
}