主要内容

TextOverlay

R2026b

Specify text overlay in RoadRunner Viewer viewport

Since R2026b

    Description

    The TextOverlay object represents a text overlay in the RoadRunner Viewer viewport. Use a TextOverlay object to change the text, size, position, and text style of the corresponding text overlay.

    Creation

    The addTextOverlay function adds an empty text overlay to the specified RoadRunner Viewer viewport. For example, txt = addTextOverlay(rrViewer); adds the empty text overlay txt to the viewport of the RoadRunner Viewer object rrViewer.

    Properties

    expand all

    Text to display, specified as a string scalar or character vector.

    Style of the text, specified as a string scalar or character vector. Use this property to specify text style properties, such as color, font-size, and font-style. You must separate each text style property and value pair by using a semicolon.

    Example: txt.Style="color: white; font-size: 16px;"; specifies the color and font size of txt as white and 16px, respectively.

    Position of the text overlay in the viewport, specified as a 1-by-2 vector in the range [0, 1]. This value is relative to the size of the viewport, measured from the top-left corner. The value [0 0] is the top-left corner and [1 1] is the bottom-right corner.

    If you specify WorldPosition, RoadRunner Viewer ignores this property.

    Size of the text overlay in the viewport, specified as a 1-by-2 vector of the form [w h] in the range [0, 1]. The value of w extends the overlay to the right, and the value of h extends the overlay down, relative to Position and the size of the viewport.

    By default, the size of the text overlay is [0 0]. To see the text overlay, set this property to a value greater than 0.

    Position of the text overlay in the scene graph using world coordinates, specified as a 1-by-3 vector of the form [x y z]. RoadRunner Viewer places the top-left corner of the overlay at the specified position. If you specify this property, RoadRunner Viewer ignores the value of Position.

    By default, the text overlay position is relative to the RoadRunner Viewer viewport regardless of the camera position. You can use this property to specify for the text overlay to maintain a fixed position relative to the scene graph so that it remains at that position as the camera orbits, pans, or zooms.

    Examples

    collapse all

    Use addTextOverlay to add a text overlay to the RoadRunner Viewer viewport. Then, modify the properties of the TextOverlay object to specify the text, style, position, and size of the overlay. This example assumes you have already added the folder containing the RoadRunner API to your MATLAB® path. For information on getting started with RoadRunner Viewer, see Get Started with RoadRunner Viewer (RoadRunner Scenario).

    Open RoadRunner Viewer and create a roadrunnerViewer object rrViewer.

    rrViewer = roadrunnerViewer;

    To add a text overlay, txt, to the RoadRunner Viewer viewport, use addTextOverlay.

    txt = addTextOverlay(rrViewer);

    To specify the text to display, modify the Text property of txt.

    txt.Text = "Hello World";
    

    To modify the style, position, and size of the text overlay, specify the Style, Position, and Size properties of txt, respectively. The position and size values of the text overlay are relative to the size of the RoadRunner Viewer viewport, measured from the top-left corner.

    txt.Style = "background: rgba(0,0,0,0.7); color: white; font-size: 16px;";
    txt.Position = [0.01 0.01];
    txt.Size = [0.25 0.05];

    To update RoadRunner Viewer and view the changes to the overlay, use the drawnow function.

    drawnow(rrViewer)

    Version History

    Introduced in R2026b