It is currently Sun May 31, 2020 1:54 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Wed May 20, 2020 8:44 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1831
Location: Germany (Saxony, Deutscheinsiedel)
I made a little example to show the selecting of only one button (which is toggled then, previously toggled buttons loose this state).
Code:
; ButtonEx example:
; Select one button and set it in 'Toggle' (pressed) mode, but release other buttons which were toggled/pressed before...
; by André
; last update: 20th May 2020

XIncludeFile "ButtonExModule.pbi"

UsePNGImageDecoder()

#Window = 0

Enumeration 1
  #ButtonImg1
  #ButtonImg2
  #ButtonImg3
  #Image
  #Font
EndEnumeration

LoadFont(#Font, "Arial", 9, #PB_Font_Bold)
LoadImage(#Image, "Delete.png")

If OpenWindow(#Window, 0, 0, 450, 80, "ButtonEx: Select one button...", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
 
  ButtonEx::Gadget(#ButtonImg1, 10, 20, 100, 25, "Delete 1", ButtonEx::#MacOS, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
  ButtonEx::AddImage(#ButtonImg1, #Image, 16, 16, ButtonEx::#Left)
 
  ButtonEx::Gadget(#ButtonImg2, 120, 20, 100, 25, "Delete 2", ButtonEx::#MacOS, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
  ButtonEx::AddImage(#ButtonImg2, #Image, 16, 16, ButtonEx::#Right)
  ButtonEx::SetFont(#ButtonImg2, #Font)
 
  ButtonEx::Gadget(#ButtonImg3, 230, 20, 100, 25, "Delete 3", 0, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
  ButtonEx::AddImage(#ButtonImg3, #Image, 16, 16, ButtonEx::#Right)
  ButtonEx::SetFont(#ButtonImg3, #Font)
  ButtonEx::SetColor(#ButtonImg3, ButtonEx::#BackColor, $AADDDD)
  ButtonEx::SetColor(#ButtonImg3, ButtonEx::#BorderColor, $FF0000)
 
 
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case ButtonEx::#Event_Gadget ; works with or without EventType()
        Select EventGadget()
          Case #ButtonImg1
            Debug "Delete1 button pressed"
            If ActiveButton > 0
              ;Debug "Last selected button: " + ActiveButton
              ;Debug "State of this button: " + ButtonEx::GetState(ActiveButton)
              ButtonEx::SetState(ActiveButton, 0)   ; reset the 'Toggle' state for the last selected button
            EndIf
            ButtonEx::SetState(#ButtonImg1, ButtonEx::#Toggle)
            ActiveButton = #ButtonImg1
          Case #ButtonImg2
            Debug "Delete2 button pressed"
            If ActiveButton > 0
              ;Debug "Last selected button: " + ActiveButton
              ;Debug "State of this button: " + ButtonEx::GetState(ActiveButton)
              ButtonEx::SetState(ActiveButton, 0)   ; reset the 'Toggle' state for the last selected button
            EndIf
            ButtonEx::SetState(#ButtonImg2, ButtonEx::#Toggle)
            ActiveButton = #ButtonImg2
          Case #ButtonImg3
            Debug "Delete3 button pressed"
            If ActiveButton > 0
              ;Debug "Last selected button: " + ActiveButton
              ;Debug "State of this button: " + ButtonEx::GetState(ActiveButton)
              ButtonEx::SetState(ActiveButton, 0)   ; reset the 'Toggle' state for the last selected button
            EndIf
            ButtonEx::SetState(#ButtonImg3, ButtonEx::#Toggle)
            ActiveButton = #ButtonImg3
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
 
  CloseWindow(#Window)
EndIf

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Thu May 21, 2020 8:08 am 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 1262
Location: Germany
Update:
  • Added: ButtonEx::CombineToogle()
  • Added: ButtonEx::Free()

_________________
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Thu May 21, 2020 8:05 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1831
Location: Germany (Saxony, Deutscheinsiedel)
Thorsten1867 wrote:
Update:
  • Added: ButtonEx::CombineToogle()
  • Added: ButtonEx::Free()

Thank you for this extension, Thorsten! :D

Would you be so kind, to provide a small example how to use the new 'CombineToggle' (you have a little spelling mistake in your command name, I think) modus? Thanks!

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Fri May 22, 2020 9:58 am 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 1262
Location: Germany
Code:
XIncludeFile "ButtonExModule.pbi"

UsePNGImageDecoder()

#Window = 0

Enumeration 1
  #ButtonImg1
  #ButtonImg2
  #ButtonImg3
  #Image
  #Font
EndEnumeration

LoadFont(#Font, "Arial", 9, #PB_Font_Bold)
LoadImage(#Image, "Delete.png")

If OpenWindow(#Window, 0, 0, 450, 80, "ButtonEx: Select one button...", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
 
  ButtonEx::Gadget(#ButtonImg1, 10, 20, 100, 25, "Delete 1", ButtonEx::#MacOS|ButtonEx::#Toggle, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
  ButtonEx::AddImage(#ButtonImg1, #Image, 16, 16, ButtonEx::#Left)
 
  ButtonEx::Gadget(#ButtonImg2, 120, 20, 100, 25, "Delete 2", ButtonEx::#MacOS|ButtonEx::#Toggle, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
  ButtonEx::AddImage(#ButtonImg2, #Image, 16, 16, ButtonEx::#Right)
  ButtonEx::SetFont(#ButtonImg2, #Font)
 
  ButtonEx::Gadget(#ButtonImg3, 230, 20, 100, 25, "Delete 3", ButtonEx::#Toggle, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
  ButtonEx::AddImage(#ButtonImg3, #Image, 16, 16, ButtonEx::#Right)
  ButtonEx::SetFont(#ButtonImg3, #Font)
  ButtonEx::SetColor(#ButtonImg3, ButtonEx::#BackColor, $AADDDD)
  ButtonEx::SetColor(#ButtonImg3, ButtonEx::#BorderColor, $FF0000)
 
  ButtonEx::CombineToggle(#ButtonImg1, "Delete")
  ButtonEx::CombineToggle(#ButtonImg2, "Delete")
  ButtonEx::CombineToggle(#ButtonImg3, "Delete")
 
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case ButtonEx::#Event_Gadget ; works with or without EventType()
        Select EventGadget()
          Case #ButtonImg1
            Debug "Delete1 button pressed"
          Case #ButtonImg2
            Debug "Delete2 button pressed"
          Case #ButtonImg3
            Debug "Delete3 button pressed"
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
 
  CloseWindow(#Window)
EndIf

_________________
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Fri May 22, 2020 8:10 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1831
Location: Germany (Saxony, Deutscheinsiedel)
Thank you, Thorsten for this additional example! :D

It works well, but you need to fix the two spelling error in the ButtonEx module: replace the "old" ButtonEx::CombineToogle() in declaration and procedure with the correct "CombineToggle()" ;-)

When testing the module on MacOS I found a bug:
The round corners on MacOS are painted with black instead of the real (MacOS) window background. Are you able to fix this?
Image

Thank you!

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Mon May 25, 2020 3:32 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue May 01, 2007 3:49 am
Posts: 137
Location: Germany
Great lib; thank you so much!

However, changing the focus of the buttons via tab seems not to work? (Tested with Win10)

_________________
M.Sc. Aerospace Engineering

My Free Setup Creator for Windows | My 3D Ego Shooter made in PB


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] ButtonEx (all OS)
PostPosted: Sat May 30, 2020 11:40 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1831
Location: Germany (Saxony, Deutscheinsiedel)
@XOr: I don't think that ButtonEx supports focus (visible rectangle)... at least for now. Doesn't work on MacOS too.

@All: anyone has an idea, what need to be changed in the ButtonEx module to avoid the black-painted round corners, when using ButtonEx on MacOS with the related flag? (see my screenshot above)
As far as I can see, Thorsten used the code snippets successfully mentioned here: viewtopic.php?f=27&t=75014&p=552167&hilit=nscolor#p552167

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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