Page 1 of 1

PB 6.30b3 TextGadget horizontal text positioning error

Posted: Tue Oct 07, 2025 9:02 am
by Cezary
Linux Mint 22.2 Cinnamon, PureBasic_Linux3_beta_X64_6.30 installation pack:
regargless of TextGadget parameter #PB_Text_Right, #PB_Text_Center or without any (should be left aligned), the text is always centered.

Code: Select all

If OpenWindow(0, 100, 100, 150, 100, "test", #PB_Window_SystemMenu)

  TextGadget(0, 10, 10, 100, 20, "aaa", #PB_Text_Border)
  TextGadget(1, 10, 40, 100, 20, "bbb", #PB_Text_Border | #PB_Text_Center)
  TextGadget(2, 10, 70, 100, 20, "ccc", #PB_Text_Border | #PB_Text_Right)

  Repeat : Until #PB_Event_CloseWindow = WaitWindowEvent()
  
EndIf

Re: PB 6.30b3 TextGadget horizontal text positioning error

Posted: Tue Oct 07, 2025 3:16 pm
by Erlend
I confirm, allways center alignment, regardless of flags, Ubuntu 25.04 .

BR
Erlend

Re: PB 6.30b3 TextGadget horizontal text positioning error

Posted: Wed Oct 08, 2025 5:08 pm
by mk-soft
Alignment y looks good, but doesn't fit for AllOS

Small fix for Beta 3 ;)

Code: Select all

; TOP Fix

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_entry_set_alignment(*entry, xalign.f)
    gtk_label_set_xalign(*label, xalign.f)
    gtk_label_set_yalign(*label, yalign.f)
    gtk_misc_set_alignment(*label, xalign.f, yalign.f)
  EndImport
  
  Procedure _LinuxTextGadget(Gadget, x, y, Width, Height, Text$, Flags = 0)
    Protected r1 = TextGadget(Gadget, x, y, Width, Height, Text$, Flags)
    Protected widget
    If Gadget = #PB_Any
      widget = GadgetID(r1)
    Else
      widget = r1
    EndIf
    CompilerIf Subsystem("gtk2")
      If Flags & #PB_Text_Center
        gtk_misc_set_alignment(widget, 0.5, 0.0)
        gtk_label_set_justify_(widget, #GTK_JUSTIFY_CENTER)
      ElseIf Flags & #PB_Text_Right
        gtk_misc_set_alignment(widget, 1.0, 0.0)
        gtk_label_set_justify_(widget, #GTK_JUSTIFY_RIGHT)
      Else
        gtk_misc_set_alignment(widget, 0.0, 0.0)
        gtk_label_set_justify_(widget, #GTK_JUSTIFY_LEFT)
      EndIf
    CompilerElse
      If Flags & #PB_Text_Center
        gtk_label_set_xalign(widget, 0.5)
        gtk_label_set_yalign(widget, 0.0)
        gtk_label_set_justify_(widget, #GTK_JUSTIFY_CENTER)
      ElseIf Flags & #PB_Text_Right
        gtk_label_set_xalign(widget, 1.0)
        gtk_label_set_yalign(widget, 0.0)
        gtk_label_set_justify_(widget, #GTK_JUSTIFY_RIGHT)
      Else
        gtk_label_set_xalign(widget, 0.0)
        gtk_label_set_yalign(widget, 0.0)
        gtk_label_set_justify_(widget, #GTK_JUSTIFY_LEFT)
      EndIf
    CompilerEndIf 
    ProcedureReturn r1
  EndProcedure
  
  Macro TextGadget(Gadget, x, y, Width, Height, Text, Flags=0)
    _LinuxTextGadget(Gadget, x, y, Width, Height, Text, Flags)
  EndMacro
  
CompilerEndIf

;-TOP Main

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("&File")
    MenuItem(99, "E&xit")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    TextGadget(0, 10, 10, 240, 25, "Small Fix For Beta 3 ;)")
    TextGadget(1, 10, 40, 240, 25, "Small Fix For Beta 3 ;)", #PB_Text_Center)
    TextGadget(2, 10, 70, 240, 25, "Small Fix For Beta 3 ;)", #PB_Text_Right)
    
    SetGadgetColor(0, #PB_Gadget_FrontColor, #Black)
    SetGadgetColor(1, #PB_Gadget_FrontColor, #Black)
    SetGadgetColor(2, #PB_Gadget_FrontColor, #Black)
    
    SetGadgetColor(0, #PB_Gadget_BackColor, #Red)
    SetGadgetColor(1, #PB_Gadget_BackColor, #Yellow)
    SetGadgetColor(2, #PB_Gadget_BackColor, #Green)
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 99
              PostEvent(#PB_Event_CloseWindow, 0, 0)
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()