주요 콘텐츠

addTextOverlay

R2026b

Add text overlay to RoadRunner Viewer viewport

Since R2026b

    Description

    txt = addTextOverlay(rrViewer) adds an empty text overlay to the viewport of the specified RoadRunner Viewer object rrViewer, and returns a TextOverlay object, txt. Use the TextOverlay object to specify the text content, text style, text size, and text position in the viewport. For example, txt = addTextOverlay(rrViewer); adds a text overlay, txt, to the viewport of the specified RoadRunner Viewer rrViewer. The code txt.Text = "Hello World";, txt.Size = [0.25 0.25];, and txt.Style = "background: rgba(0,0,0,0.7); color: white; font-size: 16px;"; specify the text content, size, and style of the text overlay txt, respectively.

    example

    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 its text, style, position, and size. 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)

    Input Arguments

    collapse all

    RoadRunner Viewer in which to add a text overlay, specified as a roadrunnerViewer object.

    Output Arguments

    collapse all

    Text overlay, returned as a TextOverlay object. You can use text overlays to display annotations, such as the variables used during simulation or descriptions of events.

    Version History

    Introduced in R2026b