How to vertically center a text gadget to a string gadget?

Just starting out? Need help? Post your questions and find answers here.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

How to vertically center a text gadget to a string gadget?

Post by uwekel »

Hi,

i would like to exactly center a label in front of a string gadget, but i have no idea, how. At the moment, it is docked to the upper left corner of the gridbox, so it does not look very good.

Can anyone help?

Run this code and you will hopefully see what i mean.

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='Test' text='Test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "<gridbox columns='2'>" +
       "<text text='Eingabe:'/>" +
       "<string width='250'/>" +
       "</gridbox>" +
       "</window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow 
  Else  
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
Regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: How to vertically center a text gadget to a string gadge

Post by RASHAD »

Use Singlebox with the proper margins

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='Test' text='Test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "<gridbox columns='2'>" +
       "  <singlebox margin='top:0,left:200,right:0,bottom:0'>" +
       "<text text='Eingabe:'/>" +
       "  </singlebox>" +
       "<string width='250'/>" +
       "</gridbox>" +
       "</window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  Else 
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
Egypt my love
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: How to vertically center a text gadget to a string gadge

Post by uwekel »

Hello Rashad,

thank you for your quick reply, but that is not exactly what i meant. The y-position of the word "Eingabe" should be maybe 3 or 4 pixels down.

Regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: How to vertically center a text gadget to a string gadge

Post by RASHAD »

Hi uwekel
OK so play with the top margin 3,4 or 10 as you like

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='Test' text='Test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "<gridbox columns='2'>" +
       "  <singlebox margin='top:10,left:0,right:0,bottom:0'>" +
       "<text text='Eingabe:'/>" +
       "  </singlebox>" +
       "<string width='250'/>" +
       "</gridbox>" +
       "</window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  Else
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
Egypt my love
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: How to vertically center a text gadget to a string gadge

Post by uwekel »

Hi Rashad,

the margins in pixels do not work with larger fonts. But the singlebox by itself does the trick :-)

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='Test' text='Test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "<gridbox columns='2'>" +
       "<singlebox>" +
       "<text text='Eingabe:'/>" +
       "</singlebox>" +
       "<string width='250'/>" +
       "</gridbox>" +
       "</window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  Else
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
I am wondering why the

Code: Select all

align="center,left"
attribute in the text gadget line does not work :?:
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: How to vertically center a text gadget to a string gadge

Post by RASHAD »

No you still need the margins

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='Test' text='Test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "<gridbox columns='2'>" +
       "<singlebox>" +
       "<text text='Eingabe:'/>" +
       "</singlebox>" +
       "<string width='250' height='60'/>" +
       "</gridbox>" +
       "</window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  Else
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='Test' text='Test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "<gridbox columns='2'>" +
       "<singlebox margin='top:20,left:0,right:0,bottom:0'>" +
       "<text text='Eingabe:'/>" +
       "</singlebox>" +
       "<string width='250' height='60'/>" +
       "</gridbox>" +
       "</window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  Else
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
Last edited by RASHAD on Wed Jul 06, 2016 10:16 pm, edited 1 time in total.
Egypt my love
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: How to vertically center a text gadget to a string gadge

Post by mhs »

Hmm... what's about the "<hbox>" element with align="center"? Can't it be used for this?
Post Reply