ButtonImageGadget disappears

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

ButtonImageGadget disappears

Post by Lord »

Hello everyone!

I just stumbled over this:
I've got 2 Button in a ToolBar. One ButtonGadget and one
ImageButtonGadget.

If I leave the window, enter it again an press one of the
following buttons, the ButtonImageGadget disappears:
TAB, SHIFT left, CTRL left, ALT,
ALT Gr, CTRL right, SHIFT right

The button reappears, if I hoover over the button.

Why disappears the ImageButton and how can I prevent
this?

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
EndEnumeration

Enumeration
  #Toolbar
EndEnumeration

Enumeration
  #myImgButton
  #myNrmButton
EndEnumeration

Define Quit.i, Event.i

OpenWindow(#MainWindow, 10, 10, 300, 300, "Test")

CreateToolBar(#Toolbar, WindowID(#MainWindow))

ButtonImageGadget(#myImgButton, WindowWidth(#MainWindow)-30, 1, 24, 24, 0, #PB_Button_Toggle)
SetParent_(GadgetID(#myImgButton), ToolBarID(#Toolbar))

ButtonGadget(#myNrmButton, WindowWidth(#MainWindow)-60, 1, 24, 24, "", #PB_Button_Toggle)
SetParent_(GadgetID(#myNrmButton), ToolBarID(#Toolbar))


Quit=0

Repeat
Event=WaitWindowEvent()
Select Event
    Case #PB_Event_CloseWindow
      Quit=#True
  EndSelect
Until Quit

End

Image
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: ButtonImageGadget disappears

Post by Lord »

I did some more testing.

It seems, that there has been something changed since PB v5.0,
which causes the above mentioned disappearing of the gadget.

I tested versions 4.51, 4.60, 4.61, 5.0 and 5.11. All with x86 and
x64.

The ButtonImageGadget stays stable with versions 4.51 to 4.61.
In 5.0 and 5.11 (I didn't test 5.1) the gadget disappears.

My system is a Win7, x64 machine.

So the question is wether this is a bug or not. Any recommendations?
Image
User avatar
Kiffi
Addict
Addict
Posts: 1504
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: ButtonImageGadget disappears

Post by Kiffi »

confirmed.

Test1:

* Starting your snippet
* Pressing <Tab>
-> The second buttons doesn't disappears.

Test2:

* Starting your snippet
* Moving the window to the center of my screen
* Pressing <Tab>
-> The second buttons disappears.
* Pressing <Tab> again
-> The second buttons reappears (and stays).

curious...

Greetings ... Kiffi
Hygge
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ButtonImageGadget disappears

Post by RASHAD »

Workaround

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
EndEnumeration

Enumeration
  #Toolbar
EndEnumeration

Enumeration
  #myImgButton
  #myNrmButton
EndEnumeration

Define Quit.i, Event.i

OpenWindow(#MainWindow, 10, 10, 300, 300, "Test")

CreateToolBar(#Toolbar, WindowID(#MainWindow))

ButtonImageGadget(#myImgButton, WindowWidth(#MainWindow)-30, 1, 24, 24, 0, #PB_Button_Toggle)
SetParent_(GadgetID(#myImgButton), ToolBarID(#Toolbar))

ButtonGadget(#myNrmButton, WindowWidth(#MainWindow)-60, 1, 24, 24, "", #PB_Button_Toggle)
SetParent_(GadgetID(#myNrmButton), ToolBarID(#Toolbar))


Quit=0

Repeat
Event=WaitWindowEvent()
Select Event
    Case #PB_Event_CloseWindow
      Quit=#True
    Case #WM_KEYDOWN
        InvalidateRect_(WindowID(0),0,1)  
  EndSelect
Until Quit

End
Egypt my love
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: ButtonImageGadget disappears

Post by Lord »

@ Kiffi
Thanks for your confirmation.

@ Rashad
Thanks for your workaround.
But this doesn't work. At least fo me. The gadget still disappears.

@ all
I did another test in a vmware XP environmet.
I run the exe from my PB v5.11, Win7 system.
There the gadget does not disappear.

So it has to do something with Win7 in conjuction with PB v5.xx.

Can I consider this a bug?
Image
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: ButtonImageGadget disappears

Post by MachineCode »

Lord wrote:Can I consider this a bug?
No, because the team has said in the past that overlapping items are not supported. You're putting buttons over a toolbar. This should be mentioned in the manual, though, so you don't have to find out in the forum like this.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ButtonImageGadget disappears

Post by infratec »

Hi,

it's not only a Win7 problem.
I can confirm this behaviour for Win XP 32bit.

If it is a bug or not ....
I think only Fred, who knows the internals, can decide if it is a bug or not.

Bernd
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ButtonImageGadget disappears

Post by netmaestro »

Use ToolBarImageButton() with the toggle flag, it's supported and will work.
BERESHEIT
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: ButtonImageGadget disappears

Post by Lord »

netmaestro wrote:Use ToolBarImageButton() with the toggle flag, it's supported and will work.
I know. But how can I place the button to the far right
and keep it there when resizing the window?
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: ButtonImageGadget disappears

Post by ts-soft »

Workaround:
Use a ContainerGadget and no Toolbar. Add your buttons with:
http://www.purebasic.fr/english/viewtop ... 12&t=53623
but Toogle is not supported!

Greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Re: ButtonImageGadget disappears

Post by rrpl »

Lord wrote: I know. But how can I place the button to the far right
and keep it there when resizing the window?

Code: Select all

EnableExplicit
Global Window_0,Container_0,ButtonImage_0, ButtonImage_1

Procedure OpenWindow_0()
  Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
  Container_0 = ContainerGadget(#PB_Any,WindowWidth(Window_0)-60, 0, 60, 25)
  ButtonImage_0 = ButtonImageGadget(#PB_Any, 0, 1, 24, 24, 0,#PB_Button_Toggle)
  ButtonImage_1 = ButtonImageGadget(#PB_Any, 30, 1, 24, 24, 0,#PB_Button_Toggle)
  CloseGadgetList()
EndProcedure

Define Quit.i, Event.i

OpenWindow_0()

Quit=0

Repeat
Event=WaitWindowEvent()
Select Event
    Case #PB_Event_CloseWindow
      Quit=#True
    Case #PB_Event_SizeWindow 
      ResizeGadget(Container_0,WindowWidth(Window_0)-60,#PB_Ignore,#PB_Ignore,#PB_Ignore)
  EndSelect
Until Quit

End
"What you are is what you have been. What you’ll be is what you do now.” -Buddha
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: ButtonImageGadget disappears

Post by Lord »

Hi rrpl!

Thanks for your reply.

With your snippet the button stays on the window. Thats right.

But the problem was a ButtonImageGadget on a toolbar.
I already tried a ContainerGadget:
EnableExplicit

Enumeration
#myWindow
EndEnumeration

Enumeration
#myToolbar
EndEnumeration

Enumeration
#myContainer
#myButton1
#myButton2
EndEnumeration

Define Quit.i, Event.i


OpenWindow(#myWindow, 0, 0, 600, 400, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
CreateToolBar(#myToolbar, WindowID(#myWindow))
ToolBarStandardButton(#myToolbar,#PB_ToolBarIcon_New)
ContainerGadget(#myContainer,WindowWidth(#myWindow)-60, 0, 60, 25)
ButtonImageGadget(#myButton1, 0, 1, 24, 24, 0,#PB_Button_Toggle)
ButtonImageGadget(#myButton2, 30, 1, 24, 24, 0,#PB_Button_Toggle)
CloseGadgetList()
SetParent_(GadgetID(#myContainer), ToolBarID(#myToolbar))


Quit=0

Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_SizeWindow
ResizeGadget(#myContainer,WindowWidth(#myWindow)-60,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit

End
I think, I have to fall back to PB v4.61. Even if I loose PostEvent() :( , but
get also rid of autocasting :D .
Image
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Re: ButtonImageGadget disappears

Post by rrpl »

You could make the rest of the toolbar out of gadgets also, but only if it suits your purpose.

Code: Select all

EnableExplicit

Enumeration
#myWindow
EndEnumeration

Enumeration
#myContainer
#myButton0
#myButton1
#myButton2
EndEnumeration

Define Quit.i, Event.i

OpenWindow(#myWindow, 0, 0, 600, 400, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
ButtonImageGadget(#myButton0, 1, 1, 24, 24, 0,#PB_Button_Toggle)
ContainerGadget(#myContainer,WindowWidth(#myWindow)-60, 0, 60, 25)
ButtonImageGadget(#myButton1, 0, 1, 24, 24, 0,#PB_Button_Toggle)
ButtonImageGadget(#myButton2, 30, 1, 24, 24, 0,#PB_Button_Toggle)
CloseGadgetList()


Quit=0

Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_SizeWindow
  ResizeGadget(#myContainer,WindowWidth(#myWindow)-60,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Case #PB_Event_CloseWindow
Quit=#True
  
EndSelect
Until Quit

End
Must admit I have used the same toolbar/gadgets combination before in my own apps, so its a shame if it no longer works properly.
"What you are is what you have been. What you’ll be is what you do now.” -Buddha
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: ButtonImageGadget disappears

Post by Lord »

@ts-soft:
Sorry ts-soft, I didn't want to ignore you.
I just didn't notice your posting.
ts-soft wrote:Workaround:
Use a ContainerGadget and no Toolbar. Add your buttons with:
http://www.purebasic.fr/english/viewtop ... 12&t=53623
but Toogle is not supported!

Greetings - Thomas
That would be a almost a complete rewrite of a grown program.
And toggle ist a must. Thanks anyway.

@rrpl:
Hi rrpl!
rrpl wrote:You could make the rest of the toolbar out of gadgets also, but only if it suits your purpose.
...
Must admit I have used the same toolbar/gadgets combination before in my own apps, so its a shame if it no longer works properly.
Thanks for your recommendations, but I think I will stick
with PB v4.61 for this program. And yes, it is a shame,
also because a "normal" ButtonGadget still works that way.
Image
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: ButtonImageGadget disappears

Post by Lord »

I couldn't resist. :D

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
  #ButtonWindow
EndEnumeration

Enumeration
  #xImage
  #oImage
EndEnumeration

Enumeration
  #Toolbar
  #TBB1
  #TBB2
  #TBB3
EndEnumeration

Enumeration
  #myImageButton
EndEnumeration

Procedure MakeImages()
  CreateImage(#xImage, 24, 24)
  StartDrawing(ImageOutput(#xImage))
  Box(0, 0, 24, 24, $F0F0F0)
  LineXY(0,0, 23,23, $0000FF)
  LineXY(0,23, 23,0, $0000FF)
  StopDrawing()
  CreateImage(#oImage, 24, 24)
  StartDrawing(ImageOutput(#oImage))
  Box(0, 0, 24, 24, $F0F0F0)
  DrawingMode(#PB_2DDrawing_Outlined)
  Circle(12, 12, 4, $0000FF)
  StopDrawing()
EndProcedure
Procedure PinWindow(hWnd, Event, wParam, lParam)
  If Event = #WM_WINDOWPOSCHANGED
    ResizeWindow(#ButtonWindow, 
                 WindowX(#MainWindow, #PB_Window_InnerCoordinate)+WindowWidth(#MainWindow)-30,
                 WindowY(#MainWindow, #PB_Window_InnerCoordinate)+2,
                 #PB_Ignore, #PB_Ignore)
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure 


MakeImages(); Because I want to use ButtonImageGadget()

OpenWindow(#MainWindow, 10, 10, 300, 300, "",#PB_Window_SizeGadget|#PB_Window_SystemMenu)

CreateToolBar(#Toolbar, WindowID(#MainWindow))
ToolBarStandardButton(#TBB1, #PB_ToolBarIcon_New)
ToolBarStandardButton(#TBB2, #PB_ToolBarIcon_Open)
ToolBarStandardButton(#TBB3, #PB_ToolBarIcon_Save)

OpenWindow(#ButtonWindow,
           WindowX(#MainWindow, #PB_Window_InnerCoordinate)+WindowWidth(#MainWindow)-30,
           WindowY(#MainWindow, #PB_Window_InnerCoordinate)+2,
           24, 24,"", #PB_Window_BorderLess, WindowID(#MainWindow))
ButtonImageGadget(#myImageButton, 0, 1, 24, 24, ImageID(#oImage), #PB_Button_Toggle)
SetGadgetAttribute(#myImageButton, #PB_Button_PressedImage, ImageID(#xImage))
WindowBounds(#MainWindow, GadgetWidth(#myImageButton)+4+#TBB3*24, GadgetHeight(#myImageButton)+4, #PB_Ignore, #PB_Ignore)

SetWindowCallback(@PinWindow(), #MainWindow); 'synchronize' #ButtonWindow with #MainWindow


Define Quit.i=#False
Define Event.i
Define EventGadget.i
Define EventType.i

Repeat
Event=WaitWindowEvent()
EventGadget=EventGadget()
EventType=EventType()

Select Event
  Case #PB_Event_Gadget
    Select EventGadget
      Case #myImageButton
        SetActiveWindow(#MainWindow)
        Select GetGadgetState(#myImageButton)
          Case 0
            ; Do what you want
          Case 1
            ;Do what you want
        EndSelect
    EndSelect
  Case #PB_Event_CloseWindow
    Quit=#True
  EndSelect
Until Quit

End
This works for me, as it did before PB v5.x.
The only(?) annoyance is the 'flash' of the main window,
when the button is pressed.
Image
Post Reply