mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +08:00
Improve invoice component style
This commit is contained in:
parent
564877a23b
commit
389083bd9f
@ -25,8 +25,8 @@ type InvoiceCellProps struct {
|
|||||||
BackgroundColor Color
|
BackgroundColor Color
|
||||||
|
|
||||||
BorderColor Color
|
BorderColor Color
|
||||||
BorderWidth int
|
BorderWidth float64
|
||||||
BorderStyle int
|
BorderSides []CellBorderSide
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvoiceCell.
|
// InvoiceCell.
|
||||||
@ -118,6 +118,8 @@ func newInvoice(defaultStyle, headingStyle TextStyle) *Invoice {
|
|||||||
i.colProps.BorderColor = lightGrey
|
i.colProps.BorderColor = lightGrey
|
||||||
|
|
||||||
i.itemProps = i.NewCellProps()
|
i.itemProps = i.NewCellProps()
|
||||||
|
i.itemProps.BorderColor = lightGrey
|
||||||
|
i.itemProps.BorderSides = []CellBorderSide{CellBorderSideBottom}
|
||||||
i.itemProps.Alignment = CellHorizontalAlignmentRight
|
i.itemProps.Alignment = CellHorizontalAlignmentRight
|
||||||
|
|
||||||
// Invoice totals default properties.
|
// Invoice totals default properties.
|
||||||
@ -341,7 +343,7 @@ func (i *Invoice) NewCellProps() InvoiceCellProps {
|
|||||||
BackgroundColor: white,
|
BackgroundColor: white,
|
||||||
BorderColor: white,
|
BorderColor: white,
|
||||||
BorderWidth: 1,
|
BorderWidth: 1,
|
||||||
BorderStyle: int(CellBorderSideAll),
|
BorderSides: []CellBorderSide{CellBorderSideAll},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +369,14 @@ func (i *Invoice) newColumn(description string, alignment CellHorizontalAlignmen
|
|||||||
return col
|
return col
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Invoice) setCellBorder(cell *TableCell, invoiceCell *InvoiceCell) {
|
||||||
|
for _, side := range invoiceCell.BorderSides {
|
||||||
|
cell.SetBorder(side, CellBorderStyleSingle, invoiceCell.BorderWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.SetBorderColor(invoiceCell.BorderColor)
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Invoice) drawAddress(title, name string, addr *InvoiceAddress) []*StyledParagraph {
|
func (i *Invoice) drawAddress(title, name string, addr *InvoiceAddress) []*StyledParagraph {
|
||||||
var paragraphs []*StyledParagraph
|
var paragraphs []*StyledParagraph
|
||||||
|
|
||||||
@ -462,23 +472,21 @@ func (i *Invoice) drawInformation() *Table {
|
|||||||
// Add description.
|
// Add description.
|
||||||
cell := table.NewCell()
|
cell := table.NewCell()
|
||||||
cell.SetBackgroundColor(description.BackgroundColor)
|
cell.SetBackgroundColor(description.BackgroundColor)
|
||||||
cell.SetBorder(CellBorderSideAll, CellBorderStyleSingle, 1)
|
i.setCellBorder(cell, description)
|
||||||
cell.SetBorderColor(description.BorderColor)
|
|
||||||
|
|
||||||
p := newStyledParagraph(description.TextStyle)
|
p := newStyledParagraph(description.TextStyle)
|
||||||
p.Append(description.Value)
|
p.Append(description.Value)
|
||||||
p.SetMargins(0, 0, 2, 0)
|
p.SetMargins(0, 0, 2, 1)
|
||||||
cell.SetContent(p)
|
cell.SetContent(p)
|
||||||
|
|
||||||
// Add value.
|
// Add value.
|
||||||
cell = table.NewCell()
|
cell = table.NewCell()
|
||||||
cell.SetBackgroundColor(value.BackgroundColor)
|
cell.SetBackgroundColor(value.BackgroundColor)
|
||||||
cell.SetBorder(CellBorderSideAll, CellBorderStyleSingle, 1)
|
i.setCellBorder(cell, value)
|
||||||
cell.SetBorderColor(value.BorderColor)
|
|
||||||
|
|
||||||
p = newStyledParagraph(value.TextStyle)
|
p = newStyledParagraph(value.TextStyle)
|
||||||
p.Append(value.Value)
|
p.Append(value.Value)
|
||||||
p.SetMargins(0, 0, 2, 0)
|
p.SetMargins(0, 0, 2, 1)
|
||||||
cell.SetContent(p)
|
cell.SetContent(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,11 +510,10 @@ func (i *Invoice) drawTotals() *Table {
|
|||||||
cell := table.NewCell()
|
cell := table.NewCell()
|
||||||
cell.SetBackgroundColor(description.BackgroundColor)
|
cell.SetBackgroundColor(description.BackgroundColor)
|
||||||
cell.SetHorizontalAlignment(value.Alignment)
|
cell.SetHorizontalAlignment(value.Alignment)
|
||||||
cell.SetBorder(CellBorderSideAll, CellBorderStyleSingle, 1)
|
i.setCellBorder(cell, description)
|
||||||
cell.SetBorderColor(value.BorderColor)
|
|
||||||
|
|
||||||
p := newStyledParagraph(description.TextStyle)
|
p := newStyledParagraph(description.TextStyle)
|
||||||
p.SetMargins(0, 0, 1, 1)
|
p.SetMargins(0, 0, 2, 1)
|
||||||
p.Append(description.Value)
|
p.Append(description.Value)
|
||||||
cell.SetContent(p)
|
cell.SetContent(p)
|
||||||
|
|
||||||
@ -514,11 +521,10 @@ func (i *Invoice) drawTotals() *Table {
|
|||||||
cell = table.NewCell()
|
cell = table.NewCell()
|
||||||
cell.SetBackgroundColor(value.BackgroundColor)
|
cell.SetBackgroundColor(value.BackgroundColor)
|
||||||
cell.SetHorizontalAlignment(value.Alignment)
|
cell.SetHorizontalAlignment(value.Alignment)
|
||||||
cell.SetBorder(CellBorderSideAll, CellBorderStyleSingle, 1)
|
i.setCellBorder(cell, description)
|
||||||
cell.SetBorderColor(value.BorderColor)
|
|
||||||
|
|
||||||
p = newStyledParagraph(value.TextStyle)
|
p = newStyledParagraph(value.TextStyle)
|
||||||
p.SetMargins(0, 0, 1, 1)
|
p.SetMargins(0, 0, 2, 1)
|
||||||
p.Append(value.Value)
|
p.Append(value.Value)
|
||||||
cell.SetContent(p)
|
cell.SetContent(p)
|
||||||
}
|
}
|
||||||
@ -600,8 +606,7 @@ func (i *Invoice) generateLineBlocks(ctx DrawContext) ([]*Block, DrawContext, er
|
|||||||
cell := table.NewCell()
|
cell := table.NewCell()
|
||||||
cell.SetHorizontalAlignment(col.Alignment)
|
cell.SetHorizontalAlignment(col.Alignment)
|
||||||
cell.SetBackgroundColor(col.BackgroundColor)
|
cell.SetBackgroundColor(col.BackgroundColor)
|
||||||
cell.SetBorder(CellBorderSideAll, CellBorderStyleSingle, 1)
|
i.setCellBorder(cell, col)
|
||||||
cell.SetBorderColor(col.BorderColor)
|
|
||||||
cell.SetContent(paragraph)
|
cell.SetContent(paragraph)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,14 +614,13 @@ func (i *Invoice) generateLineBlocks(ctx DrawContext) ([]*Block, DrawContext, er
|
|||||||
for _, line := range i.lines {
|
for _, line := range i.lines {
|
||||||
for _, itemCell := range line {
|
for _, itemCell := range line {
|
||||||
paragraph := newStyledParagraph(itemCell.TextStyle)
|
paragraph := newStyledParagraph(itemCell.TextStyle)
|
||||||
paragraph.SetMargins(0, 0, 1, 0)
|
paragraph.SetMargins(0, 0, 3, 2)
|
||||||
paragraph.Append(itemCell.Value)
|
paragraph.Append(itemCell.Value)
|
||||||
|
|
||||||
cell := table.NewCell()
|
cell := table.NewCell()
|
||||||
cell.SetHorizontalAlignment(itemCell.Alignment)
|
cell.SetHorizontalAlignment(itemCell.Alignment)
|
||||||
cell.SetBackgroundColor(itemCell.BackgroundColor)
|
cell.SetBackgroundColor(itemCell.BackgroundColor)
|
||||||
cell.SetBorder(CellBorderSideAll, CellBorderStyleSingle, 1)
|
i.setCellBorder(cell, itemCell)
|
||||||
cell.SetBorderColor(itemCell.BorderColor)
|
|
||||||
cell.SetContent(paragraph)
|
cell.SetContent(paragraph)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -626,7 +630,7 @@ func (i *Invoice) generateLineBlocks(ctx DrawContext) ([]*Block, DrawContext, er
|
|||||||
|
|
||||||
func (i *Invoice) generateTotalBlocks(ctx DrawContext) ([]*Block, DrawContext, error) {
|
func (i *Invoice) generateTotalBlocks(ctx DrawContext) ([]*Block, DrawContext, error) {
|
||||||
table := newTable(2)
|
table := newTable(2)
|
||||||
table.SetMargins(0, 0, 5, 35)
|
table.SetMargins(0, 0, 5, 40)
|
||||||
table.SkipCells(1)
|
table.SkipCells(1)
|
||||||
|
|
||||||
totalsTable := i.drawTotals()
|
totalsTable := i.drawTotals()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user