GTK 3 Header Bar

Now that GTK 3 is being used. Could I use a GTKHeaderBar in my application? If so how would I got about doing so? I toyed around with different variations of declares but can’t seem to get it to work properly.

Thanks.

What have you tried?

Looks cool…

https://developer.gnome.org/gtk3/stable/GtkHeaderBar.html#gtk-header-bar-new

Xojo 2017.2 is out now and it would be nice to use the stylish GTK+3 Headerbar.

On macOS you can easily modify a Toolbar via declares to get it more macOS like. I never had any experience with Linux. How could we start to expand the Toolbar on Linux?

Only found this tutorial for Linux developer.

GTK+3 Headerbar

Library: libgtk-3.so

How to realize for example this declare “gtk_header_bar_set_subtitle ()”:

[code]void
gtk_header_bar_set_subtitle (GtkHeaderBar *bar, const gchar *subtitle);

Declare Function gtk_header_bar_set_subtitle Lib “libgtk-3.so” ???[/code]

Headerbar is not Toolbar.

from https://developer.gnome.org/gtk3/stable/GtkHeaderBar.html

GtkHeaderBar is similar to a horizontal GtkBox …

[quote=352483:@Axel Schneider]Headerbar is not Toolbar.

from https://developer.gnome.org/gtk3/stable/GtkHeaderBar.html

GtkHeaderBar is similar to a horizontal GtkBox …[/quote]
Ah ok, but it could be used instead of a toolbar?! I read some posts of you. Looks like you have more Linux experience. Any idea, how implement this? Thanks for your feedback.

I have an old project (November 2016) with Linux Declares (gtk2) on this site

(but it does not work in Xojo 2017)

to set a window title

Declare Sub gtk_window_set_title lib "libgtk-x11-2" _ (windowRef As Integer, title as CString) gtk_window_set_title(Window1.Handle, "Title")

similar to this it could be something like that (but you must find a way to insert a HeaderBar)

[code]
Declare Sub gtk_header_bar_set_has_subtitle Lib “libgtk-3.so” _
(HeaderBarRef As Integer, b as Boolean)
gtk_header_bar_set_has_subtitle(HeaderBar1.Handle,True)

Declare Sub gtk_header_bar_set_subtitle Lib “libgtk-3.so” _
(HeaderBarRef As Integer, title as CString)
gtk_header_bar_set_subtitle(HeaderBar1.Handle, “SubTitle”)[/code]

Where should the HeaderBar inserted into? The Titlebar?

GtkHeaderbar is a subclass of GtkContainer. Is a ContainerControl or a RectControl the equivalent to GTKContainer? How to create a new GtkHeaerbar Instance? ContainerControls Open-Event

Declare Sub gtk_header_bar_new Lib GTK3 (ref As Integer) gtk_header_bar_new(Self.Handle)

has no effect.

The Declare is simply

Declare Function gtk_header_bar_new Lib "libgtk-3.so" as Ptr

Then you have to employ

Declare Sub gtk_window_set_titlebar lib "libgtk-3.so" (win as ptr, bar as ptr)

with the ptr of the window‘s handle and the result of the first declare.

Together with some more declares, a lot of individual settings are possible – including examining the minimum and natural height and width settings of every control/GTKWidget …

Would there be a certain interest in a GTKLib?

After the input of our really helpful and friendly german Xojo-Evangelist Ulrich B., we gone a step forward.

[code]Const GTK3Lib = “libgtk-3.so”

Declare Function gtk_header_bar_new Lib GTK3Lib As Ptr
Dim headerBar As Ptr = gtk_header_bar_new

Declare Sub gtk_window_set_titlebar Lib GTK3Lib (windowRef As Ptr, headerBar As Ptr)
gtk_window_set_titlebar(Ptr(Window1.Handle), headerBar)

Declare Sub gtk_header_bar_set_has_subtitle Lib GTK3Lib (headerBarRef As Ptr, b As Boolean)
gtk_header_bar_set_has_subtitle(headerBar, True)

Declare Sub gtk_header_bar_set_subtitle Lib GTK3Lib (headerBarRef As Integer, title As CString)
gtk_header_bar_set_subtitle(headerBar, “SubTitle”)
[/code]

Thank you!
To take it a bit further and ask again for the demands for an easy-to-use Xojo GTK3 library:

demand? no.
a nice-to-haye? yes. :slight_smile:
I usually don’t use a whole library, but they’re great resources to pick out a couple of things.

For Linux we use declares to change the Toolbar-Style, and to embed fonts within the application.
That’s what I could provide to a possible library/collection.

To answer James’ question from my point of view, after some testing:
In theory it is doable. In reality I ran into what I consider a struggle between Xojo’s layout engine and different distros.

The HeaderBar works flawlessly only on Ubuntu (once I made some changes to control positions (or, better, the window height)). On other distros I tested, glitches occur when ApplicationWindow.ShowAll is being cast on the window that should contain the header bar. These vary from window heights I could not set appropriately and almost in every case wrongly positioned controls when they are locked (at least) on right and/or bottom. These overlap the windows’ bounds after the header bar is shown, although by their frame values viewed in debugger they should fit. I am unsure if this behavior should be considered a Xojo Linux framework bug (although I could create a workaround for it).

If someone should want to inspect this behavior and maybe find a solution, let me know and I’ll upload the code to a free repository. I do not have the time to inspect this further (just played with it when a flu did not let me out of bed last week).

Ive had the same issue as in the picture.
The content of the window is shown at an offset.

System elementary os.

Not really. Top and left are ok, but right and bottom lock somehow invert their offset. I worked around that by subclassing Window with a CreateHeader event, where in case right and bottom locks of embedded controls are set to false (but saved in a dictionary) and restored afterwards.
That handles the right offset, but not the bottom in every case, as some distros change the window size strangely. I thought I could use GTKWindow, but its size information does not help at all – some distros deliver the same values as the Xojo window, some smaller, some bigger values. Feels a bit like fine-tuning your site for different browsers back in the old days.

[quote=353273:@Ulrich Bogun]Not really. Top and left are ok, but right and bottom lock somehow invert their offset. I worked around that by subclassing Window with a CreateHeader event, where in case right and bottom locks of embedded controls are set to false (but saved in a dictionary) and restored afterwards.
That handles the right offset, but not the bottom in every case, as some distros change the window size strangely. I thought I could use GTKWindow, but its size information does not help at all – some distros deliver the same values as the Xojo window, some smaller, some bigger values. Feels a bit like fine-tuning your site for different browsers back in the old days.[/quote]

It even happens to me if there is no content on a window. Just a plain project r2.1

@Ulrich Bogun the screeshot you show happens on ALL linux GTK 3 distro’s once custom background color is set on a window or you use the paint event.

Also when you place controls, they don’t honor their position in linux GTK 3. Window width and height could be a problem here perhaps the wrong values are used. In the IDE it shows good. But running builds or debugs show completely out-of-position- content.

You say you could work around it, i’d really like to know how.

Not fully. It works for the right side, but not for the bottom of controls in all distros.
I’ve put all I got so far on this repository. Please note the different size information in Xojo.Window.height vs. GTKWindow.windowSize.Height and GTKWidget.NaturalHeight for the same window in the listbox. Almost every distro brings different values (I thought one could use the value for the window dimensions, but it does not seem so).

If those where the true size values then why on earth would one distro give dimensions bigger than the actual window?

I can’t seem to find that in gtk 3 with other tools.
I think this is an issue in xojo using the gtk3 framework.