GtkPaned Children Width

I am having trouble understanding and achieving a three-column layout using GtkPaned. The goal is to have a left and a right column with a maximum width of 200px, and leave the middle column take the remaining width. This is what I have so far:

Is it even possible to achieve what I described with the approach I am currently following?

Seems to be possible.

should work for leftmost area.

Do you know the total available size of all three areas? I think so. You may use for the parent window, or maybe

Then it should be some basic math – maybe not quite exact?

1 Like

I was able to set the leftmost area to a maximum width and it works. As for the rightmost area, nothing seems to work to set a maximum width. I’m currently using glade (after trying PyGtk and thinking it was too hard to create the interface with pure code).

So, if I try to use the last two suggestions, it means I’ll mix the building of the interface partly writing it in XML, part in code. That makes me almost want to go back to pure code.

Still reading and trying stuff. Will post any updates as soon as I have some.

Thanks @StefanSalewski

Oh I missed the fact that you want to do it in glade. And I have no idea how to do it with glade/gtkbuilder, I generally avoid all the xml stuff. For my feeling in high level languages like Nim or Python directly creating the widgets in code is simpler as using glade/gtkbuilder. But I think it is OK to create the GtkPaned with glade and set final size in code.

Yes, you can achieve that using GtkBox as intermediate container and a mix of its packing and common properties, basically like this:

GtkPaned (expand=true):
  - GtkBox (expand=false, width-request=200)
  - GtkBox (expand=true)
      - GtkPaned (expand=true)
          -GtkBox (expand=true, resize=true, shrink=false)
          -GtkBox (width-request=200, expand=false, resize=false, shrink=true)

Here is a working example, just try it with glade

I hope this is what you need!

1 Like

I just did a short test without glade. As expected, that gives a not really correct result, the rightmost area is a bit too small. Reason is that the handles of the panes takes space too. We should be able to fix for that, but I assume that you prefer the glade solution.

# nim c app0.nim
import gintro/[gtk, glib, gobject, gio]

proc appActivate(app: Application) =
  let window = newApplicationWindow(app)
  window.title = "GTK3 Paned Widgets"
  window.defaultSize = (800, 200)
  let p1 = newPaned(Orientation.horizontal)
  let p2 = newPaned(Orientation.horizontal) # show before request allocated width
  let fullWidth = window.getAllocatedWidth
  p2.setPosition(fullWidth - 200 - 200)

proc main =
  let app = newApplication("org.gtk.example")
  connect(app, "activate", appActivate)
  discard run(app)

1 Like

@tchx84 That was just what I was hopping for. Great! Special kudos for the simplified outline of the solution. Much appreciated. Thanks.

@StefanSalewski I was reading this today:

They say:

When construcing a more complicated user interface, with dozens or hundreds of widgets, doing all the setup work in C code is cumbersome, and making changes becomes next to impossible.

Thankfully, GTK+ supports the separation of user interface layout from your business logic, by using UI descriptions in an XML format that can be parsed by the GtkBuilder class.

So, it is hard to come to a conclusion as whether one should use XML or do pure C or Python, for instance.

Anyways, your help and examples are much appreciated. I learned a lot from them and at least I now know doing pure code to create the UI (vs XML) is not altogether evil :slight_smile: Thanks a lot!

For people coding in plain C Glade and GtkBuilder can be a big help indeed., as plain C is so verbose that making changes or only understanding code some time later can be very hard.

For the modern high level languages like Python, Nim, maybe also Vala, Rust, Go, D and many more I can not see such a big benefit for using Glade and GtkBuilder.

I started using Glade some years ago, at that time Glade documentation and and tutorials was really not good, and GTK community was not very active at all. I can remember struggling with a point, sending message to gtk mailing list:

Of course no reply. My NEd Nim editor created at that time is using glade, and I added some GTkBuilder examples to the Nim bindings page, but never used Glade myself since then. Maybe documentation and tutorials have improved, so I may give it a try again at some time.

Generally GtkBuilder like QML may be a good solution for fast prototyping of user interface–centric applications in a declarative way.

1 Like

Using GtkBuilder is always recommended, especially once you start using widget templates and your own composite widget classes. Composite widgets in GTK, like the dialogs or the various selection widgets (file chooser, color chooser, etc) are written as GtkBuilder XML descriptions. Tweaking XML without having to change the code allows for shorter testing, design, and bug fixing cycles.

The composite widget templates are also useful because they allow you to ship the XML and every other asset like special icons or other data files necessary to run your application, and either embed it right into your binary (for C code) or as a single binary blob that gets mmap()'ed by every instance of your application and/or library. It makes deploying applications a lot easier, faster, and robust.

Whether you decide to use Glade to generate the XML with a visual tool, or write the XML yourself, it’s entirely up to you. GTK ships with a tool that helps you with the validation and simplification of an XML file, in case you decide to write or tweak it by hand. It also can show you the result, so you can quickly check what a change looks like without running your whole application.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.