Hi
You can set right alignment as the property of the objects and then I think the best option is to make your own “space distance” variable
Best Regards
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello everyone,
I am currently trying to develop a panel that requires aligning text with the right edge of a graphical background layer. I have been using the TextGetSize() function to calculate the width of the text and attempting to position the text by subtracting this width from the right edge X-coordinate of the background. However, the results are not accurate, and the text does not align with the right edge as expected.
Here is the code snippet I used:
obj.TextCreate(0, "n 1", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "ON", 10), y + y_distance * 1, 10, "Arial", "ON", clrYellow);
obj.TextCreate(0, "n 2", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "999", 10), y + y_distance * 2, 10, "Arial", "999", clrYellow);
obj.TextCreate(0, "n 3", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "IC MARKETS", 10), y + y_distance * 3, 10, "Arial", "IC MARKETS", clrYellow);
int GetRightEdge(const int chart_ID, const string ref_name)
{
int ref_x = (int)ObjectGetInteger(chart_ID, ref_name, OBJPROP_XDISTANCE) + (int)ObjectGetInteger(chart_ID, ref_name, OBJPROP_XSIZE);
return ref_x;
}
int CalculateLeftAlignmentX(const int rightEdgeX, const string text, const int distance)
{
uint text_width, text_height;
TextGetSize(text, text_width, text_height);
int new_x = rightEdgeX - text_width - distance;
printf("%f",text_width);
return new_x;
}
Does anyone know a more accurate method to measure text width, or are there other techniques that can help achieve this alignment? Thank you for your help!