Set ToolBar height?

Linux specific forum
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Set ToolBar height?

Post by garretthylltun »

Now that I'm aware of the GTK documentation, I was trying to see if it was possible to change the height of the toolbar. I see that on the Windows side of things they have some API calls to do this, but I was unable to find anything so far in the GTK docs.

Does anyone know if it's possible with GTK?

Thanks,
~Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Set ToolBar height?

Post by Shardik »

It's only possible to change the height of the ToolBar indirectly. One possibility is to use

Code: Select all

gtk_toolbar_set_style_(*Toolbar.GtkToolbar, Style)
to display only an icon, an icon together with a label below the icon or only the label without an icon. Another possibility is to change the icon size to fixed predefined resolutions. For demonstration purposes you may try the following code example.

You may wonder why I used API tool buttons and not PB's ToolBarStandardButton(). Of course it also works with PB's ToolBarStandardButtons but I would have to define a label for each button. By using predefined stock icons the labels are already predefined and are also automatically displayed in your local language (in my case in German).

You may also wonder why not every selected predefined icon size results in the correct resolution. This is caused by the fact that the predefined stock icons don't provide all listed possible resolutions. If you would provide an icon in all resolutions, the icon would be switched to the correct size!

Code: Select all

Procedure ChangeToolBarIconSize(ToolBarIconSize.I)
  ; ----- Change icon size of ToolBar
  gtk_toolbar_set_icon_size_(ToolBarID(0), ToolBarIconSize)

  ; ----- Redisplay window to show modified ToolBar
  gtk_widget_show_all_(WindowID(0))
EndProcedure

OpenWindow(0, 200, 100, 300, 250, "ToolBar")

; ----- Create toolbar and 3 API tool buttons
CreateToolBar(0, WindowID(0))
ToolButton = gtk_tool_button_new_from_stock_( #GTK_STOCK_DIALOG_INFO)
gtk_toolbar_insert_(ToolBarID(0), ToolButton, -1)
ToolButton = gtk_tool_button_new_from_stock_(#GTK_STOCK_DIALOG_WARNING)
gtk_toolbar_insert_(ToolBarID(0), ToolButton, -1)
ToolButton = gtk_tool_button_new_from_stock_(#GTK_STOCK_DIALOG_ERROR)
gtk_toolbar_insert_(ToolBarID(0), ToolButton, -1)

; ----- Define FrameGadget with 5 OptionGadgets for the different icon sizes
FrameGadget(0, 10, 5, 130, 150, "ToolBar icon size:")
OptionGadget(1, 10,  20, 110, 25, "16x16")
OptionGadget(2, 10,  45, 110, 25, "18x18")
OptionGadget(3, 10,  70, 110, 25, "20x20")
OptionGadget(4, 10,  95, 110, 25, "24x24")
OptionGadget(5, 10, 120, 110, 25, "32x32")
OptionGadget(6, 10, 145, 110, 25, "48x48")
SetGadgetState(4, #True)

; ----- Define FrameGadget with 3 display styles
FrameGadget(7, 150, 5, 130, 90, "ToolBar style:")
OptionGadget( 8, 160, 20, 110, 25, "Icon only")
OptionGadget( 9, 160, 45, 110, 25, "Label only")
OptionGadget(10, 160, 70, 110, 25, "Icon plus label")
SetGadgetState(8, #True)

; ----- Redisplay window to show modified ToolBar
gtk_widget_show_all_(WindowID(0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1 ; 16x16
          ChangeToolBarIconSize(#GTK_ICON_SIZE_MENU)
        Case 2 ; 18x18
          ChangeToolBarIconSize(#GTK_ICON_SIZE_SMALL_TOOLBAR)
        Case 3 ; 20x20
          ChangeToolBarIconSize(#GTK_ICON_SIZE_BUTTON)
        Case 4 ; 24x24
          ChangeToolBarIconSize(#GTK_ICON_SIZE_LARGE_TOOLBAR)
        Case 5 ; 32x32
          ChangeToolBarIconSize(#GTK_ICON_SIZE_DND)
        Case 6 ; 48x48
          ChangeToolBarIconSize(#GTK_ICON_SIZE_DIALOG)
        Case 8
          gtk_toolbar_set_style_(ToolBarID(0), #GTK_TOOLBAR_ICONS)
        Case 9
          gtk_toolbar_set_style_(ToolBarID(0), #GTK_TOOLBAR_TEXT)
        Case 10
          gtk_toolbar_set_style_(ToolBarID(0), #GTK_TOOLBAR_BOTH)
      EndSelect
  EndSelect
ForEver
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Set ToolBar height?

Post by Oma »

@ Shardik:
wow, that's a demo

A simple solution is to set the toolbar-height, but the height of content also stretches automatically ...

Code: Select all

;======================================================================
; Module/File:     Toolbar_ChangeHeight.pb - Linux
; Function:        Toolbar: Set new toolbar height - Linux
; Author:          Oma (Charly Bauer)
; Date:            Aug. 02, 2014
; Version:         0.1
; Target Compiler: PureBasic 5.22 LTS - Linux x86
; Target OS:       Linux - Xubuntu
;======================================================================
; problem: the height of content depends from toolbar-height v.v.
; -> the height of the content also get stretched
; further problem: found no way to get the ID of content like Buttons from PureBasic

Global *widget.GtkWidget

; trial to PureBasic-Example ...
If OpenWindow(0, 0, 0, 150, 150, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	If CreateToolBar(0, WindowID(0))
		ToolBarStandardButton(0, #PB_ToolBarIcon_New)
		ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
		ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
	EndIf
	
	Debug "original height: " + Str(ToolBarHeight(0));       original toolbar-height
	*widget= ToolBarID(0);                                   toolbar-widget-adress to set GtkWidget-Structure-Type
	*widget\requisition\height= 60;                          set height in Structure 'widget\requisition\height'
	Debug "    new height: " + Str(ToolBarHeight(0));        debug new toolbar-height
	
	Repeat
		Event = WaitWindowEvent()
		If Event = #PB_Event_Menu
			Debug "ToolBar ID: "+Str(EventMenu())
		EndIf
	Until Event = #PB_Event_CloseWindow 
EndIf
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Set ToolBar height?

Post by Shardik »

@Charly:
Nice finding! I did a Google search and didn't find any example like yours but only the approaches demonstrated in my demo code. I shouldn't trust Google search results too much anymore but instead try to think more about it by myself because I remember having used already this *Widget\requisition\height setting for another Gadget... :oops:
Oma wrote:... but the height of content also stretches automatically ...
That seems to depend on your desktop manager. Using KDE the icons are not stretched:

Ubuntu 12.04 x64 with KDE - ToolBar height 60 pixels
Image

Ubuntu 12.04 x64 with KDE - ToolBar height 31 pixels
Image
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Set ToolBar height?

Post by Oma »

Hi Shardik!

And now a challenge for my english :cry:

I had the fear that it depends on the installation.
To clarify: Not the icons themself are stretched but the frame around. Visible an mouseover.

I haven't tested, but theres a command which could solve the problem:
gtk_tool_item_set_expand(GtkToolItem *tool_item, gboolean expand)

But in my Version i can't mix the Basic-Toolbar-Commands with API without Error.

Bye
Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Re: Set ToolBar height?

Post by garretthylltun »

The button frames do stretch on Ubuntu 12.04(elementary OS), but when I clicked one of the buttons the height of the toolbar snaps back to original height. Placing

Code: Select all

*widget= ToolBarID(0)
*widget\requisition\height= 60
in the loop did not resize the height back to 60 after the click.

I'm really sorry, I am still a bit new to Linux and do not have comprehension of GTK+ calls yet. So I greatly appreciate all of your input here on the forums while I try to learn how to use the calls to the GTK+ system.

Thanks,
~Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Set ToolBar height?

Post by Shardik »

Oma wrote:; further problem: found no way to get the ID of content like Buttons
Oma wrote:But in my Version i can't mix the Basic-Toolbar-Commands with API without Error.
You have to know that PureBasic doesn't use GtkToolButtons but regular GtkButtons in the ToolBar. Please take a look into this thread with my explanation, try my posted code of a Widget Explorer which maps all widgets in a PB window and compare PB's usage of widgets with that of API defined toolbar elements... :wink:
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Set ToolBar height?

Post by Shardik »

garretthylltun wrote:Placing

Code: Select all

*widget= ToolBarID(0)
*widget\requisition\height= 60
in the loop did not resize the height back to 60 after the click.
Confirmed for Ubuntu 12.04 x64 with KDE...
I think Charly's solution unfortunately seems only to be some sort of a hack which isn't very stable. It only seems to work with PB's ToolBarStandardButton (up to the first button selection) but not with GTK's GtkToolButtons. Have you tried my posted alternative of changing the icon size which is a documented and valid GTK2 approach?
Oma wrote:I haven't tested, but theres a command which could solve the problem:
gtk_tool_item_set_expand(GtkToolItem *tool_item, gboolean expand)
Since PB doesn't use GtkToolItems you can't use this function...
Even when using API functions to create ToolButtons, the expansion does only increase the width but not the height of the ToolBar. Place your cursor above the toolbar buttons to see their selectable rectangles:

Code: Select all

Define *ToolBar.GtkWidget

OpenWindow(0, 200, 100, 150, 150, "ToolBar")
*ToolBar = CreateToolBar(0, WindowID(0))
ToolButton1 = gtk_tool_button_new_from_stock_( #GTK_STOCK_DIALOG_INFO)
gtk_toolbar_insert_(*ToolBar, ToolButton1, -1)
ToolButton2 = gtk_tool_button_new_from_stock_(#GTK_STOCK_DIALOG_WARNING)
gtk_toolbar_insert_(*ToolBar, ToolButton2, -1)

*ToolBar\requisition\height = 60
gtk_tool_item_set_expand_(ToolButton2, #True)
gtk_widget_show_all_(WindowID(0))
   
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Re: Set ToolBar height?

Post by garretthylltun »

I did find from another example that Shardik provided in my Combobox question thread that if I apply a ButtonGadget or an ImageButton that I can set the height of the button to say 48x48 and the toolbar does take on a new height that appropriately contains and that the button retains it's size.

Code: Select all

OpenWindow(0, 100, 100, 500, 80, "ToolBar", #PB_Window_SystemMenu)
CreateToolBar(0, WindowID(0))

ButtonGadget(1,0,0,36,36,"btn")

ToolItem = gtk_tool_item_new_()
gtk_tool_item_set_visible_horizontal_(ToolItem, #True)
gtk_toolbar_insert_(ToolBarID(0), ToolItem, 0)
gtk_widget_reparent_(GadgetID(1), ToolItem)

gtk_widget_show_all_(WindowID(0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        Debug "button pushed"
        Break
      EndIf
  EndSelect
ForEver
I only wish it wouldn't resize the height of all the gadgets that I add to the toolbar via this method.
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
Post Reply