TabBarGadget - Tabs like in a browser

Share your advanced PureBasic knowledge/code with the community.
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 »

You can identify a right klick with EventType() and #PB_EventType_RightClick.
After this, you can use GetTabBarGadgetItemPosition(EventGadget(), #TabBarGadgetItem_Event), to identify the position of tab.
You can find an example of event handling here: Event types
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
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: TabBarGadget - Tabs like in a browser

Post by Niffo »

Here is my contribution to TabBarGadget : Added SetTabBarGadgetBackColor() and GetTabBarGadgetBackColor to be able to force the background color.

http://niffo.free.fr/TabBarGadget/
Niffo
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 »

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.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: TabBarGadget - Tabs like in a browser

Post by davido »

@Nifo,
Thank you.
DE AA EB
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 »

Thanks Niffo ^-^

➽ 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.
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: TabBarGadget - Tabs like in a browser

Post by wombats »

Hi,

I want to set the current tab after the tabs have all been added, but the first time the event is called, it reports that the current tab is -1 if the event has been called via BindEvent(). However, if the event is handled in the main event loop, it reports the current tab number correctly.

Code: Select all

XIncludeFile "TabBarGadget.pbi"

Enumeration
  #Window
  #Gadget_TabBar
  #Gadget_ListView_BindGadget
  #Gadget_ListView_EventLoop
EndEnumeration

Procedure OnTabBarGadgetChange()
  AddGadgetItem(#Gadget_ListView_BindGadget, -1, "New tab: " + Str(GetTabBarGadgetItemPosition(#Gadget_TabBar, #TabBarGadgetItem_Event)))
EndProcedure

OpenWindow(#Window, 0, 0, 800, 450, "TabBarGadget", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)

TabBarGadget(#Gadget_TabBar, 0, 0, WindowWidth(#Window), #TabBarGadget_DefaultHeight, #TabBarGadget_None, #Window)

TextGadget(#PB_Any, 10, 40, 100, 20, "BindGadget:")
ListViewGadget(#Gadget_ListView_BindGadget, 10, 60, 100, 300)
TextGadget(#PB_Any, 120, 40, 100, 20, "Event Loop:")
ListViewGadget(#Gadget_ListView_EventLoop, 120, 60, 100, 300)

AddTabBarGadgetItem(#Gadget_TabBar, #PB_Default, "One")
AddTabBarGadgetItem(#Gadget_TabBar, #PB_Default, "Two")
AddTabBarGadgetItem(#Gadget_TabBar, #PB_Default, "Three")

BindGadgetEvent(#Gadget_TabBar, @OnTabBarGadgetChange(), #TabBarGadget_EventType_Change)

SetTabBarGadgetState(#Gadget_TabBar, 1)
PostEvent(#PB_Event_Gadget, #Window, #Gadget_TabBar, #TabBarGadget_EventType_Change)

Repeat
  
  Define event = WaitWindowEvent()
  
  If EventType() = #TabBarGadget_EventType_Change
    AddGadgetItem(#Gadget_ListView_EventLoop, -1, "New tab: " + Str(GetTabBarGadgetItemPosition(#Gadget_TabBar, #TabBarGadgetItem_Event)))
  EndIf
  
Until event = #PB_Event_CloseWindow
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 »

Hi wombats,

It seems like it's the order of BindEvent events, as you can see here:

Code: Select all

Procedure ButtonHandler1()
	Debug "ButtonHandler1"
EndProcedure

Procedure ButtonHandler2()
	Debug "ButtonHandler2"
EndProcedure

OpenWindow(0, 100, 100, 200, 90, "Click test", #PB_Window_SystemMenu)

ButtonGadget(0, 10, 10, 180, 30, "Click me")
BindGadgetEvent(0, @ButtonHandler1())
BindGadgetEvent(0, @ButtonHandler2())

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
As you can see, the second defined event is call as first.
That meens, that "your" bind event to the TabBarGadget is called before my event, were I set the EventTab.
So you get -1 in your callback but 0 is the normal loop.

So the problem is how do you use "my" #TabBarGadget_EventType_Change event, if you post it.
____

A workaround for you:

Code: Select all

; use this callback to read the event tab
Procedure OnTabBarGadgetChange()
	AddGadgetItem(#Gadget_ListView_BindGadget, -1, "New tab: " + Str(EventData()))
EndProcedure
;...

; Add the data parameter with the GetTabBarGadgetState()
PostEvent(#PB_Event_Gadget, #Window, #Gadget_TabBar, #TabBarGadget_EventType_Change, GetTabBarGadgetState(#Gadget_TabBar))
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
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: TabBarGadget - Tabs like in a browser

Post by GenRabbit »

This is awesome. Any chance of getting a Module version of it?

I have moved it to work with module. Demo & main file. But I've but screwed up somewhere and have no idea what I have done wrong. :P (around 90% seems to work)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: TabBarGadget - Tabs like in a browser

Post by mestnyi »

STARGÅTE wrote:Hi wombats,

It seems like it's the order of BindEvent events, as you can see here:

Code: Select all

Procedure ButtonHandler1()
	Debug "ButtonHandler1"
EndProcedure

Procedure ButtonHandler2()
	Debug "ButtonHandler2"
EndProcedure

OpenWindow(0, 100, 100, 200, 90, "Click test", #PB_Window_SystemMenu)

ButtonGadget(0, 10, 10, 180, 30, "Click me")
BindGadgetEvent(0, @ButtonHandler1())
BindGadgetEvent(0, @ButtonHandler2())

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
As you can see, the second defined event is call as first.
[/code]
I asked Fred to change the order of the call, but alas. :oops:
viewtopic.php?f=3&t=62603
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: TabBarGadget - Tabs like in a browser

Post by Dude »

Can the TabBarGadget be resized? I don't see a procedure for it in the source? Or am I blind? I need it to match the window's width when the user resizes the window.
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: TabBarGadget - Tabs like in a browser

Post by Niffo »

You can resize the gadget then call UpdateTabBarGadget() ;)
Niffo
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: TabBarGadget - Tabs like in a browser

Post by Dude »

Tried that, but it didn't work. :( Here's my resize code:

Code: Select all

; w and h are the width and height of the resized window, with some extra calcs thrown in.
ResizeGadget(#panel,#PB_Ignore,#PB_Ignore,w-(18*dpi),h-(verticalfactor*1.32)-(35*dpi))
This works perfectly with a PanelGadget, but not the TabBarGadget (even with UpdateTabBarGadget() after it).

Maybe I don't understand how the TabBarGadget is meant to work. I assumed it was a simple drop-in replacement for the PanelGadget? Here's an example of the drop-in changes I made:

Code: Select all

;Global panel=PanelGadget(#panel,10*dpi,43*dpi,0,0)
Global panel=TabBarGadget(#panel,10*dpi,43*dpi,0,0,0,#win_main)

;AddGadgetItem(#panel,-1,"Calendar ",img_cal)
AddTabBarGadgetItem(#panel,-1,"Calendar ",img_cal)
Is this not how it's meant to be used?
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: TabBarGadget - Tabs like in a browser

Post by Niffo »

Unlike PanelGadget(), TabBarGadget() does not handle containers, you have to handle them yourself.
Niffo
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: TabBarGadget - Tabs like in a browser

Post by Dude »

Do you mean I have to put a ContainerGadget inside each TabBarGadget tab, with all gadgets inside those containers?
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: TabBarGadget - Tabs like in a browser

Post by Niffo »

Yes
Niffo
Post Reply