Questions about Dialog

Just starting out? Need help? Post your questions and find answers here.
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Questions about Dialog

Post by forumuser »

How can I create a hbox with multiple buttons in it which
- Have the same amount of space between them
- Are always centered (all of them as a group) inside the hbox
- Do not change their size when the window is resized

Basic sample code (from the help file, reduced):

Code: Select all

  DisableExplicit
  #Dialog = 0
  #Xml = 0

  XML$ = "<window id='#PB_Any' name='test' text='test' minwidth='500' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
         "  <hbox spacing='20' expand='no'>" +
         "    <singlebox/>" +
         "    <button text='button 1' width='100'/>" +
         "    <button text='button 2' width='100'/>" +
         "    <singlebox/>" +
         "  </hbox>" +
         "</window>"
  
  If ParseXML(#Xml, 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

Are the flags for frames broken?
I've tried
#PB_Frame_Single
#PB_Frame_Double
and
#PB_Frame_Flat
and the frame always looks the same?

Code: Select all

  DisableExplicit
  #Dialog = 0
  #Xml = 0

  XML$ = "<window id='#PB_Any' name='test' text='Preferences' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
         "  <hbox>" +
         "      <frame text='Backup' flags='#PB_Frame_Single'>" +
         "        <vbox expand='no'>" +
         "          <checkbox text='Activate backup'/>" +
         "        </vbox>" +
         "      </frame>" +
         "  </hbox>" +
         "</window>"

  If ParseXML(#Xml, 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
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: Questions about Dialog

Post by wombats »

I would suggest using a Gridbox.

Code: Select all

DisableExplicit
#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='test' text='Preferences' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "  <hbox>" +
       "    <singlebox expand='no' align='center, top'>" +
       "    <gridbox columns='4' colexpand='equal' colspacing='5'>" +
       "      <button text='1' width='40' height='25'/>" +
       "      <button text='2' width='40' height='25'/>" +
       "      <button text='3' width='40' height='25'/>" +
       "      <button text='4' width='40' height='25'/>" +
       "     </gridbox>" +
       "     </singlebox>" +
       "  </hbox>" +
       "</window>"

If ParseXML(#Xml, 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
It does seem that the flags for a FrameGadget do nothing on a Dialog:

Code: Select all

dlg_xml$ = "<window id='#PB_Any' name='test' text='Dialog' minwidth='320' minheight='250' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>"
dlg_xml$ + "  <vbox>"
dlg_xml$ + "    <frame text='FrameGadget Standard'/>"
dlg_xml$ + "    <frame flags='#PB_Frame_Single'/>"
dlg_xml$ + "    <frame flags='#PB_Frame_Double'/>"
dlg_xml$ + "    <frame flags='#PB_Frame_Flat'/>"
dlg_xml$ + "  </vbox>"
dlg_xml$ + "</window>"

OpenWindow(0, 0, 0, 320, 250, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
FrameGadget(0, 10,  10, 300, 50, "FrameGadget Standard")
FrameGadget(1, 10,  70, 300, 50, "", #PB_Frame_Single)
FrameGadget(2, 10, 130, 300, 50, "", #PB_Frame_Double)
FrameGadget(3, 10, 190, 300, 50, "", #PB_Frame_Flat)

ParseXML(0, dlg_xml$)
CreateDialog(0) 
OpenXMLDialog(0, 0, "test")

ResizeWindow(DialogWindow(0), WindowX(0) + WindowWidth(0) + 10, #PB_Ignore, #PB_Ignore, #PB_Ignore)

Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
I've submitted it as a bug report.
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Questions about Dialog

Post by forumuser »

Thanks a lot, wombats!

gridbox works fine and my next question would have been if I should file a bug report :)

One more question (because I don't know if I'm doing it wrong or if it is a bug as well)...
I want to set the width of the first column for a listicon gadget directly in the XML definition
(I know that I can change these values via SetGadgetItemAttribute() afterwards if I want to!)

Is "values" the wrong keyword?

Code: Select all

  DisableExplicit
  #Dialog = 0
  #Xml = 0

  XML$ = "<window id='#PB_Any' name='test' text='test' minwidth='600' minheight='auto' flags='#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget'>" +
         "  <listicon text='content' height='150' values='500'/>" +
         "</window>"

  If ParseXML(#Xml, 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
User avatar
HeX0R
Addict
Addict
Posts: 992
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Questions about Dialog

Post by HeX0R »

This is not possible, you have to do this afterwards via code.

Btw.:
If you want to play with dialogs, you might try the DialogDesign0r.
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Questions about Dialog

Post by forumuser »

This is not possible, you have to do this afterwards via code
Ok, thanks!
If you want to play with dialogs, you might try the DialogDesign0r.
Wow, what a great tool!
Post Reply