本文整理汇总了Golang中github.com/shibukawa/nanovgo.Context.TextRune方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.TextRune方法的具体用法?Golang Context.TextRune怎么用?Golang Context.TextRune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shibukawa/nanovgo.Context
的用法示例。
在下文中一共展示了Context.TextRune方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Draw
//.........这里部分代码省略.........
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 {
t.textOffset -= nextCX - (clipX + clipWidth) + 1.0
}
if prevCX < clipX {
t.textOffset += clipX - prevCX + 1.0
}
drawPosX = oldDrawPosX + t.textOffset
// draw text with offset
ctx.TextRune(drawPosX, drawPosY, text)
_, bounds = ctx.TextBounds(drawPosX, drawPosY, textString)
// recompute cursor position
glyphs = ctx.TextGlyphPositionsRune(drawPosX, drawPosY, text)
var caretX float32 = -1
if len(t.preeditText) != 0 {
// draw preedit text
caretX = t.textIndex2Position(t.cursorPos+len(t.preeditText), bounds[2], glyphs)
offsetIndex := t.cursorPos
offsetX := t.textIndex2Position(t.cursorPos, bounds[2], glyphs)
ctx.SetStrokeColor(nanovgo.MONO(255, 160))
ctx.SetFillColor(nanovgo.MONO(255, 80))
ctx.SetStrokeWidth(2.0)
for i, blockLength := range t.preeditBlocks {
nextOffsetIndex := offsetIndex + blockLength
nextOffsetX := t.textIndex2Position(nextOffsetIndex, bounds[2], glyphs)
if i != t.preeditFocusedBlock {
ctx.BeginPath()
ctx.MoveTo(offsetX+2, drawPosY+lineH*0.5-1)
ctx.LineTo(nextOffsetX-2, drawPosY+lineH*0.5-1)
ctx.Stroke()
} else {
ctx.BeginPath()
ctx.Rect(offsetX, drawPosY-lineH*0.5, nextOffsetX-offsetX, lineH)
ctx.Fill()
}
offsetIndex = nextOffsetIndex
offsetX = nextOffsetX
}
screen := t.FindWindow().Parent().(*Screen)
示例2: drawParagraph
func drawParagraph(ctx *nanovgo.Context, x, y, width, height, mx, my float32) {
text := "This is longer chunk of text.\n \n Would have used lorem ipsum but she was busy jumping over the lazy dog with the fox and all the men who came to the aid of the party."
ctx.Save()
defer ctx.Restore()
ctx.SetFontSize(18.0)
ctx.SetFontFace("sans")
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignTop)
_, _, lineh := ctx.TextMetrics()
// The text break API can be used to fill a large buffer of rows,
// or to iterate over the text just few lines (or just one) at a time.
// The "next" variable of the last returned item tells where to continue.
runes := []rune(text)
var gx, gy float32
var gutter int
lnum := 0
for _, row := range ctx.TextBreakLinesRune(runes, width) {
hit := mx > x && mx < (x+width) && my >= y && my < (y+lineh)
ctx.BeginPath()
var alpha uint8
if hit {
alpha = 64
} else {
alpha = 16
}
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, alpha))
ctx.Rect(x, y, row.Width, lineh)
ctx.Fill()
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 255))
ctx.TextRune(x, y, runes[row.StartIndex:row.EndIndex])
if hit {
var caretX float32
if mx < x+row.Width/2 {
caretX = x
} else {
caretX = x + row.Width
}
px := x
lineRune := runes[row.StartIndex:row.EndIndex]
glyphs := ctx.TextGlyphPositionsRune(x, y, lineRune)
for j, glyph := range glyphs {
x0 := glyph.X
var x1 float32
if j+1 < len(glyphs) {
x1 = glyphs[j+1].X
} else {
x1 = x + row.Width
}
gx = x0*0.3 + x1*0.7
if mx >= px && mx < gx {
caretX = glyph.X
}
px = gx
}
ctx.BeginPath()
ctx.SetFillColor(nanovgo.RGBA(255, 192, 0, 255))
ctx.Rect(caretX, y, 1, lineh)
ctx.Fill()
gutter = lnum + 1
gx = x - 10
gy = y + lineh/2
}
lnum++
y += lineh
}
if gutter > 0 {
txt := strconv.Itoa(gutter)
ctx.SetFontSize(13.0)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignMiddle)
_, bounds := ctx.TextBounds(gx, gy, txt)
ctx.BeginPath()
ctx.SetFillColor(nanovgo.RGBA(255, 192, 0, 255))
ctx.RoundedRect(
float32(int(bounds[0]-4)),
float32(int(bounds[1]-2)),
float32(int(bounds[2]-bounds[0])+8),
float32(int(bounds[3]-bounds[1])+4),
float32(int(bounds[3]-bounds[1])+4)/2.0-1.0)
ctx.Fill()
ctx.SetFillColor(nanovgo.RGBA(32, 32, 32, 255))
ctx.Text(gx, gy, txt)
}
y += 20.0
ctx.SetFontSize(13.0)
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignTop)
ctx.SetTextLineHeight(1.2)
//.........这里部分代码省略.........
示例3: Draw
//.........这里部分代码省略.........
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:
iconPosX = bx + 8.0
case ButtonIconRight:
iconPosX = bx + bw - iw - 8
}
if b.icon > 0 {
ctx.TextRune(iconPosX, iconPosY, []rune{rune(b.icon)})
} else {
var eOff float32 = 0.25
if b.enabled {
eOff = 0.5
}
imgPaint := nanovgo.ImagePattern(iconPosX, iconPosY-ih*0.5, iw, ih, 0, b.imageIcon, eOff)
ctx.SetFillPaint(imgPaint)
ctx.Fill()
}
}
ctx.SetFontSize(fontSize)
ctx.SetFontFace(b.theme.FontBold)
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.SetFillColor(b.theme.TextColorShadow)
ctx.Text(textPosX, textPosY, caption)
ctx.SetFillColor(textColor)
ctx.Text(textPosX, textPosY+1.0, caption)
}