本文整理汇总了Golang中github.com/shibukawa/nanovgo.Context.ImageSize方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.ImageSize方法的具体用法?Golang Context.ImageSize怎么用?Golang Context.ImageSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shibukawa/nanovgo.Context
的用法示例。
在下文中一共展示了Context.ImageSize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PreferredSize
func (i *ImageView) PreferredSize(self Widget, ctx *nanovgo.Context) (int, int) {
if i.image == 0 {
return 0, 0
}
w, h, _ := ctx.ImageSize(i.image)
return w, h
}
示例2: Draw
func (i *ImagePanel) Draw(self Widget, ctx *nanovgo.Context) {
cols, _ := i.gridSize()
x := float32(i.x)
y := float32(i.y)
thumbSize := float32(i.thumbSize)
for j, image := range i.images {
pX := x + float32(i.margin+(j%cols)*(i.thumbSize+i.spacing))
pY := y + float32(i.margin+(j/cols)*(i.thumbSize+i.spacing))
imgW, imgH, _ := ctx.ImageSize(image.ImageID)
var iw, ih, ix, iy float32
if imgW < imgH {
iw = thumbSize
ih = iw * float32(imgH) / float32(imgW)
ix = 0
iy = -(ih - thumbSize) * 0.5
} else {
ih = thumbSize
iw = ih * float32(imgH) / float32(imgW)
iy = 0
ix = -(iw - thumbSize) * 0.5
}
imgPaint := nanovgo.ImagePattern(pX+ix, pY+iy, iw, ih, 0, image.ImageID, toF(i.mouseIndex == j, 1.0, 0.7))
ctx.BeginPath()
ctx.RoundedRect(pX, pY, thumbSize, thumbSize, 5)
ctx.SetFillPaint(imgPaint)
ctx.Fill()
shadowPaint := nanovgo.BoxGradient(pX-1, pY, thumbSize+2, thumbSize+2, 5, 3, nanovgo.MONO(0, 128), nanovgo.MONO(0, 0))
ctx.BeginPath()
ctx.Rect(pX-5, pY-5, thumbSize+10, thumbSize+10)
ctx.RoundedRect(pX, pY, thumbSize, thumbSize, 6)
ctx.PathWinding(nanovgo.Hole)
ctx.SetFillPaint(shadowPaint)
ctx.Fill()
ctx.BeginPath()
ctx.RoundedRect(pX+0.5, pY+0.5, thumbSize-1, thumbSize-1, 4-0.5)
ctx.SetStrokeWidth(1.0)
ctx.SetStrokeColor(nanovgo.MONO(255, 80))
ctx.Stroke()
}
}
示例3: PreferredSize
func (t *TextBox) PreferredSize(self Widget, ctx *nanovgo.Context) (int, int) {
sizeH := float32(t.FontSize()) * 1.4
var unitWidth, textWidth float32
ctx.SetFontSize(float32(t.FontSize()))
if t.unitImage > 0 {
w, h, _ := ctx.ImageSize(t.unitImage)
unitHeight := sizeH * 0.4
unitWidth = float32(w) * unitHeight / float32(h)
} else if t.units != "" {
unitWidth, _ = ctx.TextBounds(0, 0, t.units)
}
textWidth, _ = ctx.TextBounds(0, 0, string(t.editingText()))
sizeW := sizeH + textWidth + unitWidth
return int(sizeW), int(sizeH)
}
示例4: Draw
func (i *ImageView) Draw(self Widget, ctx *nanovgo.Context) {
if i.image == 0 {
return
}
x := float32(i.x)
y := float32(i.y)
ow := float32(i.w)
oh := float32(i.h)
var w, h float32
{
iw, ih, _ := ctx.ImageSize(i.image)
w = float32(iw)
h = float32(ih)
}
if i.policy == ImageSizePolicyFixed {
if ow < w {
h = float32(int(h * ow / w))
w = ow
}
if oh < h {
w = float32(int(w * oh / h))
h = oh
}
} else { // mPolicy == Expand
// expand to width
h = float32(int(h * ow / w))
w = ow
// shrink to height, if necessary
if oh < h {
w = float32(int(w * oh / h))
h = oh
}
}
imgPaint := nanovgo.ImagePattern(x, y, w, h, 0, i.image, 1.0)
ctx.BeginPath()
ctx.Rect(x, y, w, h)
ctx.SetFillPaint(imgPaint)
ctx.Fill()
}
示例5: PreferredSize
func (b *Button) PreferredSize(self Widget, ctx *nanovgo.Context) (int, int) {
fontSize := float32(b.FontSize())
ctx.SetFontSize(fontSize)
ctx.SetFontFace(b.theme.FontBold)
tw, _ := ctx.TextBounds(0, 0, b.caption)
var iw float32
ih := fontSize
if b.icon > 0 {
ih *= 1.5 / 2
ctx.SetFontFace(b.theme.FontIcons)
ctx.SetFontSize(ih)
iw, _ = ctx.TextBounds(0, 0, string([]rune{rune(b.icon)}))
iw += float32(b.y) * 0.15
} else if b.imageIcon > 0 {
ih *= 0.9
w, h, _ := ctx.ImageSize(b.imageIcon)
iw = float32(w) * ih / float32(h)
}
return int(tw + iw + 20), int(fontSize) + 10
}
示例6: drawThumbnails
func drawThumbnails(ctx *nanovgo.Context, x, y, w, h float32, images []int, t float32) {
var cornerRadius float32 = 3.0
var thumb float32 = 60.0
var arry float32 = 30.5
stackh := float32(len(images)/2)*(thumb+10) + 10
u := (1 + cosF(t*0.5)) * 0.5
u2 := (1 - cosF(t*0.2)) * 0.5
ctx.Save()
defer ctx.Restore()
// Drop shadow
shadowPaint := nanovgo.BoxGradient(x, y+4, w, h, cornerRadius*2, 20, nanovgo.RGBA(0, 0, 0, 128), nanovgo.RGBA(0, 0, 0, 0))
ctx.BeginPath()
ctx.Rect(x-10, y-10, w+20, h+30)
ctx.RoundedRect(x, y, w, h, cornerRadius)
ctx.PathWinding(nanovgo.Hole)
ctx.SetFillPaint(shadowPaint)
ctx.Fill()
// Window
ctx.BeginPath()
ctx.RoundedRect(x, y, w, h, cornerRadius)
ctx.MoveTo(x-10, y+arry)
ctx.LineTo(x+1, y+arry-11)
ctx.LineTo(x+1, y+arry+11)
ctx.SetFillColor(nanovgo.RGBA(200, 200, 200, 255))
ctx.Fill()
ctx.Block(func() {
ctx.Scissor(x, y, w, h)
ctx.Translate(0, -(stackh-h)*u)
dv := 1.0 / float32(len(images)-1)
for i, imageID := range images {
tx := x + 10.0
ty := y + 10.0
tx += float32(i%2) * (thumb + 10.0)
ty += float32(i/2) * (thumb + 10.0)
imgW, imgH, _ := ctx.ImageSize(imageID)
var iw, ih, ix, iy float32
if imgW < imgH {
iw = thumb
ih = iw * float32(imgH) / float32(imgW)
ix = 0
iy = -(ih - thumb) * 0.5
} else {
ih = thumb
iw = ih * float32(imgW) / float32(imgH)
ix = -(iw - thumb) * 0.5
iy = 0
}
v := float32(i) * dv
a := clampF((u2-v)/dv, 0, 1)
if a < 1.0 {
drawSpinner(ctx, tx+thumb/2, ty+thumb/2, thumb*0.25, t)
}
imgPaint := nanovgo.ImagePattern(tx+ix, ty+iy, iw, ih, 0.0/180.0*nanovgo.PI, imageID, a)
ctx.BeginPath()
ctx.RoundedRect(tx, ty, thumb, thumb, 5)
ctx.SetFillPaint(imgPaint)
ctx.Fill()
shadowPaint := nanovgo.BoxGradient(tx-1, ty, thumb+2, thumb+2, 5, 3, nanovgo.RGBA(0, 0, 0, 128), nanovgo.RGBA(0, 0, 0, 0))
ctx.BeginPath()
ctx.Rect(tx-5, ty-5, thumb+10, thumb+10)
ctx.RoundedRect(tx, ty, thumb, thumb, 6)
ctx.PathWinding(nanovgo.Hole)
ctx.SetFillPaint(shadowPaint)
ctx.Fill()
ctx.BeginPath()
ctx.RoundedRect(tx+0.5, ty+0.5, thumb-1, thumb-1, 4-0.5)
ctx.SetStrokeWidth(1.0)
ctx.SetStrokeColor(nanovgo.RGBA(255, 255, 255, 192))
ctx.Stroke()
}
})
// Hide fades
fadePaint := nanovgo.LinearGradient(x, y, x, y+6, nanovgo.RGBA(200, 200, 200, 255), nanovgo.RGBA(200, 200, 200, 0))
ctx.BeginPath()
ctx.Rect(x+4, y, w-8, 6)
ctx.SetFillPaint(fadePaint)
ctx.Fill()
fadePaint = nanovgo.LinearGradient(x, y+h, x, y+h-6, nanovgo.RGBA(200, 200, 200, 255), nanovgo.RGBA(200, 200, 200, 0))
ctx.BeginPath()
ctx.Rect(x+4, y+h-6, w-8, 6)
ctx.SetFillPaint(fadePaint)
ctx.Fill()
// Scroll bar
shadowPaint = nanovgo.BoxGradient(x+w-12+1, y+4+1, 8, h-8, 3, 4, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 92))
ctx.BeginPath()
//.........这里部分代码省略.........
示例7: Draw
func (t *TextBox) Draw(self Widget, ctx *nanovgo.Context) {
t.WidgetImplement.Draw(self, ctx)
x := float32(t.x)
y := float32(t.y)
w := float32(t.w)
h := float32(t.h)
bg := nanovgo.BoxGradient(x+1, y+2, w-2, h-2, 3, 4, nanovgo.MONO(255, 32), nanovgo.MONO(32, 32))
fg1 := nanovgo.BoxGradient(x+1, y+2, w-2, h-2, 3, 4, nanovgo.MONO(150, 32), nanovgo.MONO(32, 32))
fg2 := nanovgo.BoxGradient(x+1, y+2, w-2, h-2, 3, 4, nanovgo.RGBA(255, 0, 0, 100), nanovgo.RGBA(255, 0, 0, 50))
ctx.BeginPath()
ctx.RoundedRect(x+1, y+2, w-2, h-2, 3)
if t.editable && t.Focused() {
if t.validFormat {
ctx.SetFillPaint(fg1)
} else {
ctx.SetFillPaint(fg2)
}
} else {
ctx.SetFillPaint(bg)
}
ctx.Fill()
ctx.BeginPath()
ctx.RoundedRect(x+0.5, y+0.5, w-1, h-1, 2.5)
ctx.SetStrokeColor(nanovgo.MONO(0, 48))
ctx.Stroke()
ctx.SetFontSize(float32(t.FontSize()))
ctx.SetFontFace(t.Font())
drawPosX := x
drawPosY := y + h*0.5 + 1
xSpacing := h * 0.3
var unitWidth float32
if t.unitImage > 0 {
iw, ih, _ := ctx.ImageSize(t.unitImage)
unitHeight := float32(ih) * 0.4
unitWidth = float32(iw) * unitHeight / float32(h)
imgPaint := nanovgo.ImagePattern(x+w-xSpacing-unitWidth, drawPosY-unitHeight*0.5,
unitWidth, unitHeight, 0, t.unitImage, toF(t.enabled, 0.7, 0.35))
ctx.BeginPath()
ctx.Rect(x+w-xSpacing-unitWidth, drawPosY-unitHeight*0.5, unitWidth, unitHeight)
ctx.SetFillPaint(imgPaint)
ctx.Fill()
unitWidth += 2
} else if t.units != "" {
unitWidth, _ = ctx.TextBounds(0, 0, t.units)
ctx.SetFillColor(nanovgo.MONO(255, toB(t.enabled, 64, 32)))
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignMiddle)
ctx.Text(x+w-xSpacing, drawPosY, t.units)
}
switch t.alignment {
case TextLeft:
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
drawPosX += xSpacing
case TextRight:
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignMiddle)
drawPosX += w - unitWidth - xSpacing
case TextCenter:
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
drawPosX += w * 0.5
}
if t.enabled {
ctx.SetFillColor(t.theme.TextColor)
} else {
ctx.SetFillColor(t.theme.DisabledTextColor)
}
// clip visible text area
clipX := x + xSpacing - 1
clipY := y + 1.0
clipWidth := w - unitWidth - 2.0*xSpacing + 2.0
clipHeight := h - 3.0
ctx.Scissor(clipX, clipY, clipWidth, clipHeight)
oldDrawPosX := drawPosX
drawPosX += t.textOffset
if t.committed {
ctx.Text(drawPosX, drawPosY, t.value)
} else {
text := t.editingText()
textString := string(text)
_, bounds := ctx.TextBounds(drawPosX, drawPosY, textString)
lineH := bounds[3] - bounds[1]
// find cursor positions
glyphs := ctx.TextGlyphPositionsRune(drawPosX, drawPosY, text)
t.updateCursor(ctx, bounds[2], glyphs)
// compute text offset
prevCPos := toI(t.cursorPos > 0, t.cursorPos-1, 0)
nextCPos := toI(t.cursorPos < len(glyphs), t.cursorPos+1, len(glyphs))
prevCX := t.textIndex2Position(prevCPos, bounds[2], glyphs)
nextCX := t.textIndex2Position(nextCPos, bounds[2], glyphs)
if nextCX > clipX+clipWidth {
//.........这里部分代码省略.........
示例8: Draw
func (b *Button) Draw(self Widget, ctx *nanovgo.Context) {
b.WidgetImplement.Draw(self, ctx)
bx := float32(b.x)
by := float32(b.y)
bw := float32(b.w)
bh := float32(b.h)
var gradTop nanovgo.Color
var gradBot nanovgo.Color
if b.pushed {
gradTop = b.theme.ButtonGradientTopPushed
gradBot = b.theme.ButtonGradientBotPushed
} else if b.mouseFocus && b.enabled {
gradTop = b.theme.ButtonGradientTopFocused
gradBot = b.theme.ButtonGradientBotFocused
} else {
gradTop = b.theme.ButtonGradientTopUnfocused
gradBot = b.theme.ButtonGradientBotUnfocused
}
ctx.BeginPath()
ctx.RoundedRect(bx+1.0, by+1.0, bw-2.0, bh-2.0, float32(b.theme.ButtonCornerRadius-1))
if b.backgroundColor.A != 0.0 {
bgColor := b.backgroundColor
bgColor.A = 1.0
ctx.SetFillColor(bgColor)
ctx.Fill()
if b.pushed {
gradTop.A = 0.8
gradBot.A = 0.8
} else {
a := 1 - b.backgroundColor.A
if !b.enabled {
a = a*0.5 + 0.5
}
gradTop.A = a
gradBot.A = a
}
}
bg := nanovgo.LinearGradient(bx, by, bx, by+bh, gradTop, gradBot)
ctx.SetFillPaint(bg)
ctx.Fill()
ctx.BeginPath()
var pOff float32 = 0.0
if b.pushed {
pOff = 1.0
}
ctx.RoundedRect(bx+0.5, by+1.5-pOff, bw-1.0, bh-2+pOff, float32(b.theme.ButtonCornerRadius))
ctx.SetStrokeColor(b.theme.BorderLight)
ctx.Stroke()
ctx.BeginPath()
ctx.RoundedRect(bx+0.5, by+0.5, bw-1.0, bh-2, float32(b.theme.ButtonCornerRadius))
ctx.SetStrokeColor(b.theme.BorderDark)
ctx.Stroke()
fontSize := float32(b.FontSize())
ctx.SetFontSize(fontSize)
ctx.SetFontFace(b.theme.FontBold)
caption := b.caption
tw, _ := ctx.TextBounds(0, 0, caption)
centerX := bx + bw*0.5
centerY := by + bh*0.5
textPosX := centerX - tw*0.5
textPosY := centerY - 1.0
textColor := b.TextColor()
if b.icon > 0 || b.imageIcon > 0 {
var iw, ih float32
if b.icon > 0 {
ih = fontSize * 1.5 / 2
ctx.SetFontSize(ih)
ctx.SetFontFace(b.theme.FontIcons)
iw, _ = ctx.TextBounds(0, 0, string([]rune{rune(b.icon)}))
} else if b.imageIcon > 0 {
ih = fontSize * 0.9
w, h, _ := ctx.ImageSize(b.imageIcon)
iw = float32(w) * ih / float32(h)
}
if b.caption != "" {
iw += float32(b.h) * 0.15
}
ctx.SetFillColor(textColor)
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
iconPosX := centerX
iconPosY := centerY - 1
switch b.iconPosition {
case ButtonIconLeftCentered:
iconPosX -= (tw + iw) * 0.5
textPosX += iw * 0.5
case ButtonIconRightCentered:
iconPosX -= iw * 0.5
textPosX += tw * 0.5
case ButtonIconLeft:
//.........这里部分代码省略.........