Re: About layouts



Fernando Apesteguía wrote:

I'm developing an app with gtk. I use glade for GUI development. My question
is about the different kinds of layouts. I would like my app resizes by
itself when a label text is really long. I've noticed I can do this by
placing a table layout (I think vbox and hbox work well too).
In fact, this behaves well even when changing fonts dpi (This is the answer
to my question  that you can see at
http://mail.gnome.org/archives/gtk-app-devel-list/2006-January/msg00064.html
)

But my app has a lot of labels and buttons so I estimated I need a lot of
layouts creating a complex hierarchy (vbox inside a table layout, inside a
hbox, inside a table layout again...)

Did I forget a simply way to make this??

Your question is not quite clear to me. It seems to be about two issues:
1. auto-resizing of labels, 2, what containers to use for your layout.

Regarding GtkLabels: automatic resizing is their default behaviour,
regardless of which sort of container (Gtktable, GtkVBox, etc.) it is
being put into.

Example: when working with Glade, just create an empty dialog window.
Drop a new GtkLabel into it (directly into the window, without
additional layout containers). Make the window as small as possible (not
via the "minimizie" button). You will see that you can't make the window
smaller than the dimensions needed by the GtkLabel to have its text
(should be "label1" or similar) fully visible. In Glade's "properties"
window, when you type in additional text into the "Label" property of
the GtkLabel, you can see the window grow as you type. Again, this is
the default behaviour of GtkLabel (and most other types of widgets as
well) and is not bound to particular containers like GtkTables or Boxes.

However, if your texts may get "really long", this behaviour shouldn't
actually be what you want. Especially if the label has disabled its
wrapping property, restricting the label text to just one line, the
horizontal size requirement by the label may easily exceed the screen's
dimensions, making the window wider than the screen as well. This would
make your application basically useless.

There are three common strategies to consider if you're planning to deal
with display of really long texts. They aim at avoiding unrestricted
size requests by the GtkLabel:
1. enable the "wrap text" property of the GtkLabel
2. put the GtkLabel into a GtkScrolledWindow
3. use GtkTextView instead of GtkLabel, with "editable" property unset.

Regarding the other aspect of your question: what layout containers to
use and the extent of complexity is determined solely by what layout you
actually want to achieve. For instance, having 20 rows with each one
consisting of a GtkButton and a GtkLabel next to it, and all widgets
aligned vertically, is quite a simple layout. You would only need one
GtkTable with 2 columns and 20 rows for it. You could also easily use 10
rows with 4 columns (button, label, button, label) each with the same
single table.

More complex layouts require additional layout containers, of course.
You didn't provide any idea what sort of complex layout hierarchy you
want to achieve so I can't give more detailed recommendations.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]