Page 1 of 1

StringGadget text orientation

Posted: Fri Mar 28, 2008 4:37 pm
by CSAUER
I would like to see flags for left (=default), center and right orientation inside StringGadgets. This would be very useful especially if it would be available on all platforms.

BR, CSAUER

Posted: Fri Mar 28, 2008 4:56 pm
by Fluid Byte
Actually it's already in there for Windows, just name of the constant doesn't begin with "#PB_". Image

Code: Select all

OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
StringGadget(0,5,5,200,20,"untitled1",#ES_LEFT)
StringGadget(1,5,30,200,20,"untitled2",#ES_CENTER)
StringGadget(2,5,55,200,20,"untitled3",#ES_RIGHT)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend

Posted: Fri Mar 28, 2008 6:29 pm
by Rook Zimbabwe
Actually I just use the same flags for the text gadget and that works.

Code: Select all

StringGadget(#String_msrv, 456, 6, 138, 18, "SERVER ID", #PB_Text_Center)
I always thought it was an undocumented feature...
:D

Code: Select all


Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Button_0
  #Text_3
  #String_INPUT
  #Text_2
  #Text_1
  #Text_0
  #String_2
  #String_1
  #String_0
EndEnumeration

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()

Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
  what$ = GetGadgetText(#String_INPUT)
    For x = #String_2 To #String_0
      SetGadgetText(x, what$)
    Next
    
EndProcedure

Procedure String_INPUT_Event(Window, Event, Gadget, Type)
  Debug "#String_INPUT"
EndProcedure

Procedure String_2_Event(Window, Event, Gadget, Type)
  Debug "#String_2"
EndProcedure

Procedure String_1_Event(Window, Event, Gadget, Type)
  Debug "#String_1"
EndProcedure

Procedure String_0_Event(Window, Event, Gadget, Type)
  Debug "#String_0"
EndProcedure

Procedure RegisterGadgetEvent(Gadget, *Function)
  
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
  
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
  
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
      LastElement(EventProcedures())
    EndIf
  Next
  
EndProcedure

Procedure Open_Window_0()
  
  If OpenWindow(#Window_0, 5, 5, 404, 145, "TEXT STUFF",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
    
      StringGadget(#String_0, 5, 10, 120, 20, "left")
      RegisterGadgetEvent(#String_0, @String_0_Event())
      StringGadget(#String_1, 140, 10, 120, 20, "center", #PB_Text_Center)
      RegisterGadgetEvent(#String_1, @String_1_Event())
      StringGadget(#String_2, 275, 10, 120, 20, "right", #PB_Text_Right)
      RegisterGadgetEvent(#String_2, @String_2_Event())
      
      TextGadget(#Text_0, 5, 35, 120, 20, "LEFT")
      TextGadget(#Text_1, 140, 35, 120, 20, "CENTER", #PB_Text_Center)
      TextGadget(#Text_2, 275, 30, 120, 20, "RIGHT", #PB_Text_Right)
      
      StringGadget(#String_INPUT, 5, 60, 390, 20, "") ; input box
      RegisterGadgetEvent(#String_INPUT, @String_INPUT_Event())
      
      TextGadget(#Text_3, 5, 85, 390, 15, "TYPE A WORD AND HIT THE BUTTON", #PB_Text_Center)

      ButtonGadget(#Button_0, 5, 105, 390, 30, "ENTER THE TEXT")
      RegisterGadgetEvent(#Button_0, @Button_0_Event())
      
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat
  
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
  
  Select Event
    Case #PB_Event_Gadget
      CallEventFunction(Window, Event, Gadget, Type)
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
8)

Posted: Fri Mar 28, 2008 9:13 pm
by Fluid Byte
Rook Zimbabwe wrote:Actually I just use the same flags for the text gadget and that works.
It's because these flags are interpreted as API constants. Image

The enumeration is the same:

Code: Select all

#ES_CENTER = #PB_Text_Center
#ES_RIGHT = #PB_Text_Right

Re: StringGadget text orientation

Posted: Mon Sep 28, 2015 8:14 am
by CONVERT
As Rook Zimbabwe, I always thought it was an undocumented feature...

But, it would be great if PureBasic takes an official position: #ES_RIGHT and #ES_CENTER for Windows (and what for Linux?).

Re: StringGadget text orientation

Posted: Mon Sep 28, 2015 11:42 am
by RSBasic
If you need api codes for Linux: http://www.chabba.de/Linux/StringGadget ... d_Align.pb (LinuxAPI-Lib by Omi)

Re: StringGadget text orientation

Posted: Mon Sep 28, 2015 11:52 am
by CONVERT
Thanks, RSBasic.