Side label align in dynamic widget

jdpjamesp

ProgressTalk.com Moderator
Staff member
Probably a really simple solution, but I'm creating a dynamic widget and side label as follows:

Code:
CREATE TEXT tt-DynamicWidgets.LabelHandle IN WIDGET-POOL lv-WidgetPool
  ASSIGN X = lv-X - 102
         Y = lv-Y + 2
         WIDTH-PIXELS = 100
         FRAME        = FRAME {&FRAME-NAME}:HANDLE 
         FORMAT       = "X(25)"
         VISIBLE      = TRUE
         SCREEN-VALUE = tt-CompulsoryColumns.ColumnLabel + ":".
  CREATE FILL-IN tt-DynamicWidgets.WidgetHandle IN WIDGET-POOL lv-WidgetPool
  ASSIGN DATA-TYPE = "CHARACTER"
         NAME = "Fil-" + tt-CompulsoryColumns.ColumnName
         FRAME = FRAME {&FRAME-NAME}:HANDLE
         SIDE-LABEL-HANDLE = tt-DynamicWidgets.LabelHandle
         SENSITIVE = FALSE
         HIDDEN = FALSE
         PRIVATE-DATA = tt-CompulsoryColumns.ColumnName
         FORMAT = tt-CompulsoryColumns.ColumnFormat
         BGCOLOR = ?
         X = lv-X
         Y = lv-Y
         WIDTH-PIXELS = 200.

The trouble is, the text in the side labels is left aligned and I want it right aligned as would be the case when creating static fill ins. Any thoughts?! Cheers.
 
I think, but not sure here, that you need to look at the FONT-TABLE:GET-TEXT-WIDTH-PIXELS method - it will allow you to position your label exactly based on the width of the label. Very un-ABLish.

Or, if using 3GL .Net controls, simply:

THIS-OBJECT:label1:TextAlign = System.Drawing.ContentAlignment:MiddleRight.
 
Thanks Stefan - using the ABL. Bit of a pain to have to work it out. Shame that you can't just right align the text or something.
 
Hi Cringer, try it.

CREATE TEXT tt-DynamicWidgets.LabelHandle IN WIDGET-POOL lv-WidgetPool
ASSIGN X = lv-X - ( LENGTH(tt-CompulsoryColumns.ColumnLabel + ":") *
SESSION:PIXELS-PER-COLUMN + 2)
Y = lv-Y + 2
/*
WIDTH-PIXELS = 100
*/
FRAME = FRAME {&FRAME-NAME}:HANDLE
FORMAT = "X(25)"
VISIBLE = TRUE
SCREEN-VALUE = TRIM(tt-CompulsoryColumns.ColumnLabel + ":").

Regards
 
Relying on a fixed pixels per character width is not a good idea, I doubt anyone is using a fixed font. FONT-TABLE:GET-TEXT-WIDTH-PIXELS( columnlabel ) will give you the width in pixels of your label and will provide a correct result for both iiiiii and wwwwww:

Code:
MESSAGE
   FONT-TABLE:GET-TEXT-WIDTH-PIXELS( "iiiiii:" ) SKIP
   FONT-TABLE:GET-TEXT-WIDTH-PIXELS( "wwwwww:" )
VIEW-AS ALERT-BOX.
 
Stefan, is true, this works well.

DEFINE VARIABLE iFont AS INTEGER NO-UNDO.DEFINE VARIABLE hFrame AS HANDLE NO-UNDO.
hFrame = FRAME {&FRAME-NAME}:HANDLE.
iFont = hFrame:FONT.


CREATE TEXT h-Label
ASSIGN
X = lv-X - FONT-TABLE:GET-TEXT-WIDTH-PIXELS(TRIM(c-Label) + ':', iFont ) - 4
Y = lv-Y + 4
WIDTH-PIXELS = FONT-TABLE:GET-TEXT-WIDTH-PIXELS(TRIM(c-Label) + ':', iFont)
HEIGHT-PIXELS = FONT-TABLE:GET-TEXT-HEIGHT-PIXELS(iFont)
FRAME = FRAME {&FRAME-NAME}:HANDLE
FORMAT = FILL("X", LENGTH(TRIM(c-Label) + ':'))
VISIBLE = TRUE
SCREEN-VALUE = TRIM(c-Label) + ":".

Thank you, regards
 
Thank you gentlemen. I will investigate this if necessary. The users seem to be happy enough with left-aligned labels for now.
 
Back
Top