Page 1 of 1

position a textline vertically

Posted: Sat Jul 01, 2006 10:50 am
by Tomio
My TextGadget() must be as small as possible to display a 1-line text.
But while there is still lot of space to the lower gadget-border, the text already touches (and is cut by) the upper gadget-border.

Is the a way to position the texline vertically?

Thanks.../tomio

Posted: Sat Jul 01, 2006 11:02 am
by srod
I don't think so, at least not with a text gadget (unless you subclass the control and take charge of the painting etc). It is certainly possible with a string gadget by using the #EM_SETRECT message.

Instead, you might be better off using the text metrics to calculate the required size of the text gadget etc.

Posted: Sat Jul 01, 2006 12:09 pm
by Tomio
srod wrote:I don't think so, at least not with a text gadget (unless you subclass the control and take charge of the painting etc). It is certainly possible with a string gadget by using the #EM_SETRECT message.

Instead, you might be better off using the text metrics to calculate the required size of the text gadget etc.
I have not enought space and the available space is small already: Textsize is 7 for Courier.

With the StringGadget() the mousepointer changes to a blinking input-caret. But there is no text-input. Only the pointer's position is evaluated. This is confusing and doesn't look nice.

../tomio

Posted: Sat Jul 01, 2006 12:23 pm
by srod
I must admit to being a little confused here.

Any chance of posting either a screenshot showing the problem, or some code?

Posted: Sat Jul 01, 2006 4:05 pm
by Tomio
srod wrote:I must admit to being a little confused here.

Any chance of posting either a screenshot showing the problem, or some code?
Hello srod!

your comment was a hint for me and I found out:
the text goes up if you doesn't use a border:

Code: Select all

 If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TextGadget(1, 10,  10, 60, 20, "ABCgjhi", #PB_Text_Border)
    SetGadgetColor(1,#PB_Gadget_BackColor,RGB(255,255,0))
    SetGadgetColor(1,#PB_Gadget_FrontColor,RGB(0,0,255))    

    TextGadget(2, 72,  10, 60, 20, "ABCgjhi")              ;<<<!!!
    SetGadgetColor(2,#PB_Gadget_BackColor,RGB(255,255,0))
    SetGadgetColor(2,#PB_Gadget_FrontColor,RGB(0,0,255))    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
Ok, a can live with it.
Thanks../tomio

Posted: Sat Jul 01, 2006 9:38 pm
by Konne
U could draw the text on an Image and make an Imagegadget.

Posted: Mon Oct 02, 2006 10:19 pm
by TerryHough
I needed a way to control the placement of the text in a borderless stringgadget, specifically I wanted to align the text at the bottom of the gadget rather than at the top.

A forum search turned up this topic and another similar one with example code by Sparkie.

So, using srod's hint above, this is what I came up with, thanks to some of Sparkie's code. Sparkie's works with multiple lines in the stringgadget, but I only needed handling for one line of text in each stringgadget.

I did not get it working with textgadgets, but someone else may have a go at it.

Note: The stringgadget must be multiline for this to work.

Code: Select all

#VP_CENTER = 0
#VP_BOTTOM = 1

Procedure SetGadgetTextVPosition(gadNum, vPosition.l=1)
  ; Get width and height of text on one line
  hdc = GetDC_(GadgetID(gadNum))
  GetTextExtentPoint32_(hdc, "AQbcj10", 7, @textXY.SIZE)
  ReleaseDC_(GadgetID(gadNum), hdc)
  ;--> Get and reset rect coordinates for StringGadget
  eRect.RECT
  GetClientRect_(GadgetID(gadNum), eRect)
  Select vPosition
  Case #VP_CENTER
    eRect\top = (eRect\Bottom - textXY\cy) / 2
  Case #VP_BOTTOM
    eRect\top = eRect\bottom - textXY\cy
  EndSelect
  SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect)
EndProcedure

; Example code
#Cou_Font_N12 = 1
LoadFont(#Cou_Font_N12    ,"DGCourier", 12)
SetGadgetFont(#PB_Default, FontID(#Cou_Font_N12))
If OpenWindow(0, 0, 0, 270, 160, "Vertical Postitioned Text", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  StringGadget(1, 10,  10, 60, 40, "AbjQ", #PB_String_ReadOnly | #PB_Text_Border|#ES_MULTILINE)
  SetGadgetColor(1,#PB_Gadget_BackColor,RGB(255,255,0))
  SetGadgetColor(1,#PB_Gadget_FrontColor,RGB(0,0,255))
  SetGadgetTextVPosition(1,#VP_CENTER)

  StringGadget(2, 90,  10, 60, 40, "ABCjqhi", #PB_String_BorderLess |#ES_MULTILINE)              ;<<<!!!
  SetGadgetColor(2,#PB_Gadget_BackColor,RGB(255,255,0))
  SetGadgetColor(2,#PB_Gadget_FrontColor,RGB(0,0,255))
  SetGadgetTextVPosition(2)
  
  SetActiveGadget(1)
  While WindowEvent():Wend
  Delay(5000)
  SetGadgetText(1,"gojo")
  While WindowEvent():Wend
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf