It is currently Thu Nov 26, 2020 2:04 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [Done] SetGadgetFont(#Gadget, #PB_Default) don't work
PostPosted: Wed Jun 15, 2016 4:56 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 644
Reset the gadget font on Mac OS don't work.


Top
 Profile  
Reply with quote  
 Post subject: Re: SetGadgetFont(#Gadget, #PB_Default) don't work
PostPosted: Thu Jul 07, 2016 8:21 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14179
Location: France
Please always post a small snippet showing your issue, thanks ! Seems to work here with this code from the help file:

Code:
If OpenWindow(0, 0, 0, 222, 130, "SetGadgetFont", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If LoadFont(0, "Arial", 16)
      SetGadgetFont(#PB_Default, FontID(0))   ; Set the loaded Arial 16 font as new standard
    EndIf
    ButtonGadget(0, 10, 10, 200, 30, "Button - Arial 16")
    SetGadgetFont(#PB_Default, #PB_Default)  ; Set the font settings back to original standard font
    ButtonGadget(1, 10, 50, 200, 30, "Button - standard")
    If LoadFont(1,"Courier",10, #PB_Font_Bold | #PB_Font_Underline)
      SetGadgetFont(#PB_Default, FontID(1))   ; Set the loaded Courier 10 font as new standard
    EndIf
    TextGadget(2, 10, 90, 200, 40, "Bold + underlined Courier 10 Text", #PB_Text_Center)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: SetGadgetFont(#Gadget, #PB_Default) don't work
PostPosted: Thu Jul 07, 2016 9:33 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 644
Sorry! It is the Editor-Gadget:

Code:
#list = 1
#butt = 2
LoadFont(1,"Courier",10, #PB_Font_Bold | #PB_Font_Underline)
 If OpenWindow(0, 0, 0, 322, 190, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    EditorGadget(#list, 8, 8, 306, 133)
    ButtonGadget(#butt, 8, 150, 306, 30, "Change",#PB_Button_Toggle)
    For a = 0 To 5
      AddGadgetItem(#list, a, "Zeile "+Str(a))
    Next
    Repeat
      event = WaitWindowEvent()
      If event = #PB_Event_Gadget And EventGadget() = #butt
        If GetGadgetState(#butt) = 0: SetGadgetFont(#list, #PB_Default): SetGadgetFont(#butt, #PB_Default): EndIf
        If GetGadgetState(#butt) = 1: SetGadgetFont(#list, FontID(1)  ): SetGadgetFont(#butt, FontID(1)  ): EndIf
      EndIf
    Until event = #PB_Event_CloseWindow
  EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: SetGadgetFont(#Gadget, #PB_Default) don't work
PostPosted: Sat Aug 06, 2016 9:16 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1781
Location: Germany
This is a workaround to read the default font name and default font size of the EditorGadget in order to be able to later restore its default font:
Code:
EnableExplicit

Enumeration
  #Editor
  #Button
EndEnumeration

Define EditorDefaultFontName.S
Define EditorDefaultFontSize.CGFloat
Define i.I

If LoadFont(0, "Courier", 10, #PB_Font_Bold | #PB_Font_Underline)
  OpenWindow(0, 0, 0, 200, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(#Editor, 10, 10, 180, 100)
  ButtonGadget(#Button, 10, 120, 180, 25, "Toggle font", #PB_Button_Toggle)
 
  For i = 1 To 7
    AddGadgetItem(#Editor, i, "Line " + Str(i))
  Next
 
  EditorDefaultFontName = PeekS(CocoaMessage(0, CocoaMessage(0, CocoaMessage(0,
    GadgetID(#Editor), "font"), "displayName"), "UTF8String"), -1, #PB_UTF8)
  CocoaMessage(@EditorDefaultFontSize,
    CocoaMessage(0, GadgetID(#Editor), "font"), "pointSize")

  If LoadFont(1, EditorDefaultFontName, Int(EditorDefaultFontSize))
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #PB_Event_Gadget
          If EventGadget() = #Button
            If GetGadgetState(#Button) = 0
              SetGadgetFont(#Editor, FontID(1))
              SetGadgetFont(#Button, #PB_Default)
            Else
              SetGadgetFont(#Editor, FontID(0))
              SetGadgetFont(#Button, FontID(0))
            EndIf
          EndIf
      EndSelect
    ForEver
  EndIf
EndIf

But be aware that this workaround only works correctly if the whole text in the EditorGadget has the same font and size because the font method always returns the font of the first character in the text view's string, or if the text view is empty it returns the font at the insertion point.

However, if the text view is configured to accept rich text, the text view can have several different fonts and it's more complicated to obtain the font and size of a selected range...


Top
 Profile  
Reply with quote  
 Post subject: Re: SetGadgetFont(#Gadget, #PB_Default) don't work
PostPosted: Sat Feb 08, 2020 8:50 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14179
Location: France
Fixed.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye