Re: DynamicDialogs - komplexe dynamische GUIs einfach erstel
Verfasst: 02.03.2016 01:11
@PureLust: Planst du eigentlich auch eine Unterstützung von verschiedenen Fonts in den Dialogen? (für mich z.B. nützlich bei TextGadgets, die ich als Überschriften oder Beschriftung von weiteren GUI-Elementen verwende)
Wenn ja, gibt es ja evtl. die Möglichkeit einen optionalen Parameter 'FontID' einzuführen. Und wenn dieser Wert gültig, d.h. ein abweichender Font angegeben, ist, dann könnte der Dialog-Generator automatisch den notwendigen XML-Code ergänzen.
Ansonsten ist dies sicher auch "händisch" durch Befüllung des 'XMLParam$' Parameters möglich, habe es noch nicht probiert.
Aktuell nutze ich in meinem händisch erstelltem XML-Code die folgenden selbst erstellten "Hilfs"-Funktionen. Vielleicht sind dir diese nützlich, falls du Unterstützung abweichender Fonts tatsächlich einbauen möchtest....
Der nachfolgende Code ist nicht direkt lauffähig, da ich "nur" die Funktionen aus meinem Projekt zusammenkopiert habe:
Was für mich weniger interessant, sind besondere Makro-Funktionen o.ä., die das Einrücken erleichtern.
Ich komme gut und ausreichend mit dem händischen Einrücken der "DynamicDialogs-Befehle" zurecht, und bin schon froh, dass im generierten XML-Code dem Testen/Debuggen wegen ordentliche Einrückung automatisch dabei ist...
Ich kann mich nur wiederholen: herzlichen Dank für deine Mühe!
PS: Wo bleibt eigentlich die Veröffentlichung im engl. Forum?
Wenn ja, gibt es ja evtl. die Möglichkeit einen optionalen Parameter 'FontID' einzuführen. Und wenn dieser Wert gültig, d.h. ein abweichender Font angegeben, ist, dann könnte der Dialog-Generator automatisch den notwendigen XML-Code ergänzen.
Ansonsten ist dies sicher auch "händisch" durch Befüllung des 'XMLParam$' Parameters möglich, habe es noch nicht probiert.
Aktuell nutze ich in meinem händisch erstelltem XML-Code die folgenden selbst erstellten "Hilfs"-Funktionen. Vielleicht sind dir diese nützlich, falls du Unterstützung abweichender Fonts tatsächlich einbauen möchtest....
Der nachfolgende Code ist nicht direkt lauffähig, da ich "nur" die Funktionen aus meinem Projekt zusammenkopiert habe:
Code: Alles auswählen
; First we create the 1x1 pixel image for later testing the text width with GetTextWidth()....
If Not CreateImage(#Image_GetTextSize, 1, 1)
Debug "Can't create 1x1 image for testing text width later..."
EndIf
Procedure GetTextWidth(text$, FontID = #Font_Standard, AddAdditionalGadgetPixels = #True)
; This function has the purpose to check, how the width (in pixel) of a given text is.
; As the 2nd and 3rd parameters are optional, as standard the regular system-font
; (FontID = #Font_Standard) will be used, and there will be added an additional
; pixel size to the calculated text-width for using the returned value with gadgets.
; The standard of this parameter is #True, as in most cases the needed width of a
; gadget (TextGadget, HyperlinkGadget,...) is needed. In other cases (e.g. for
; calculating the pure text-width a listicon column need to have...) this parameter
; need to be set to #False.
Protected width
If StartDrawing(ImageOutput(#Image_GetTextSize))
If FontID <> #Font_Standard
DrawingFont(FontID(FontID))
Else
DrawingFont(GetGadgetFont(#PB_Default))
EndIf
width = TextWidth(text$)
StopDrawing()
Else
Debug "StartDrawing() failed - can't check for text width!"
EndIf
If AddAdditionalGadgetPixels = #True
;CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
; width * 1.05
;CompilerEndIf
width + 15 ; currently (Aug. 201%) this value if for testing only, it need to be adapted for each OS and probably a factor is needed...
EndIf
;Debug text$ + "==> width = " + Str(width)
ProcedureReturn width
EndProcedure
Procedure GetTextHeight(text$, FontID = #Font_Standard)
Protected height
If StartDrawing(ImageOutput(#Image_GetTextSize))
If FontID <> #Font_Standard
DrawingFont(FontID(FontID))
Else
DrawingFont(GetGadgetFont(#PB_Default))
EndIf
height = TextHeight(text$)
StopDrawing()
Else
Debug "StartDrawing() failed - can't check for text width!"
EndIf
ProcedureReturn height
EndProcedure
Procedure.s DialogGadgetTextSize(text$, FontID, margin=0)
; This function is a combination of the two other functions, and will give
; a XML containing both width and height parameters!
Protected width, height
width = GetTextWidth(text$, FontID) + margin ; we use another self-written function to calculate the width value
height = GetTextHeight(text$, FontID) + margin ; we use another self-written function to calculate the height value
; ... and now we return a XML string with both values:
ProcedureReturn " width='"+Str(width)+"' height='"+Str(height)+"' "
EndProcedure
;-------------------------------
; eine exemplarische Zeile aus dem XML-Code:
" <text name='WHNameTitle' text='WHeritageName'" + DialogGadgetTextSize(Language("WHeritageName"), #Font_SmallBold, 3) + " />" + LF$ +
;-------------------------------
Procedure SetDialogGadgetTitleFont(Dialog, GadName$, FontType = #Font_SmallBold)
; The purpose of this function is, to check if a gadget - created via XML dialog - is available,
; and if yes set the smaller 'title' font for it. This is used to shorten code like this example:
; gad = DialogGadget(dialog, "WHNameTitle")
; SetGadgetFont(gad, FontID(#Font_SmallBold))
;
; Parameters:
; dialog = dialog number previously got (to be given as parameter from calling procedure)
; GadName$ = name of the gadget created in the XML description
; FontType = can be given as parameter (e.g. for bigger fonts like #Font_Middle or #Font_Big),
; or the standard (#Font_SmallBold) like used for all section titles will be used
;
Protected gad
gad = DialogGadget(Dialog, GadName$)
If gad > -1
SetGadgetFont(gad, FontID(FontType))
EndIf
EndProcedure
; nach der erfolgreichen Dialog-/GUI-Erstellung verwendete Funktion:
SetDialogGadgetTitleFont(dialog, "WHNameTitle")
Was für mich weniger interessant, sind besondere Makro-Funktionen o.ä., die das Einrücken erleichtern.
Ich komme gut und ausreichend mit dem händischen Einrücken der "DynamicDialogs-Befehle" zurecht, und bin schon froh, dass im generierten XML-Code dem Testen/Debuggen wegen ordentliche Einrückung automatisch dabei ist...
Ich kann mich nur wiederholen: herzlichen Dank für deine Mühe!
PS: Wo bleibt eigentlich die Veröffentlichung im engl. Forum?