Wrong gadget size with dialog library?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Wrong gadget size with dialog library?

Post by Lord »

Hi!

I've encountered a problem with a button gadget.
I tried to have an button with size 12x12 pixel and a font size of 6.
The layout is: button and string gadget in first row, then an editor
gadget.
Everything looks fine, but the button and the string gadget do
always have a minimum size of 24 pixel.

How can I get button/string with less than 24 pixel?
Example code:

Code: Select all

EnableExplicit

Runtime Enumeration
  #MainWindow
EndEnumeration
Runtime Enumeration
  #Button1
  #Text1
  #Editor1
EndEnumeration

Define XML$
Define xmlGUI.i
Define dlgGUI.i

Procedure myResize()
  Protected Text.s
  Text+
       "Button x: "+#TAB$+GadgetX(#Button1)+#CRLF$+
       "Button y: "+#TAB$+GadgetY(#Button1)+#CRLF$+
       "Button w: "+#TAB$+GadgetWidth(#Button1)+#CRLF$+
       "Button h: "+#TAB$+GadgetHeight(#Button1)+#CRLF$+
       "String x:  "+#TAB$+GadgetX(#Text1)+#CRLF$+
       "String y:  "+#TAB$+GadgetY(#Text1)+#CRLF$+
       "String w:  "+#TAB$+GadgetWidth(#Text1)+#CRLF$+
       "String h:  "+#TAB$+GadgetHeight(#Text1)+#CRLF$+
       "Window w: "+#TAB$+WindowWidth(#MainWindow, #PB_Window_InnerCoordinate)+#CRLF$+
       "Window h: "+#TAB$+WindowHeight(#MainWindow, #PB_Window_InnerCoordinate)+#CRLF$
  SetGadgetText(#Editor1, Text)
 EndProcedure

XML$="<?xml version='1.0' encoding='UTF-8'?>"+
     "<dialogs>"+
     "  <window ID='#MainWindow' text='Test' name='myWindow'"+
     "          minwidth='640' minheight='480'"+
     "          flags='#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered |"+
     "                 #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget'>"+
     "  <vbox expand='item:2'>"+
     "    <hbox expand='item:2'>"+
     "      <button ID='#Button1' width='12' height='12' text='?'>"+
     "      </button>"+
     "      <string ID='#Text1' height='12' text='Text 1'>"+
     "      </string>"+
     "    </hbox>"+
     "    <!-- "+
     "      Dieser Bereich ist auskommentiert"+
     "    -->"+
     "    <editor ID='#Editor1' text='Editor 1'>"+
     "    </editor>"+
     "  </vbox>"+
     "  </window>"+
     "</dialogs>"

LoadFont(1, "Arial", 6)
SetGadgetFont(#PB_Default, FontID(1))

xmlGUI = ParseXML(#PB_Any, XML$)
If xmlGUI
  If XMLStatus(xmlGUI) = #PB_XML_Success
    dlgGUI = CreateDialog(#PB_Any)
    If dlgGUI
      If OpenXMLDialog(dlgGUI, xmlGUI, "myWindow")
        
;         SetGadgetFont(#Button1, FontID(1))
;         SetGadgetFont(#Text1, FontID(1))
;         SetGadgetFont(#Editor1, FontID(1))
        
        myResize()
        BindEvent(#PB_Event_SizeWindow, @myResize())
        
        Repeat
        Until WaitWindowEvent()=#PB_Event_CloseWindow
                
      Else
        Debug "Fehler in der Dialog-Definition: " + DialogError(dlgGUI)
      EndIf
    Else
      Debug "Dialog konnte nicht erstellt werden!"
    EndIf
  Else
    Debug "XML Fehler: " + XMLError(xmlGUI)
    Debug "           in Zeile " + Str(XMLErrorLine(xmlGUI)) + " an Position " + Str(XMLErrorPosition(xmlGUI))
  EndIf
  FreeXML(xmlGUI)
Else
  Debug "XML$ konnte gelesen werden."
  End
EndIf
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Wrong gadget size with dialog library?

Post by RASHAD »

Hi Lord
Width, Height (optional) The size (in pixels) of the #Dialog. If the size is smaller than the required size as defined in the XML (after layout calculation), then the required size will be used. If omitted, the size of the dialog will be the smallest size required.
I think we should have an explanation from Fred
Can't say if it's bug or not (It could be limitations)
Next is a workaround not perfect specially with resizing

Code: Select all

EnableExplicit

Runtime Enumeration
  #MainWindow
EndEnumeration
Runtime Enumeration
  #Button1
  #Text1
  #Editor1
EndEnumeration

Define XML$,x,y,w,h
Define xmlGUI.i
Define dlgGUI.i

Procedure myResize()
  Protected Text.s
  Text+
       "Button x: "+#TAB$+GadgetX(#Button1)+#CRLF$+
       "Button y: "+#TAB$+GadgetY(#Button1)+#CRLF$+
       "Button w: "+#TAB$+GadgetWidth(#Button1)+#CRLF$+
       "Button h: "+#TAB$+GadgetHeight(#Button1)+#CRLF$+
       "String x:  "+#TAB$+GadgetX(#Text1)+#CRLF$+
       "String y:  "+#TAB$+GadgetY(#Text1)+#CRLF$+
       "String w:  "+#TAB$+GadgetWidth(#Text1)+#CRLF$+
       "String h:  "+#TAB$+GadgetHeight(#Text1)+#CRLF$+
       "Window w: "+#TAB$+WindowWidth(#MainWindow, #PB_Window_InnerCoordinate)+#CRLF$+
       "Window h: "+#TAB$+WindowHeight(#MainWindow, #PB_Window_InnerCoordinate)+#CRLF$
  SetGadgetText(#Editor1, Text)
 EndProcedure

XML$="<?xml version='1.0' encoding='UTF-8'?>"+
     "<dialogs>"+
     "  <window ID='#MainWindow' text='Test' name='myWindow'"+
     "          minwidth='640' minheight='480'"+
     "          flags='#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered |"+
     "                 #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget'>"+
     "  <vbox expand='item:2'>"+
     "    <hbox expand='item:2'>"+
     "      <button ID='#Button1' name='but' width='12' height='12' text='?'>"+
     "      </button>"+
     "      <string ID='#Text1' name='text' height='12' text='Text 1'>"+
     "      </string>"+
     "    </hbox>"+
     "    <!-- "+
     "      Dieser Bereich ist auskommentiert"+
     "    -->"+
     "    <editor ID='#Editor1' text='Editor 1'>"+
     "    </editor>"+
     "  </vbox>"+
     "  </window>"+
     "</dialogs>"

LoadFont(1, "Arial", 6)
SetGadgetFont(#PB_Default, FontID(1))

xmlGUI = ParseXML(#PB_Any, XML$)
If xmlGUI
  If XMLStatus(xmlGUI) = #PB_XML_Success
    dlgGUI = CreateDialog(#PB_Any)
    If dlgGUI
      If OpenXMLDialog(dlgGUI, xmlGUI, "myWindow")
          Define button = DialogGadget(dlgGUI, "but")          
          x = GadgetX(button)
          y = GadgetY(button)
          w = GadgetWidth(button)
          h = 12
          FreeGadget(button)
          ButtonGadget(button,x,y,w,h,"")
          
          Define string = DialogGadget(dlgGUI, "text")          
          x = GadgetX(string)
          y = GadgetY(string)
          w = GadgetWidth(string)
          h = 12
          FreeGadget(string)
          StringGadget(string,x,y,w,h,"")
;         SetGadgetFont(#Button1, FontID(1))
;         SetGadgetFont(#Text1, FontID(1))
;         SetGadgetFont(#Editor1, FontID(1))
       
        myResize()
        BindEvent(#PB_Event_SizeWindow, @myResize())
       
        Repeat
        Until WaitWindowEvent()=#PB_Event_CloseWindow
               
      Else
        Debug "Fehler in der Dialog-Definition: " + DialogError(dlgGUI)
      EndIf
    Else
      Debug "Dialog konnte nicht erstellt werden!"
    EndIf
  Else
    Debug "XML Fehler: " + XMLError(xmlGUI)
    Debug "           in Zeile " + Str(XMLErrorLine(xmlGUI)) + " an Position " + Str(XMLErrorPosition(xmlGUI))
  EndIf
  FreeXML(xmlGUI)
Else
  Debug "XML$ konnte gelesen werden."
  End
EndIf
Egypt my love
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Wrong gadget size with dialog library?

Post by Lord »

Hi RASHAD!
RASHAD wrote:...
Next is a workaround not perfect specially with resizing
...
Yes, without resizing the window, the button and the
string gadget have the right width, but the box does'nt
have the right hight.
After window resize everything is messed up again.
Image
Post Reply