How to right-align custom graphics text?

How to right-align custom graphics text?

perryK67ZX
Contributor Contributor
681 Views
1 Reply
Message 1 of 2

How to right-align custom graphics text?

perryK67ZX
Contributor
Contributor

I don't see a way via the API to right-align text, but I do see the `formattedText` property. Is there a list of formatting options available? Is there an option for right-aligning the text?

0 Likes
682 Views
1 Reply
Reply (1)
Message 2 of 2

j4n.vokurka
Advocate
Advocate

Hello,

I've used custom graphics - more precisely billboard - to display text on screen as well. I will share my creation and setting of custom graphics written in C++ so you have a reference:

Ptr<CustomGraphicsGroup> graphics = customGroups->add();
graphics->id(BillboardID);

Ptr<Matrix3D> matrix = Matrix3D::create();
Ptr<CustomGraphicsText> graphicsText = graphics->addText(BillboardBlock, "Arial", 0.5, matrix);

Ptr<CustomGraphicsBillBoard> billBoard = CustomGraphicsBillBoard::create(Point3D::create(0, 0, 0));
billBoard->billBoardStyle(CustomGraphicsBillBoardStyles::ScreenBillBoardStyle);
graphicsText->billBoarding(billBoard);

Ptr<CustomGraphicsViewScale> viewScale = CustomGraphicsViewScale::create(30, Point3D::create(0, 0, 0));
graphicsText->viewScale(viewScale);

Ptr<CustomGraphicsViewPlacement> viewPlace = CustomGraphicsViewPlacement::create(
	Point3D::create(0, 0, 0),
	static_cast<ViewCorners>(currentCorner),
	Point2D::create(XCoordinate, YCoordinate));
graphicsText->viewPlacement(viewPlace);

graphicsText->isSelectable(false);

Ptr<CustomGraphicsSolidColorEffect> BlackColor = CustomGraphicsSolidColorEffect::create(Color::create(0, 0, 0, 255));
graphicsText->color(BlackColor);


This basically displays a text block (formattedText) that:
- is always facing towards my screen

- has certain size and color

- is not selectable

- is located in one of the corners of the screen

- is indented by x, y values according to which corner it is located in and according to the size of the text block so it doesn't "overflow" and is in it entirety displayed 

Now if your criteria are mostly the same, you will face the same problem as me. Text block has x, y coordinates and according to the size and the selected corner you have to adjust these coordinates so the text displays properly. Both x and y coordinates' origin is in the top-left corner.

For example if you display your text in top-left corner you don't have to indent the text at all because that's the point from which the text starts to display. However if you have selected bottom-right corner (which is imo the most convenient spot for these graphics) you will have to indent the text block by its full width and height so it stays on the screen. 

If you display for example a numerical value of which you know how many maximum decimal places it should have it's easy. If you try to display dynamic text it's something completely different. You would probably have to calculate the number of characters before "\n" is entered and then use the highest value and the number of rows to set the indentation. 

Good luck