Re: Setting exact size of Gtk::Label
- From: Ian Martin <martin_id vodafone co nz>
- To: gtkmm-list gnome org
- Subject: Re: Setting exact size of Gtk::Label
- Date: Fri, 09 Sep 2011 17:02:43 +1200
I probably should have framed a simple problem statement for the reflector;
something like this:
I need to delineate a rectangle on the screen, of a precisely given
position and size, and write text within that rectangle, with a guarantee
that the text, no matter what its length, will never extend outside the
rectangle.
It seems easy; but apparently it is not :-(
The reason gtkmm doesn't assume a constant window size is because it
hardly ever is. In real world cases, as soon as you lend a program to
someone else it's running on a different sized screen- and all your
widgets get messed up unless the library handles how they relate to each
other. If you think about the widget set in that context, the base
container classes should automatically resize under most circumstances.
Have a look in Gtk::Container, for instance.
A display widget that just snips visible data when it gets too long-
when invisibly it may have a whole lot of information hidden- is usually
frustrating (if not dangerous ) in many real world situations. That's
why "Why would you want to do _that_? is the sort of response you're
getting.
In most scenarios, you'd be better to make sure the string attached to
the Gtk::Label is appropriate before you attach it, not complain about
the resulating Gtk::Label width afterward. From what you've said,
you're allowing text entry; a solution would be to clip the input so it
never extends longer than the space you can allow it. All the entry
widgets send a signal when text is added, so I'd just connect to that
and truncate the text if it gets too long.
So it sounds like you're suggesting a TextView instead of a Label. (Are
you? -- I'm a bit puzzled because the first sentence of your reply seems to
suggest that a Label can do this, but I sure haven't been able to get it
remain fixed in size.)
The basic widget set is well described in the book- I'd strongly
recommend a read. A Gtk::Fixed is (I believe) a container with the
characteristic that it'll ignore any system requests to size itself
appropriately. A Gtk::Label is just that- a Label. The text is
predefined, minimal fiddling with it at runtime, just to display
information. Users can't interact with label text easily.
A Gtk::Button can be considered a (single item) Container with an Event
box. One of the constructors adds a label, but you can add anything you
like to the box instead if you want. If you're looking to capture
button presses, the signals are already connected so it's easier than
sitting a label on an EventBox yourself.
A Gtk::ComboBox with will take up to a line of text, and a Gtk::TextView
larger amounts. From what you said, you're looking for user input, and
a Label is the wrong widget for that.
A lot of the info you're looking for may be on your PC already. If
you've on Linux and have gtkmm-doc installed, have a look in
file:///usr/share/doc/libgtkmm-3.0-doc/reference/html/index.html
or libgtkmm-2.4-doc if you're on the stable version.
Ian.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]