Torque Shader Engine/GUI/Resources/guiTextListControl/Justify Text
From TDN
[edit]
guiTextListControl - Justify Text
This simple addition to GuiTextListCtrl::onRenderCell in guiTextListCtrl.cpp will allow you to justify the cell text via the GUI profile if there is only one column in the control.
In GuiTextListCtrl::onRenderCell, in the for loop just under:
else
slen = dStrlen(text);
add the following:
S32 xOffset = offset.x + 4 + mColumnOffsets[index]; // use this if we have more then one column
S32 txt_w = mFont->getStrWidth((const UTF8 *)mList[cell.y].text);
if (mColumnOffsets.size() == 1) // otherwise, if there is only one column, we can now justify the text via the profile
{
switch (mProfile->mAlignment)
{
case GuiControlProfile::RightJustify:
xOffset = offset.x + (mBounds.extent.x - txt_w) - 4;
break;
case GuiControlProfile::CenterJustify:
xOffset = offset.x + (mBounds.extent.x / 2) - txt_w / 2;
break;
default: // GuiControlProfile::LeftJustify
xOffset = offset.x + 4;
break;
}
}
Then replace this line (also in GuiTextListCtrl::onRenderCell):
GFX->drawTextN(mFont, pos, text, slen, mProfile->mFontColors);
with the following line:
GFX->drawTextN(mFont, Point2I(xOffset, offset.y), text, slen, mProfile->mFontColors);
That's all!
Now if you only use one column in your guiTextListControl, the text will be rendered justified based on the justify = "left/center/right" field in your profile.
Categories: TSE | TGEA | GUI | Code



