本文整理汇总了Golang中github.com/shibukawa/nanovgo.Context.TextBox方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.TextBox方法的具体用法?Golang Context.TextBox怎么用?Golang Context.TextBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shibukawa/nanovgo.Context
的用法示例。
在下文中一共展示了Context.TextBox方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Draw
func (l *Label) Draw(self Widget, ctx *nanovgo.Context) {
l.WidgetImplement.Draw(self, ctx)
ctx.SetFontSize(float32(l.FontSize()))
ctx.SetFontFace(l.Font())
ctx.SetFillColor(l.color)
width := 0
if l.FixedWidth() > 0 {
width = l.FixedWidth()
} else if l.columnWidth > 0 && l.wrap {
width = l.columnWidth
}
if width > 0 {
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignTop)
ctx.TextBox(float32(l.x), float32(l.y), float32(width), l.caption)
} else {
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(float32(l.x), float32(l.y)+float32(l.h)*0.5, l.caption)
}
}
示例2: drawParagraph
//.........这里部分代码省略.........
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)
bounds := ctx.TextBoxBounds(x, y, 150, "Hover your mouse over the text to see calculated caret position.")
// Fade the tooltip out when close to it.
gx = absF((mx - (bounds[0]+bounds[2])*0.5) / (bounds[0] - bounds[2]))
gy = absF((my - (bounds[1]+bounds[3])*0.5) / (bounds[1] - bounds[3]))
a := maxF(gx, gy) - 0.5
a = clampF(a, 0, 1)
ctx.SetGlobalAlpha(a)
ctx.BeginPath()
ctx.SetFillColor(nanovgo.RGBA(220, 220, 220, 255))
ctx.RoundedRect(bounds[0]-2, bounds[1]-2, float32(int(bounds[2]-bounds[0])+4), float32(int(bounds[3]-bounds[1])+4), 3)
px := float32(int((bounds[2] + bounds[0]) / 2))
ctx.MoveTo(px, bounds[1]-10)
ctx.LineTo(px+7, bounds[1]+1)
ctx.LineTo(px-7, bounds[1]+1)
ctx.Fill()
ctx.SetFillColor(nanovgo.RGBA(0, 0, 0, 220))
ctx.TextBox(x, y, 150, "Hover your mouse over the text to see calculated caret position.")
}