public override void Draw(NVGcontext ctx) { if (!this.enabled && this.pushed) { this.pushed = false; } if (m_Popup) { m_Popup.isVisible = this.pushed; } base.Draw(ctx); if (0 != this.chevronIcon) { Theme style = this.theme; byte[] icon = Fonts.GetIconUTF8(this.chevronIcon); NVGcolor currTextColor = GetCurrTextColor(); int currFontSize = (0 <= this.fontSize) ? this.fontSize : style.buttonFontSize; int fontFace = Fonts.Get(style.fontIcons); NanoVG.nvgFontSize(ctx, currFontSize * 1.5f); NanoVG.nvgFontFace(ctx, fontFace); NanoVG.nvgFillColor(ctx, currTextColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); float iw = NanoVG.nvgTextBounds(ctx, 0f, 0f, icon, null); Vector2 iconPos = this.localPosition; iconPos.X += this.size.X - iw - 8; iconPos.Y += this.size.Y * 0.5f - 1; NanoVG.nvgText(ctx, iconPos.X, iconPos.Y, icon); } }
public static SizeF MeasureString(string text) { if (string.IsNullOrWhiteSpace(text)) { return(SizeF.Empty); } if (text.EndsWith(" ")) { text = $"{text.Substring(0, text.Length - 1)}("; } NanoVG.nvgFontFace(MainWindow.Nvg, "sans"); var sb = new float[4]; try { NanoVG.nvgTextBounds(MainWindow.Nvg, 0, 0, text, sb); } catch (Exception e) { Lumberjack.Error($"NvgHelper::MeasureString: {e.Message}"); } var sfw = sb[2] - sb[0]; var sfh = sb[3] - sb[1]; return(new SizeF(sfw, sfh)); }
public override Vector2 GetPreferredSize(NVGcontext ctx) { if (string.IsNullOrEmpty(caption)) { return(Vector2.Zero); } Vector2 ret = Vector2.Zero; int prefFontSize = GetPreferredFontSize(); NanoVG.nvgFontFace(ctx, font); NanoVG.nvgFontSize(ctx, prefFontSize); int fixedWidth = (int)this.fixedSize.X; if (0 < fixedWidth) { Vector2 pos = this.localPosition; NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgTextBoxBounds(ctx, pos.X, pos.Y, fixedWidth, caption, m_Bounds); ret.X = fixedWidth; ret.Y = (m_Bounds[3] - m_Bounds[1]); } else { NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); ret.X = NanoVG.nvgTextBounds(ctx, 0, 0, caption, m_Bounds); ret.Y = prefFontSize; } return(ret); }
public override Vector2 GetPreferredSize(NVGcontext ctx) { if (!Vector2.Zero.Equals(this.fixedSize)) { return(this.fixedSize); } int currFontSize = GetPreferredFontSize(); int currFontFace = Fonts.Get(this.theme.fontNormal); NanoVG.nvgFontSize(ctx, currFontSize); NanoVG.nvgFontFace(ctx, currFontFace); float tw = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null); Vector2 ret; ret.X = tw + 1.7f * currFontSize; ret.Y = 1.3f * currFontSize; return(ret); }
public override Vector2 GetPreferredSize(NVGcontext ctx) { Vector2 ret; int prefFontSize = GetPreferredFontSize(); NanoVG.nvgFontSize(ctx, prefFontSize); NanoVG.nvgFontFace(ctx, this.theme.fontBold); float tw = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null); float iw = 0f; float ih = prefFontSize; int btnIcon = this.icon; if (0 < btnIcon) { if (NanoVG.nvgIsFontIcon(btnIcon)) { byte[] icon = Fonts.GetIconUTF8(btnIcon); ih *= 1.5f; NanoVG.nvgFontFace(ctx, this.theme.fontIcons); NanoVG.nvgFontSize(ctx, ih); iw = NanoVG.nvgTextBounds(ctx, 0f, 0f, icon, null) + this.size.Y * 0.15f; } else { int w, h; w = h = 1; ih *= 0.9f; NanoVG.nvgImageSize(ctx, btnIcon, ref w, ref h); iw = w * ih / h; } } ret.X = (int)(tw + iw) + 20; ret.Y = prefFontSize + 10; return(ret); }
public override void Draw(NVGcontext ctx) { base.Draw(ctx); Theme style = this.theme; NVGcolor gradTopColor = style.buttonGradientTopUnfocusedColor; NVGcolor gradBotColor = style.buttonGradientBotUnfocusedColor; if (this.pushed) { gradTopColor = style.buttonGradientTopPushedColor; gradBotColor = style.buttonGradientBotPushedColor; } else { gradTopColor = style.buttonGradientTopFocusedColor; gradBotColor = style.buttonGradientBotFocusedColor; } Vector2 pos = this.localPosition; Vector2 size = this.size; NanoVG.nvgBeginPath(ctx); NanoVG.nvgRoundedRect(ctx, pos.X + 1f, pos.Y + 1f, size.X - 2f, size.Y - 2f , style.buttonCornerRadius - 1f); NanoVG.nvgFillColor(ctx, gradTopColor); NanoVG.nvgFill(ctx); if (0f < this.backgroundColor.a) { // fill background. } NVGpaint gradient = NanoVG.nvgLinearGradient(ctx, pos.X, pos.Y, pos.X, pos.Y + size.Y , gradTopColor, gradBotColor); NanoVG.nvgFillPaint(ctx, gradient); NanoVG.nvgFill(ctx); NanoVG.nvgBeginPath(ctx); NanoVG.nvgStrokeWidth(ctx, 1f); NanoVG.nvgRoundedRect(ctx, pos.X + 0.5f, pos.Y + (this.pushed ? 0.5f : 1.5f) , size.X - 1f, size.Y - 1 - (this.pushed ? 0f : 1f) , style.buttonCornerRadius); NanoVG.nvgStrokeColor(ctx, style.borderLightColor); NanoVG.nvgStroke(ctx); NanoVG.nvgBeginPath(ctx); NanoVG.nvgRoundedRect(ctx, pos.X + 0.5f, pos.Y + 0.5f , size.X - 1f, size.Y - 2f , style.buttonCornerRadius); NanoVG.nvgStrokeColor(ctx, style.borderDarkColor); NanoVG.nvgStroke(ctx); int currFontSize = 0 > this.fontSize ? style.buttonFontSize : this.fontSize; NanoVG.nvgFontSize(ctx, currFontSize); NanoVG.nvgFontFace(ctx, style.fontBold); float tw = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null); Vector2 center = pos + size * 0.5f; Vector2 textPos = new Vector2(center.X - tw * 0.5f, center.Y - 1f); NVGcolor currTextColor = GetCurrTextColor(); int btnIcon = this.icon; if (0 != btnIcon) { float iw, ih; iw = 0f; ih = currFontSize; byte[] icon = Fonts.GetIconUTF8(btnIcon); if (NanoVG.nvgIsFontIcon(btnIcon)) { ih *= 1.5f; NanoVG.nvgFontSize(ctx, ih); NanoVG.nvgFontFace(ctx, style.fontIcons); iw = NanoVG.nvgTextBounds(ctx, 0, 0, icon, null); } else { int w, h; w = h = 1; ih *= 0.9f; NanoVG.nvgImageSize(ctx, btnIcon, ref w, ref h); if (0 < h) { iw = w * ih / h; } } if (!string.IsNullOrEmpty(this.caption)) { iw += size.Y * 0.15f; } NanoVG.nvgFillColor(ctx, currTextColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); Vector2 iconPos = center; iconPos.Y -= 1f; switch (this.iconAnchorType) { case IconAnchorType.LeftCentered: { iconPos.X -= (tw + iw) * 0.5f; textPos.X += iw * 0.5f; } break; case IconAnchorType.RightCentered: { textPos.X -= iw * 0.5f; iconPos.X += tw * 0.5f; } break; case IconAnchorType.Left: { iconPos.X = pos.X + 8f; } break; case IconAnchorType.Right: { iconPos.X = pos.X + size.X - iw - 8f; } break; default: break; } if (NanoVG.nvgIsFontIcon(btnIcon)) { // NOTE: icon rendering bug, any unicode > 0x10000 not being rendered correctly. // e.g. 0x1F680 (Font.Entypo.ICON_ROCKET). NanoVG.nvgText(ctx, iconPos.X, iconPos.Y + 1f, icon); } else { float imgAlpha = this.enabled ? 0.5f : 0.25f; NVGpaint imgPaint = NanoVG.nvgImagePattern( ctx , iconPos.X, iconPos.Y - ih * 0.5f, iw, ih , 0f, btnIcon, imgAlpha); NanoVG.nvgFillPaint(ctx, imgPaint); NanoVG.nvgFill(ctx); } // DEBUG: ICON BOUNDS //NanoVG.nvgStrokeWidth (ctx, 1.0f); //NanoVG.nvgBeginPath (ctx); //NanoVG.nvgRect (ctx, iconPos.X, iconPos.Y - ih * 0.5f, iw, ih); //NanoVG.nvgStrokeColor (ctx, textColor); //NanoVG.nvgStroke(ctx); } NanoVG.nvgFontSize(ctx, currFontSize); NanoVG.nvgFontFace(ctx, style.fontBold); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); NanoVG.nvgFillColor(ctx, style.textShadowColor); NanoVG.nvgText(ctx, textPos.X, textPos.Y, this.caption); NanoVG.nvgFillColor(ctx, currTextColor); NanoVG.nvgText(ctx, textPos.X, textPos.Y + 1f, this.caption); }