Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify col #275

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/assets/examples/customsize/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
Size: 12,
Extrapolate: true,
}),
col.Empty(4),
col.New(4),
)

document, err := m.Generate()
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/examples/margins/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
Size: 12,
Extrapolate: true,
}),
col.Empty(4),
col.New(4),
)

document, err := m.Generate()
Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/code/barcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewBarCol(size int, code string, ps ...props.Barcode) domain.Col {

func NewBarRow(height float64, code string, ps ...props.Barcode) domain.Row {
bar := NewBar(code, ps...)
c := col.New(0).Add(bar)
c := col.New().Add(bar)
return row.New(height).Add(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/code/matrixcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewMatrixCol(size int, code string, ps ...props.Rect) domain.Col {

func NewMatrixRow(height float64, code string, ps ...props.Rect) domain.Row {
matrixCode := NewMatrix(code, ps...)
c := col.New(0).Add(matrixCode)
c := col.New().Add(matrixCode)
return row.New(height).Add(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/code/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewQrCol(size int, code string, ps ...props.Rect) domain.Col {

func NewQrRow(height float64, code string, ps ...props.Rect) domain.Row {
qrCode := NewQr(code, ps...)
c := col.New(0).Add(qrCode)
c := col.New().Add(qrCode)
return row.New(height).Add(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Col interface {
Node
Add(components ...Component) Col
AddInner(rows ...Row) Col
GetSize() (int, bool)
GetSize() int
WithStyle(style *props.Style) Col
Render(provider Provider, cell internal.Cell, createCell bool)
}
Expand Down
22 changes: 10 additions & 12 deletions pkg/v2/grid/col/col.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ type col struct {
style *props.Style
}

func New(size int) domain.Col {
return &col{
size: size,
isMax: size == 0,
func New(size ...int) domain.Col {
if len(size) == 0 {
return &col{isMax: true}
}
}

func Empty(size int) domain.Col {
return &col{
size: size,
isMax: size == 0,
}
return &col{size: size[0]}
}

func (c *col) Add(components ...domain.Component) domain.Col {
Expand All @@ -43,8 +37,12 @@ func (c *col) AddInner(rows ...domain.Row) domain.Col {
return c
}

func (c *col) GetSize() (int, bool) {
return c.size, c.isMax
func (c *col) GetSize() int {
if c.isMax {
return c.config.MaxGridSize
}

return c.size
}

func (c *col) GetStructure() *tree.Node[domain.Structure] {
Expand Down
7 changes: 2 additions & 5 deletions pkg/v2/grid/row/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func New(height float64) domain.Row {

func Empty(height float64) domain.Row {
r := New(height)
r.Add(col.Empty(12))
r.Add(col.New())
return r
}

Expand Down Expand Up @@ -70,13 +70,10 @@ func (r *row) Render(provider domain.Provider, cell internal.Cell) {
}

for _, col := range r.cols {
size, isMax := col.GetSize()
size := col.GetSize()
parentWidth := cell.Width

percent := float64(size) / float64(r.config.MaxGridSize)
if isMax {
percent = 1
}

colDimension := parentWidth * percent
innerCell.Width = colDimension
Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/image/base64image.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewFromBase64Col(size int, path string, extension consts.Extension, ps ...p

func NewFromBase64Row(height float64, path string, extension consts.Extension, ps ...props.Rect) domain.Row {
image := NewFromBase64(path, extension, ps...)
c := col.New(0).Add(image)
c := col.New().Add(image)
return row.New(height).Add(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/image/fileimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewFromFileCol(size int, path string, ps ...props.Rect) domain.Col {

func NewFromFileRow(height float64, path string, ps ...props.Rect) domain.Row {
image := NewFromFile(path, ps...)
c := col.New(0).Add(image)
c := col.New().Add(image)
return row.New(height).Add(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/signature/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewCol(size int, value string, ps ...props.Font) domain.Col {

func NewRow(height float64, value string, ps ...props.Font) domain.Row {
signature := New(value, ps...)
c := col.New(0).Add(signature)
c := col.New().Add(signature)
return row.New(height).Add(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewCol(size int, value string, ps ...props.Text) domain.Col {

func NewRow(height float64, value string, ps ...props.Text) domain.Row {
r := New(value, ps...)
c := col.New(0).Add(r)
c := col.New().Add(r)
return row.New(height).Add(c)
}

Expand Down