Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 19:48:17 +0000



UseTool multiline text alignment

View Count: 1036

[2018-03-13 23:56:17]
@sstfrederik - Posts: 403
Hi,

I have an issue with aligning text using standard Format and AppendFormat.

I expect the middle text to be filled to 50 characters, however this is not the case as can be seen with the attached image.

The goal is to have a fixed background size.

This is some example code:

SCSFExport scsf_UseToolExampleDrawingTextAtTheEndOfTheChart(SCStudyInterfaceRef sc)
{
  // Display some text after the end of the chart
  SCSubgraphRef Status = sc.Subgraph[0];
  // Set configuration variables
  if (sc.SetDefaults)
  {
    sc.GraphName = "UseTool Example: Text";
    sc.GraphRegion = 0;
    sc.FreeDLL = 0;
    sc.AutoLoop = 0; //No automatic looping

    Status.Name = "Status";
    Status.LineWidth = 20;
    Status.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
    Status.PrimaryColor = RGB(0, 0, 0); //black
    Status.SecondaryColor = RGB(255, 127, 0); //Orange
    Status.SecondaryColorUsed = true;
    
    return;
  }

  // Do data processing  
  int BarIndex;

  int& r_LineNumber = sc.GetPersistentInt(1);

  
  s_UseTool Tool;
  Tool.ChartNumber = sc.ChartNumber;
  Tool.DrawingType = DRAWING_TEXT;
  Tool.Region = sc.GraphRegion;
  if(r_LineNumber != 0)
    Tool.LineNumber = r_LineNumber;
  Tool.AddMethod = UTAM_ADD_OR_ADJUST;
  Tool.AddAsUserDrawnDrawing = 0;
  
  Tool.BeginDateTime = 20;
  Tool.BeginValue = 90;
  Tool.UseRelativeVerticalValues = true;
  Tool.ReverseTextColor = false;
  Tool.Color = Status.PrimaryColor;
  Tool.FontBackColor = Status.SecondaryColor;
  Tool.FontBold = true;
  Tool.FontSize = Status.LineWidth;
  Tool.FontFace = sc.GetChartTextFontFaceName();
  Tool.MultiLineLabel = 1;
  
  SCString TempStatusString;
  SCString StatusString;
  //

  TempStatusString = "Testing some longer than the other string"; //still less than 50 characters
  StatusString.Format("%-10s : %-50s : %10s \n","A",TempStatusString.GetChars(),"B");

  TempStatusString = "Shorter string";
  StatusString.AppendFormat("%-10s : %-50s : %10s \n","C",TempStatusString.GetChars(),"D");
  

  TempStatusString = "And another string";
  StatusString.AppendFormat("%-10s : %-50s : %10s \n","E",TempStatusString.GetChars(),"F");
  
  //
  Tool.Text = StatusString;
  sc.UseTool(Tool);
  r_LineNumber = Tool.LineNumber;//Remember line number which has been automatically set
}


Any pointers to resolve this?

Thanks,

Frederik
imageusetool.PNG / V - Attached On 2018-03-13 23:53:02 UTC - Size: 19.5 KB - 298 views
[2018-03-14 01:18:53]
Sierra Chart Engineering - Posts: 104368
You need to specify a font which uses a fixed width per character.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account