Utiliser une police avec un Dialog

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

Utiliser une police avec un Dialog

Message par Mesa »

En attendant mieux :

Code : Tout sélectionner

CompilerIf #PB_Compiler_Unicode
  #XmlEncoding = #PB_UTF8
CompilerElse 
  #XmlEncoding = #PB_Ascii
CompilerEndIf

#Dialog = 0
#Xml = 0

Global Arial24

Arial24=LoadFont(1, "Arial", 24) 
If Arial24=0
  Debug "Erreur de police"
  End
EndIf


Procedure.s NewTextWidth(texte$, police=-1, marge=0)
  ;police=-1 => Font sytem
  Protected W
  
  
  If CreateImage(0, 200,200)
    StartDrawing(ImageOutput(0))
    If police <> -1 
      DrawingFont(police)
    EndIf
    W=TextWidth(texte$) + marge
    StopDrawing()
  Else
    Debug "Erreur dans NewTextWidth()"
    End
  EndIf
  FreeImage(0)
  ProcedureReturn "width='"+Str(W)+"' "
EndProcedure

Procedure.s NewTextHeight(texte$, police=-1, marge=0)
  ;police=-1 => Font sytem
  Protected H
  
  If CreateImage(0, 200,200)
    StartDrawing(ImageOutput(0))
    If police <> -1 
      DrawingFont(police)
    EndIf
    H=TextHeight(texte$) + marge
    StopDrawing()
  Else
    Debug "Erreur dans NewTextHeight()"
    End
  EndIf
  FreeImage(0)
  ProcedureReturn "height='"+Str(H)+"' "
EndProcedure


XML$ = "<window id='#PB_Any' name='test' text='test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "  <panel>" +
       "    <tab text='Premier Onglet'>" +
       "      <vbox expand='item:2'>" +
       "        <hbox>" +
       "          <button name='but1' text='Bouton 1' "  +
       NewTextWidth("Bouton 1",  Arial24, 60) +
       NewTextHeight("Bouton 1", Arial24, 60) +
       "           /> " +
       "          <checkbox name='check1' text='Case à cocher 1'/>" +
       "        <singlebox expand='no' align='center,right'>" +
       "          <button name='but2' text='Bouton 2' " + 
       "           /> " +
       "        </singlebox>" +
       "        </hbox>" +
       "        <editor text='Contenu...' height='150'/>" +
       "      </vbox>" +
       "    </tab>" +  
       "  </panel>" +
       "</window>"

;Debug XML$

If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
  
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    
    SetGadgetFont(DialogGadget(#Dialog, "but1"), FontID(1))
    ;SetGadgetText(DialogGadget(#Dialog, "but1"), "azerty")
    
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow 
    
  Else  
    Debug "Erreur de la bibliothèque -Dialog- : " + DialogError(#Dialog)
  EndIf
Else
  Debug "Erreur XML : " + XMLError(#Xml) + " (Ligne: " + XMLErrorLine(#Xml) + ")"
EndIf

Je n'ai pas réussi à coller le bouton 2 à gauche.

Mesa.