How to scale Draw.Text() in Immediate-Mode Drawing?

Avatar
  • updated

Hi there,

I work on an application, where one can draw lines and each line has a measure text, which shows its length in Meter. Everything is drawn using the “Immediate-Mode Drawing”.


To scale the placed lines and their points (discs) I use something like the pseudo-code below. But the text is not scaled (see screenshots).

Is there another Draw-Property to set? Maybe something like “Draw.TextFontSpace” or do you know of another possibility to scale Draw.Text()?



public void Enable ()
{
    RenderPipelineManager.beginCameraRendering += DrawShapes;
}

private void DrawShapes(ScriptableRenderContext context, Camera cam)
{
    using (Draw.Command(cam))
    {                  
        // scales all thicknesses and radius according to the set sizes in pixel
        // see example from documentation
        Draw.ThicknessSpace = ThicknessSpace.Pixels;
        Draw.RadiusSpace = ThicknessSpace.Pixels;

        // draw lines and points (using discs)
        // is scaled
        Draw.Line(…);
        Draw.Disc(…);
        
        // draw measure Text
        // >>> text is not scaled <<<
        Draw.Text(…);
    }
}


Image 714

Image 715


Best regards,
Richard

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Avatar
Freya Holmér creator
Quote from jon coughlin

Is it possible to check the width/height of a text element drawn in immediate mode? 
I want to be able to draw a line under my text, for instance, and need to know how big of a line to draw.

if you're using the persistent TextElement types, then you have access to all the TMP properties in myTextElement.Tmp, which should give you access to all the properties text mesh pro exposes for their text. There's info in the online docs on how to use TextElements!

Avatar
jon coughlin

Is it possible to check the width/height of a text element drawn in immediate mode? 
I want to be able to draw a line under my text, for instance, and need to know how big of a line to draw.

Avatar
richard

I see. Then I will do the text scaling probably based on closest-text--to-camera-distance.
Thanks for your help.

Avatar
Freya Holmér creator

pixel-based text scaling is not planned - it's using text-mesh pro shaders, so I don't have as much control over them on the shader side of things!

Avatar
richard

Alright, thanks for the reply and thanks a lot for making Shapes. It is a great asset :).
Is something like this planned in the near future (next 2-3 months)?

Avatar
Freya Holmér creator

There's no built-in pixel sizing option for text at the moment, you'll have to scale it manually with Draw.Scale or Draw.FontSize, based on whatever heuristic you want to use