goext/wpdf/wpdfRect.go
Mike Schwörer 194ea4ace5
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m16s
v0.0.460
2024-05-20 00:38:04 +02:00

127 lines
3.0 KiB
Go

package wpdf
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
type PDFRectOpt struct {
x *float64
y *float64
lineWidth *float64
drawColor *PDFColor
fillColor *PDFColor
radiusTL *float64
radiusTR *float64
radiusBR *float64
radiusBL *float64
}
func NewPDFRectOpt() *PDFRectOpt {
return &PDFRectOpt{}
}
func (opt *PDFRectOpt) X(v float64) *PDFRectOpt {
opt.x = &v
return opt
}
func (opt *PDFRectOpt) Y(v float64) *PDFRectOpt {
opt.y = &v
return opt
}
func (opt *PDFRectOpt) LineWidth(v float64) *PDFRectOpt {
opt.lineWidth = &v
return opt
}
func (opt *PDFRectOpt) DrawColor(cr, cg, cb int) *PDFRectOpt {
opt.drawColor = langext.Ptr(rgbToColor(cr, cg, cb))
return opt
}
func (opt *PDFRectOpt) DrawColorHex(c uint32) *PDFRectOpt {
opt.drawColor = langext.Ptr(hexToColor(c))
return opt
}
func (opt *PDFRectOpt) FillColor(cr, cg, cb int) *PDFRectOpt {
opt.fillColor = langext.Ptr(rgbToColor(cr, cg, cb))
return opt
}
func (opt *PDFRectOpt) FillColorHex(c uint32) *PDFRectOpt {
opt.fillColor = langext.Ptr(hexToColor(c))
return opt
}
func (opt *PDFRectOpt) Rounded(radius float64) *PDFRectOpt {
opt.radiusTL = &radius
opt.radiusTR = &radius
opt.radiusBR = &radius
opt.radiusBL = &radius
return opt
}
func (opt *PDFRectOpt) RadiusTL(radius float64) *PDFRectOpt {
opt.radiusTL = &radius
return opt
}
func (opt *PDFRectOpt) RadiusTR(radius float64) *PDFRectOpt {
opt.radiusTR = &radius
return opt
}
func (opt *PDFRectOpt) RadiusBL(radius float64) *PDFRectOpt {
opt.radiusBL = &radius
return opt
}
func (opt *PDFRectOpt) RadiusBR(radius float64) *PDFRectOpt {
opt.radiusBR = &radius
return opt
}
func (b *WPDFBuilder) Rect(w float64, h float64, styleStr PDFRectStyle, opts ...*PDFRectOpt) {
x := b.GetX()
y := b.GetY()
var lineWidth *float64
var drawColor *PDFColor
var fillColor *PDFColor
radiusTL := float64(0)
radiusTR := float64(0)
radiusBR := float64(0)
radiusBL := float64(0)
for _, opt := range opts {
x = langext.Coalesce(opt.x, x)
y = langext.Coalesce(opt.y, y)
lineWidth = langext.CoalesceOpt(opt.lineWidth, lineWidth)
drawColor = langext.CoalesceOpt(opt.drawColor, drawColor)
fillColor = langext.CoalesceOpt(opt.fillColor, fillColor)
radiusTL = langext.Coalesce(opt.radiusTL, radiusTL)
radiusTR = langext.Coalesce(opt.radiusTR, radiusTR)
radiusBR = langext.Coalesce(opt.radiusBR, radiusBR)
radiusBL = langext.Coalesce(opt.radiusBL, radiusBL)
}
if lineWidth != nil {
old := b.GetLineWidth()
b.SetLineWidth(*lineWidth)
defer func() { b.SetLineWidth(old) }()
}
if drawColor != nil {
oldR, oldG, oldB := b.GetDrawColor()
b.SetDrawColor(drawColor.R, drawColor.G, drawColor.B)
defer func() { b.SetDrawColor(oldR, oldG, oldB) }()
}
if fillColor != nil {
oldR, oldG, oldB := b.GetFillColor()
b.SetFillColor(fillColor.R, fillColor.G, fillColor.B)
defer func() { b.SetFillColor(oldR, oldG, oldB) }()
}
b.b.RoundedRectExt(x, y, w, h, radiusTL, radiusTR, radiusBR, radiusBL, string(styleStr))
}