Page 3 of 3

Re: [Module] ButtonEx (all OS)

Posted: Wed May 20, 2020 8:44 pm
by Andre
I made a little example to show the selecting of only one button (which is toggled then, previously toggled buttons loose this state).

Code: Select all

; 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

Re: [Module] ButtonEx (all OS)

Posted: Thu May 21, 2020 8:08 am
by Thorsten1867
Update:
  • Added: ButtonEx::CombineToogle()
  • Added: ButtonEx::Free()

Re: [Module] ButtonEx (all OS)

Posted: Thu May 21, 2020 8:05 pm
by Andre
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!

Re: [Module] ButtonEx (all OS)

Posted: Fri May 22, 2020 9:58 am
by Thorsten1867

Code: Select all

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

Re: [Module] ButtonEx (all OS)

Posted: Fri May 22, 2020 8:10 pm
by Andre
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!

Re: [Module] ButtonEx (all OS)

Posted: Mon May 25, 2020 3:32 am
by X0r
Great lib; thank you so much!

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

Re: [Module] ButtonEx (all OS)

Posted: Sat May 30, 2020 11:40 pm
by Andre
@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&hil ... or#p552167

Re: [Module] ButtonEx (all OS)

Posted: Wed Jun 03, 2020 10:29 am
by Thorsten1867
Update: Added: OSX_GadgetColor()

Re: [Module] ButtonEx (all OS)

Posted: Thu Jun 04, 2020 7:24 pm
by Andre
Thorsten1867 wrote:Update: Added: OSX_GadgetColor()
Thank you, Thorsten!

But unfortunately the 'black corner' problem shown above is still present...
Anyone of the MacOS experts can take a look what's still wrong? Thank you in advance! :-)

Re: [Module] ButtonEx (all OS)

Posted: Mon Oct 05, 2020 5:33 pm
by doctorized
Downloaded the latest version and tried this:

Code: Select all

ButtonEx::Gadget(#ButtonML, 345, 20, 120, 100, "Asdfghjkpoiuytreq card", ButtonEx::#MultiLine|ButtonEx::#MacOS, #Window)
LoadFont(#Font_Custom,  "Arial", 11)
ButtonEx::SetFont(#ButtonML,#Font_Custom)
custom font and text width almost the same as the button's width, the text appears a little bit upper than it should be. Any suggestions why?

Re: [Module] ButtonEx (all OS)

Posted: Wed Feb 10, 2021 11:10 pm
by doctorized
I have a window with some buttonEx buttons and I use the following code to attach menu to them:

Code: Select all

MarkIcon = CatchImage(#PB_Any, ?MarkStart, ?MarkEnd - ?MarkStart)
UnMarkIcon = CatchImage(#PB_Any, ?UnMarkStart, ?UnMarkEnd - ?UnMarkStart)
MarkIcon2 = CatchImage(#PB_Any, ?MarkStart, ?MarkEnd - ?MarkStart)
UnMarkIcon2 = CatchImage(#PB_Any, ?UnMarkStart, ?UnMarkEnd - ?UnMarkStart)
For i=0 To 11
	If CreatePopupImageMenu(#Btn_menu1 + i)
      MenuItem(#MenuMark1 + i, "item 1", ImageID(MarkIcon))
      MenuItem(#MenuUnMark1 + i, "item 2", ImageID(MarkIcon))
      MenuBar()
      MenuItem(#MenuMarkNext1 + i, "item 3", ImageID(MarkIcon2))
      MenuItem(#MenuUnMarkNext1 + i, "item 4", ImageID(MarkIcon2))
   EndIf
   ButtonEx::AttachPopupMenu(i,#Btn_menu1 + i)
Next
Is there a better/faster way to attach the menu? Now I am creating a custom menu with RASHAD's code and the code to create and attach the menus is now slow (it takes some seconds instead of a second that was required before). It would be nice to have one menu to attach on every button and get the button id with EventGadget() or something like that. Any suggestions?

Re: [Module] ButtonEx (all OS)

Posted: Tue Sep 14, 2021 5:16 pm
by doctorized
Where did AttachPopupMenu() go?