public void SetInfocard(Infocard infocard) { icard.Dispose(); icard = window.RichText.BuildText(infocard.Nodes, renderWidth > 0 ? renderWidth : 400, 0.8f); }
public void SetInfocard(Infocard infocard) { icard.Dispose(); InfocardText = infocard.ExtractText(); icard = window.RichText.BuildText(infocard.Nodes, renderWidth > 0 ? renderWidth : 400, 0.7f * ImGuiHelper.Scale); }
public override void Render(UiContext context, RectangleF parentRectangle) { //TODO: fix up if (setString != null) { Infocard = new Infocard() { Nodes = new List <RichTextNode>() }; string fontName = setFont ?? "$ListText"; if (fontName[0] == '$') { fontName = context.Data.Fonts.ResolveNickname(fontName.Substring(1)); } foreach (var s in setString.Split('\n')) { Infocard.Nodes.Add(new RichTextTextNode() { Contents = s, FontName = fontName, FontSize = setSize < 1 ? 22 : setSize, Alignment = TextAlignment.Left, Color = context.Data.GetColor("text").Color, Shadow = new TextShadow(context.Data.GetColor("black").Color) }); Infocard.Nodes.Add(new RichTextParagraphNode()); } setString = null; setFont = null; setSize = 0; } if (!Visible) { return; } var myRectangle = GetMyRectangle(context, parentRectangle); Background?.Draw(context, myRectangle); myRectangle.Width -= scrollbar.Style.Width; if (Infocard != null) { var rte = context.RenderContext.Renderer2D.CreateRichTextEngine(); var myRect = context.PointsToPixels(myRectangle); if (currInfocard != Infocard || mW != myRect.Width) { richText?.Dispose(); currInfocard = Infocard; mW = myRect.Width; richText = rte.BuildText(Infocard.Nodes, mW, (context.ViewportHeight / 480) * 0.5f); var h = richText.Height; if ((int)h > myRect.Height + 2) { scrollbar.ScrollOffset = 0; scrollbar.ThumbSize = myRect.Height / h; const float TICK_MAGIC = 0.2627986f; scrollbar.Tick = 0.01f * (scrollbar.ThumbSize / TICK_MAGIC); scrollbarVisible = true; } else { scrollbarVisible = false; } } if (scrollbarVisible) { scrollbar.Render(context, new RectangleF(myRectangle.X + myRectangle.Width, myRectangle.Y, scrollbar.Style.Width, myRectangle.Height)); } context.RenderContext.ScissorEnabled = true; context.RenderContext.ScissorRectangle = myRect; int y = myRect.Y; if (scrollbarVisible) { y -= (int)(scrollbar.ScrollOffset * (richText.Height - myRect.Height)); } rte.RenderText(richText, myRect.X, y); context.RenderContext.ScissorEnabled = false; } Border?.Draw(context, myRectangle); }