TabBarGadget - Tabs like in a browser

Share your advanced PureBasic knowledge/code with the community.
spacebuddy
Enthusiast
Enthusiast
Posts: 346
Joined: Thu Jul 02, 2009 5:42 am

Re: TabBarGadget - Tabs like in a browser

Post by spacebuddy »

I am trying to display an image in the TabBarGadget, here is my code
SetTabBarGadgetItemImage( #TabBarGadget, 0, CatchImage(#Image_Image_18, ?Image_Image_18))


I have UsePNGImageDecoder() declared since it is a .png file, but the image does not get displayed on the tab :shock:
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by STARGÅTE »

I have no problem with SetTabBarGadgetItemImage.
But you have to use the ImageID (not the Image number), I don't know if CatchImage() returns an ID ...
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: TabBarGadget - Tabs like in a browser

Post by netmaestro »

The CatchImage code as posted will return an ID and not the #. If it isn't working you should isolate the CatchImage line and verify that it is indeed returning a handle and not failing. If it's returning 0 you could try supplying the optional length parameter.
Gee, just what a need, a comedian.
What am I missing here? The tabs in the IDE are courtesy of STARGATE's TabBarGadget, Bisonte was just pointing out a fact - right? Or did something go over my head?
BERESHEIT
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: TabBarGadget - Tabs like in a browser

Post by Derren »

I guess he wanted a native TabBarGadget as part of the Purebasic command set (instead of a 3rd party lib)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: TabBarGadget - Tabs like in a browser

Post by Fangbeast »

What am I missing here? The tabs in the IDE are courtesy of STARGATE's TabBarGadget, Bisonte was just pointing out a fact - right? Or did something go over my head?
Yes, right over your head because you are shorter than me. (I saw a bald spot!! And a bird's nest??? ) It was easy enough to understand that I meant included as a component for programmers to access. heh, heh, heh, heh.
Amateur Radio, D-STAR/VK3HAF
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: TabBarGadget - Tabs like in a browser

Post by netmaestro »

This is even better than a native gadget. It is a) good enough for Fred and b) complete with source code so you can tweak/upgrade it yourself. And I sprayed my bald spot, so you were lying when you said you saw it!
BERESHEIT
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: TabBarGadget - Tabs like in a browser

Post by Fangbeast »

This is even better than a native gadget.
No, a native pb gadget with pb commands would be better:):) PBISE the heck out of good stuff like that!!! :):):):)

I claim copyright over the term PBISE than you very much.
Complete with source code so you can tweak/upgrade it yourself.
Good code like that would be nice to be native, it's so nice to have. Being in the visual designer would be even betetr for bad old eyes.
And I sprayed my bald spot, so you were lying when you said you saw it!
Thank you so much for making me fall out of the chair snorting mouthwash through both nostrils and squich the can!!

P.S. Why did you leave that hamster tatto on the spray?
Amateur Radio, D-STAR/VK3HAF
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by falsam »

STARGÅTE Thank you for this great code.

I have one feature request : A function to change the background color of the tabbargadget.
Example :

Code: Select all

SetTabBarGadetColor(Gadget.i, Color.i)
Snippet code

Code: Select all

XIncludeFile "TabBarGadget.pbi"

Enumeration
  #MainForm
  #TB
EndEnumeration

Procedure OnTabBarClick()
  
  Protected Position.i
  Static Number.i = 3
  
  Select EventType()      
    Case #TabBarGadget_EventType_Change
      Debug "selected item changed, now at position "+Str(GetTabBarGadgetItemPosition(EventGadget(), #TabBarGadgetItem_Event))
      
  EndSelect
  
EndProcedure

OpenWindow(#MainForm, 0, 0, 800, 600, "TabBarGadget test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowColor(#MainForm, RGB(210, 180, 140))

;I have one feature request : A function to change the background color of the tabbargadget. 
;Example : SetTabBarGadetColor(Gadget.i, Color.i)
TabBarGadgetInclude\TabBarColor = RGB(210, 180, 140) ;Comment this line To see the difference

TabBarGadget(#TB, 10, 60, WindowWidth(#MainForm)-20, 30, #TabBarGadget_CloseButton, #MainForm)
  AddTabBarGadgetItem(#TB, #PB_Default, "Any tab 1")
  AddTabBarGadgetItem(#TB, #PB_Default, "Any tab 2")
  AddTabBarGadgetItem(#TB, #PB_Default, "Any tab 3")
SetTabBarGadgetState(#TB, 0)

ContainerGadget(-1, 5, 90, WindowWidth(#MainForm)-10, 500)
CloseGadgetList()

BindGadgetEvent(#TB, @OnTabBarClick())

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Thanks :wink:

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by falsam »

sorry I just saw help : http://help.unionbytes.de/tbg/Configuration/

Realy a good job.

Thanks.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by STARGÅTE »

Yes, i have a configuration structure, but these settings are for all tab bar gadgets.
It is a good request to set the colors (background, border and so on) individually for each gadget.

I will implement it, if I have time.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by falsam »

Question about resize TabBarGadget : Is this code correct ?

Code: Select all

  ResizeGadget(#TB, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-20, #PB_Ignore)
  SetTabBarGadgetAttribute(#TB, #PB_Ignore, WindowWidth(#MainForm)-20)
■ Snippet code

Code: Select all

XIncludeFile "TabBarGadget.pbi"

Enumeration Font
  #FontGlobal
EndEnumeration

Enumeration Window
  #MainForm
  #PopupMenu
EndEnumeration

Enumeration Gadget
  #TB
  #Container
EndEnumeration

Declare Start()
Declare OnTabBarClick()
Declare OnResize()
Declare OnExit()

Start()

Procedure Start()
  LoadFont(#FontGlobal, "", 10)
  SetGadgetFont(#PB_Default, FontID(#FontGlobal))
  OpenWindow(#MainForm, 0, 0, 800, 600, "TabBarGadget Test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
  SetWindowColor(#MainForm, RGB(245, 222, 179))
  
  ;Tabbargadget. 
  TabBarGadgetInclude\TabBarColor = GetWindowColor(#MainForm)
  
  TabBarGadget(#TB, 10, 60, WindowWidth(#MainForm)-20, 40, #TabBarGadget_PopupButton, #MainForm)
  AddTabBarGadgetItem(#TB, #PB_Default, "Any tab 1")
  AddTabBarGadgetItem(#TB, #PB_Default, "Any tab 2")
  AddTabBarGadgetItem(#TB, #PB_Default, "Any tab 3")
  SetTabBarGadgetState(#TB, 0) ;Set active panel
  
  SetTabBarGadgetItemColor(#TB, 0, #PB_Gadget_BackColor, RGB(255, 255, 255) )
  SetTabBarGadgetItemColor(#TB, 1, #PB_Gadget_BackColor, RGB(210, 180, 140) )
  SetTabBarGadgetItemColor(#TB, 2, #PB_Gadget_BackColor, RGB(210, 180, 140) )
  
  ;Container
  ContainerGadget(#Container, 5, 100, WindowWidth(#MainForm) - 10,  WindowHeight(#MainForm) - 120)
  CloseGadgetList()
  
  ;PoppupButton Menu
  CreatePopupMenu(#PopupMenu)
  MenuItem(0, "Setup")
  MenuItem(1, "Exit")
     
  ;Trigger
  BindGadgetEvent(#TB, @OnTabBarClick())
  BindMenuEvent(#PopupMenu, 1, @OnExit())
  BindEvent(#PB_Event_SizeWindow, @OnResize())
  BindEvent(#PB_Event_CloseWindow, @OnExit())
  
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure OnTabBarClick()
  Static OlDPosition.i
  Protected Position.i = GetTabBarGadgetItemPosition(EventGadget(), #TabBarGadgetItem_Selected)
  
  Select EventType()
    Case #TabBarGadget_EventType_PopupButton
      DisplayPopupMenu(#PopupMenu, WindowID(#MainForm))  
      
    Case #TabBarGadget_EventType_Change
      SetTabBarGadgetItemColor(#TB, OlDPosition, #PB_Gadget_BackColor, RGB(210, 180, 140) )
      SetTabBarGadgetItemColor(#TB, Position, #PB_Gadget_BackColor, RGB(255, 255, 255) )    
      OlDPosition = Position  
  EndSelect
  
EndProcedure

Procedure OnResize()
  ;Resize tabbargadget
  ResizeGadget(#TB, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-20, #PB_Ignore)
  SetTabBarGadgetAttribute(#TB, #PB_Ignore, WindowWidth(#MainForm)-20)
  
  ;Resize container
  ResizeGadget(#Container, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-10, WindowHeight(#MainForm) - 120)
EndProcedure

Procedure OnExit()
  End
EndProcedure
Greetings ... falsam

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by STARGÅTE »

ResizeGadget() is sufficient, but you have to call UpdateTabBarGadget(Gadget.i) to update the drawing:

Code: Select all

Procedure OnResize()
  ;Resize tabbargadget
  ResizeGadget(#TB, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-20, #PB_Ignore)
  UpdateTabBarGadget(#TB)
  
  ;Resize container
  ResizeGadget(#Container, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-10, WindowHeight(#MainForm) - 120)
EndProcedure
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by falsam »

Ok. Thanks for your help and your online documentation.

:arrow: http://help.unionbytes.de/tbg/

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: TabBarGadget - Tabs like in a browser

Post by kenmo »

Hi STARGATE,

I'm getting TabBarGadget freezes on MacOS 10.12 Sierra. Wondering if you have any advice.

- My program has one TabBar
- If all the tabs fit, I can drag the tabs around with no problem
- If the tabs DON'T fit (left and right arrows appear), then when I start to drag a tab left/right, it freezes the program
- Usually I have to kill it with the debugger
- Sometimes, the debugger catches it on this line in TabBarGadget_Timer()

Code: Select all

PostEvent(#PB_Event_Gadget, \TabBarGadget\Window, \TabBarGadget\Number, #TabBarGadget_EventType_Pushed, \Type)
The error is
nextEventMatchingMask should only be called from the Main Thread!
Any ideas? Event bug in PB? I am going to update the OS to 10.12.1 and see what happens.


EDIT: Just saw this post, looks like Xcode 8 broke this
http://www.purebasic.fr/english/viewtop ... tchingMask
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: TabBarGadget - Tabs like in a browser

Post by wombats »

Unless I am missing something, I cannot find how you would identify the tab a user right clicked on. Does anyone know?
Post Reply