本文整理汇总了Golang中github.com/shibukawa/nanovgo.Context.SetFontFace方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.SetFontFace方法的具体用法?Golang Context.SetFontFace怎么用?Golang Context.SetFontFace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shibukawa/nanovgo.Context
的用法示例。
在下文中一共展示了Context.SetFontFace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawDropDown
func drawDropDown(ctx *nanovgo.Context, text string, x, y, w, h float32) {
var cornerRadius float32 = 4.0
bg := nanovgo.LinearGradient(x, y, x, y+h, nanovgo.RGBA(255, 255, 255, 16), nanovgo.RGBA(0, 0, 0, 16))
ctx.BeginPath()
ctx.RoundedRect(x+1, y+1, w-2, h-2, cornerRadius-1)
ctx.SetFillPaint(bg)
ctx.Fill()
ctx.BeginPath()
ctx.RoundedRect(x+0.5, y+0.5, w-1, h-1, cornerRadius-0.5)
ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 48))
ctx.Stroke()
ctx.SetFontSize(20.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 160))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x+h*0.3, y+h*0.5, text)
ctx.SetFontSize(h * 1.3)
ctx.SetFontFace("icons")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 64))
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(x+w-h*0.5, y+h*0.5, cpToUTF8(IconCHEVRONRIGHT))
}
示例2: Draw
func (g *Graph) Draw(self Widget, ctx *nanovgo.Context) {
g.WidgetImplement.Draw(self, ctx)
x := float32(g.x)
y := float32(g.y)
w := float32(g.w)
h := float32(g.h)
ctx.BeginPath()
ctx.Rect(x, y, w, h)
ctx.SetFillColor(g.backgroundColor)
ctx.Fill()
if len(g.values) < 2 {
return
}
ctx.BeginPath()
ctx.MoveTo(x, y+h)
dx := float32(len(g.values) - 1)
for i, v := range g.values {
vx := x + float32(i)*w/dx
vy := y + (1.0-v)*h
ctx.LineTo(vx, vy)
}
ctx.LineTo(x+w, y+h)
ctx.SetStrokeColor(nanovgo.MONO(100, 255))
ctx.Stroke()
ctx.SetFillColor(g.foregroundColor)
ctx.Fill()
ctx.SetFontFace(g.theme.FontNormal)
ctx.SetFillColor(g.textColor)
if g.caption != "" {
ctx.SetFontSize(14)
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignTop)
ctx.Text(x+3, y+1, g.caption)
}
if g.header != "" {
ctx.SetFontSize(18)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignTop)
ctx.Text(x+w-3, y+1, g.header)
}
if g.footer != "" {
ctx.SetFontSize(15)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignBottom)
ctx.Text(x+w-3, y+h-1, g.footer)
}
ctx.BeginPath()
ctx.Rect(x, y, w, h)
ctx.SetStrokeColor(nanovgo.MONO(100, 255))
ctx.Stroke()
}
示例3: drawLabel
func drawLabel(ctx *nanovgo.Context, text string, x, y, w, h float32) {
ctx.SetFontSize(18.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 128))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x, y+h*0.5, text)
}
示例4: drawEditBox
func drawEditBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
drawEditBoxBase(ctx, x, y, w, h)
ctx.SetFontSize(20.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 64))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x+h*0.3, y+h*0.5, text)
}
示例5: PreferredSize
func (c *CheckBox) PreferredSize(self Widget, ctx *nanovgo.Context) (int, int) {
fw, fh := c.FixedSize()
if fw > 0 || fh > 0 {
return fw, fh
}
fontSize := float32(c.FontSize())
ctx.SetFontSize(fontSize)
ctx.SetFontFace(c.theme.FontNormal)
w, _ := ctx.TextBounds(0, 0, c.caption)
return int(w + 1.7*fontSize), int(fontSize * 1.3)
}
示例6: PreferredSize
func (w *Window) PreferredSize(self Widget, ctx *nanovgo.Context) (int, int) {
if w.buttonPanel != nil {
w.buttonPanel.SetVisible(false)
}
width, height := w.WidgetImplement.PreferredSize(self, ctx)
if w.buttonPanel != nil {
w.buttonPanel.SetVisible(true)
}
ctx.SetFontSize(18.0)
ctx.SetFontFace(w.theme.FontBold)
_, bounds := ctx.TextBounds(0, 0, w.title)
return maxI(width, int(bounds[2]-bounds[0])+20), maxI(height, int(bounds[3]-bounds[1]))
}
示例7: drawWindow
func drawWindow(ctx *nanovgo.Context, title string, x, y, w, h float32) {
var cornerRadius float32 = 3.0
ctx.Save()
defer ctx.Restore()
// ctx.Reset();
// Window
ctx.BeginPath()
ctx.RoundedRect(x, y, w, h, cornerRadius)
ctx.SetFillColor(nanovgo.RGBA(28, 30, 34, 192))
// ctx.FillColor(nanovgo.RGBA(0,0,0,128));
ctx.Fill()
// Drop shadow
shadowPaint := nanovgo.BoxGradient(x, y+2, w, h, cornerRadius*2, 10, 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()
// Header
headerPaint := nanovgo.LinearGradient(x, y, x, y+15, nanovgo.RGBA(255, 255, 255, 8), nanovgo.RGBA(0, 0, 0, 16))
ctx.BeginPath()
ctx.RoundedRect(x+1, y+1, w-2, 30, cornerRadius-1)
ctx.SetFillPaint(headerPaint)
ctx.Fill()
ctx.BeginPath()
ctx.MoveTo(x+0.5, y+0.5+30)
ctx.LineTo(x+0.5+w-1, y+0.5+30)
ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 32))
ctx.Stroke()
ctx.SetFontSize(18.0)
ctx.SetFontFace("sans-bold")
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.SetFontBlur(2)
ctx.SetFillColor(nanovgo.RGBA(0, 0, 0, 128))
ctx.Text(x+w/2, y+16+1, title)
ctx.SetFontBlur(0)
ctx.SetFillColor(nanovgo.RGBA(220, 220, 220, 160))
ctx.Text(x+w/2, y+16, title)
}
示例8: drawEditBoxNum
func drawEditBoxNum(ctx *nanovgo.Context, text, units string, x, y, w, h float32) {
drawEditBoxBase(ctx, x, y, w, h)
uw, _ := ctx.TextBounds(0, 0, units)
ctx.SetFontSize(18.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 64))
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignMiddle)
ctx.Text(x+w-h*0.3, y+h*0.5, units)
ctx.SetFontSize(20.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 128))
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignMiddle)
ctx.Text(x+w-uw-h*0.5, y+h*0.5, text)
}
示例9: RenderGraph
// RenderGraph shows graph
func (pg *PerfGraph) RenderGraph(ctx *nanovgo.Context, x, y float32) {
avg := pg.GetGraphAverage()
var w float32 = 200
var h float32 = 35
ctx.BeginPath()
ctx.Rect(x, y, w, h)
ctx.SetFillColor(backgroundColor)
ctx.Fill()
ctx.BeginPath()
ctx.MoveTo(x, y+h)
for i := 0; i < nvgGraphHistoryCount; i++ {
v := float32(1.0) / float32(0.00001+pg.values[(pg.head+i)%nvgGraphHistoryCount])
if v > 80.0 {
v = 80.0
}
vx := x + float32(i)/float32(nvgGraphHistoryCount-1)*w
vy := y + h - ((v / 80.0) * h)
ctx.LineTo(vx, vy)
}
ctx.LineTo(x+w, y+h)
ctx.SetFillColor(graphColor)
ctx.Fill()
ctx.SetFontFace(pg.fontFace)
if len(pg.name) > 0 {
ctx.SetFontSize(14.0)
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignTop)
ctx.SetFillColor(titleTextColor)
ctx.Text(x+3, y+1, pg.name)
}
ctx.SetFontSize(18.0)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignTop)
ctx.SetFillColor(fpsTextColor)
ctx.Text(x+w-3, y+1, fmt.Sprintf("%.2f FPS", 1.0/avg))
ctx.SetFontSize(15.0)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignBottom)
ctx.SetFillColor(averageTextColor)
ctx.Text(x+w-3, y+h+1, fmt.Sprintf("%.2f ms", avg*1000.0))
}
示例10: Draw
func (p *PopupButton) Draw(self Widget, ctx *nanovgo.Context) {
if !p.enabled && p.pushed {
p.pushed = false
}
p.popup.SetVisible(p.pushed)
p.Button.Draw(self, ctx)
if p.chevronIcon != 0 {
ctx.SetFillColor(p.TextColor())
ctx.SetFontSize(float32(p.FontSize()))
ctx.SetFontFace(p.theme.FontIcons)
ctx.SetTextAlign(nanovgo.AlignMiddle | nanovgo.AlignLeft)
fontString := string([]rune{rune(p.chevronIcon)})
iw, _ := ctx.TextBounds(0, 0, fontString)
px, py := p.Position()
w, h := p.Size()
ix := px + w - int(iw) - 8
iy := py + h/2 - 1
ctx.Text(float32(ix), float32(iy), fontString)
}
}
示例11: drawCheckBox
func drawCheckBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
ctx.SetFontSize(18.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 160))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x+28, y+h*0.5, text)
bg := nanovgo.BoxGradient(x+1, y+float32(int(h*0.5))-9+1, 18, 18, 3, 3, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 92))
ctx.BeginPath()
ctx.RoundedRect(x+1, y+float32(int(h*0.5))-9, 18, 18, 3)
ctx.SetFillPaint(bg)
ctx.Fill()
ctx.SetFontSize(40)
ctx.SetFontFace("icons")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 128))
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(x+9+2, y+h*0.5, cpToUTF8(IconCHECK))
}
示例12: 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)
}
}
示例13: drawSearchBox
func drawSearchBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
cornerRadius := h/2 - 1
// Edit
bg := nanovgo.BoxGradient(x, y+1.5, w, h, h/2, 5, nanovgo.RGBA(0, 0, 0, 16), nanovgo.RGBA(0, 0, 0, 92))
ctx.BeginPath()
ctx.RoundedRect(x, y, w, h, cornerRadius)
ctx.SetFillPaint(bg)
ctx.Fill()
/* ctx.BeginPath();
ctx.RoundedRect(x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f);
ctx.StrokeColor(ctx.RGBA(0,0,0,48));
ctx.Stroke();*/
ctx.SetFontSize(h * 1.3)
ctx.SetFontFace("icons")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 64))
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(x+h*0.55, y+h*0.55, cpToUTF8(IconSEARCH))
ctx.SetFontSize(20.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 32))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x+h*1.05, y+h*0.5, text)
ctx.SetFontSize(h * 1.3)
ctx.SetFontFace("icons")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 32))
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(x+w-h*0.55, y+h*0.55, cpToUTF8(IconCIRCLEDCROSS))
}
示例14: 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
}
示例15: Draw
func (c *CheckBox) Draw(self Widget, ctx *nanovgo.Context) {
cx := float32(c.x)
cy := float32(c.y)
ch := float32(c.h)
c.WidgetImplement.Draw(self, ctx)
fontSize := float32(c.FontSize())
ctx.SetFontSize(fontSize)
ctx.SetFontFace(c.theme.FontNormal)
if c.enabled {
ctx.SetFillColor(c.theme.TextColor)
} else {
ctx.SetFillColor(c.theme.DisabledTextColor)
}
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(cx+1.2*ch+5, cy+ch*0.5, c.caption)
var bgAlpha uint8
if c.pushed {
bgAlpha = 100
} else {
bgAlpha = 32
}
bgPaint := nanovgo.BoxGradient(cx+1.5, cy+1.5, ch-2.0, ch-2.0, 3, 3, nanovgo.MONO(0, bgAlpha), nanovgo.MONO(0, 180))
ctx.BeginPath()
ctx.RoundedRect(cx+1.0, cy+1.0, ch-2.0, ch-2.0, 3)
ctx.SetFillPaint(bgPaint)
ctx.Fill()
if c.checked {
ctx.SetFontSize(ch)
ctx.SetFontFace(c.theme.FontIcons)
if c.enabled {
ctx.SetFillColor(c.theme.IconColor)
} else {
ctx.SetFillColor(c.theme.DisabledTextColor)
}
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(cx+ch*0.5+1.0, cy+ch*0.5, string([]rune{rune(IconCheck)}))
}
}