Page 1 of 1

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

Posted: Wed Jul 06, 2016 8:04 pm
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

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

Posted: Wed Jul 06, 2016 8:56 pm
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

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

Posted: Wed Jul 06, 2016 9:20 pm
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

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

Posted: Wed Jul 06, 2016 9:26 pm
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

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

Posted: Wed Jul 06, 2016 9:35 pm
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 :?:

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

Posted: Wed Jul 06, 2016 9:49 pm
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

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

Posted: Wed Jul 06, 2016 9:56 pm
by mhs
Hmm... what's about the "<hbox>" element with align="center"? Can't it be used for this?