TabBarGadget - Tabs like in a browser

Share your advanced PureBasic knowledge/code with the community.
User avatar
kenmo
Addict
Addict
Posts: 1948
Joined: Tue Dec 23, 2003 3:54 am

Re: TabBarGadget - Tabs like in a browser

Post by kenmo »

Hello STARGATE and TabBarGadget users!

As I mentioned before, I did some very minor cleanup and put the TabBarGadget on GitHub:
- GitHub repo

I have some updates. First, I started a develop branch with STARGATE's recommended changes from this thread:
- develop branch
- See diff/changes

Second, I created another branch called kenmo-mods with lots of changes I've collected over ~6 years of using TabBarGadget
- kenmo-mods branch
- See diff/changes
- Direct link to TabBarGadget.pbi


Here is the log of changes:
Return 24-bit color from GetTabBarGadgetItemColor() (remove alpha)
viewtopic.php?p=549690#p549690

Unbind gadget before freeing it (and free gadget before freeing memory)
viewtopic.php?p=552651#p552651

Don't force EnableExplicit if being Included in another file

Check that StartDrawing() succeeded before drawing

Force a recalculation of TabSize after changing font

Prevent thread+PostEvent issue on Mac PureBasic pre-5.60

Clear references to *Item before removing it

Clear UpdatePosted flag even if StartDrawing() fails

Define RGB constants for default colors

Added more safety checks to Callback and FreeTabBarGadget()

Store the default font ID so it can be reused by SetTabBarGadgetFont()

Added function to change WheelDirection - SetTabBarGadgetGlobalAttribute()

Made MouseWheel action settable (None, Scroll, or Change tab)

Added global DrawDisabled attribute (for batch tab changes)

Add global attributes for MiddleClickForClose and DoubleClickForNew

Added attributes to set the Bar, Border, Face, and Text default colors

Added support for WinAPI DrawText_() for clearer text on some Windows

Added GetTabBarGadgetGlobalAttribute() for the new attributes
Hopefully this is useful to some people :) Now I have a place to track my TabBarGadget mods that aren't comments copied and pasted in various files.
STARGATE maybe you can consider some of these changes for your future official release.
User avatar
STARGÅTE
Addict
Addict
Posts: 1748
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by STARGÅTE »

@kenmo:

Thank you very much for your contribution.
I added the link to the GitHub on the first page.

>>STARGATE maybe you can consider some of these changes for your future official release.
Of course! Regarding "Added support for WinAPI DrawText_() for clearer text on some Windows":
It was also my question to change the whole code to VectorDrawing, what do you think of?
PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 5.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
kenmo
Addict
Addict
Posts: 1948
Joined: Tue Dec 23, 2003 3:54 am

Re: TabBarGadget - Tabs like in a browser

Post by kenmo »

It was also my question to change the whole code to VectorDrawing, what do you think of?
Oh, I guess we have to see. I know VectorDrawing is a lot more powerful.

But I like DrawText_() API because, for me and some others (not everyone?) it makes the text look more like a "native" gadget.
Here are two posts of mine with example images:
viewtopic.php?p=496305#p496305
viewtopic.php?p=474574#p474574


Anyway, you can borrow or not borrow any of those modifications I made :) Some are new functionality, some were for stability/safety.
I finally put them into Git because it gives you a nice history, a nice way to track and see every change, easy to share.

"SetTabBarGadgetGlobalAttribute()" is a little odd, but it's OK for my usage. There's already SetTabBarGadgetAttribute() but I think you're already using all 32 bit flags! :D
Fred
Administrator
Administrator
Posts: 14731
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by Fred »

There is an issue when enable the DPI Aware flag on Windows and having a scaling <> 100%, the gadget size isn't right. To fix it, use DesktopUnscaledX/Y in ResizeGadget()

Code: Select all

If \Attributes & #TabBarGadget_Vertical
  ResizeGadget(\Number, #PB_Ignore, #PB_Ignore, DesktopUnscaledX(Rows*\TabSize+TabBarGadgetInclude\Margin), #PB_Ignore)
Else
  ResizeGadget(\Number, #PB_Ignore, #PB_Ignore, #PB_Ignore, DesktopUnscaledY(Rows*\TabSize+TabBarGadgetInclude\Margin))
EndIf
Default size needs to be adjusted as well

Code: Select all

  \PaddingX                     = DesktopScaledX(6)  ; Space from tab border to text
  \PaddingY                     = DesktopScaledX(5)  ; Space from tab border to text
  \Margin                       = 4                  ; Space from tab to border
  \ImageSpace                   = DesktopScaledX(3)  ; Space from image zu text
  \ImageSize                    = DesktopScaledX(16)
  \CloseButtonSize              = DesktopScaledX(13) ; Size of the close cross
  \CheckBoxSize                 = DesktopScaledX(10)
  \ArrowSize                    = DesktopScaledX(5)  ; Size of the Arrow in the button in navigation
  \ArrowWidth                   = DesktopScaledX(12) ; Width of the Arrow-Button in navigation
  \ArrowHeight                  = DesktopScaledY(18) ; Height of the Arrow-Button in navigation
  \Radius                       = DesktopScaledX(3)  ; Radius of the edge of the tab
Close cross as well

Code: Select all

      If *Item\Disabled
        TabBarGadget_DrawCross(*Item\Layout\CrossX+DesktopScaledX(3), *Item\Layout\CrossY+DesktopScaledY(3), \CloseButtonSize-DesktopScaledX(6), *Item\Color\Text&$FFFFFF|$40<<24)
      Else
        TabBarGadget_DrawCross(*Item\Layout\CrossX+DesktopScaledX(3), *Item\Layout\CrossY+DesktopScaledY(3), \CloseButtonSize-DesktopScaledX(6), *Item\Color\Text)
      EndIf
There is probably some other tweak to do here and here, as I patched it only for the IDE
User avatar
chi
Addict
Addict
Posts: 943
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: TabBarGadget - Tabs like in a browser

Post by chi »

Thanks! Speaking of IDE Tabs... Due to my dark theme I have black text on dark gray background. It would be nice to change that.
Et cetera is my worst enemy
User avatar
STARGÅTE
Addict
Addict
Posts: 1748
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by STARGÅTE »

chi wrote: Fri May 20, 2022 12:45 pm Thanks! Speaking of IDE Tabs... Due to my dark theme I have black text on dark gray background. It would be nice to change that.
Usually the colors were set dynamically:

Code: Select all

	CompilerSelect #PB_Compiler_OS
		CompilerCase #PB_OS_Windows
			\TabBarColor   = $FF<<24 | GetSysColor_(#COLOR_BTNFACE)
			\BorderColor   = $FF<<24 | GetSysColor_(#COLOR_3DSHADOW)
			\FaceColor     = $FF<<24 | GetSysColor_(#COLOR_BTNFACE)
			\TextColor     = $FF<<24 | GetSysColor_(#COLOR_BTNTEXT)
		CompilerDefault
			\TabBarColor   = $FFD0D0D0
			\BorderColor   = $FF808080
			\FaceColor     = $FFD0D0D0
			\TextColor     = $FF000000
	CompilerEndSelect
However, there is not Linux equivalent.
PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 5.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
chi
Addict
Addict
Posts: 943
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: TabBarGadget - Tabs like in a browser

Post by chi »

STARGÅTE wrote: Fri May 20, 2022 5:51 pm Usually the colors were set dynamically:
The TabBarGadget demo works as expected, but in the IDE as soon as I save the text goes black ;(
Image
Et cetera is my worst enemy
Fred
Administrator
Administrator
Posts: 14731
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: TabBarGadget - Tabs like in a browser

Post by Fred »

Better create a proper IDE bug report to not hijack this thread.
fryquez
Enthusiast
Enthusiast
Posts: 250
Joined: Mon Dec 21, 2015 8:12 pm

Re: TabBarGadget - Tabs like in a browser

Post by fryquez »

chi wrote: Fri May 20, 2022 7:02 pm The TabBarGadget demo works as expected, but in the IDE as soon as I save the text goes black ;(
SourceManagement.pb --> RefreshSourceTitle()
Post Reply