Re: more size questions



On Fri, 09 Sep 2011 18:03:37 -0600
"D. R. Evans" <doc evans gmail com> wrote:
> Chris Vine said the following at 09/09/2011 06:33 AM :
> 
> > This assumes of course that the even simpler approach of putting a
> > Gtk::Label into a Gtk::Fixed as the Gtk::Fixed's one and only child
> > doesn't do what you want, so you need to customise it further.
> 
> That would be perfect... except that override_background_color()
> doesn't work on Labels. So I have to have some other widget in
> addition to the Label. I have been using an EventBox and then adding
> the Label to the EventBox, because that's what I found by googling
> the question of how to set the background colour for a Label.
> 
> So we have a Label inside an EventBox inside a Fixed... which all
> along has seemed like it should work -- after all, the documentation
> for Fixed explicitly says that:
> 
> "The Gtk::Fixed widget is a container which can place child widgets at
> fixed positions and with fixed sizes, given in pixels."
> 
> But having a Label inside an EventBox inside the Fixed doesn't work:
> the Label changes size, and hence so does the EventBox.
> 
> There are functions with suggestive names line set_vexpand(bool) and
> set_hexpand(bool) whose purpose is undocumented but sound like they
> could be used to fix the size of a widget. But they don't. I don't
> know what they do, but the widgets still change size even after these
> functions have been called.
> 
> The solutions using Cairo might be possible; I'll have to look at it
> -- I don't know anything about Cairo. I do have the horrible feeling
> that I'm diving ever deeper into a mire simply to implement something
> that is trivial on 1980s-era PCs. It seems like colouring a rectangle
> and putting text in the coloured area shouldn't be that hard.

Drawing text with cairo is actually pretty easy, particularly if you
are not interested in internationalisation (and in particular with
right-to-left languages) so you are not going to use pango. In Gtk+3,
DrawingAreas have a 'draw' callback rather than an 'expose_event'
callback which even presents a cairo context for you to draw the text
on.  I realise it may not be so easy for you but it would take me about
10 minutes to implement a subclass of Gtk::DrawingArea which would draw
text in the way that you want.  All your new "set_text" method would do
is change the string (or whatever) holding the text the DrawingArea is
to display and then trigger a draw event by calling its queue_draw()
method.

However, I have been investigating the behaviour of Gtk::Fixed out of
interest, and what you want works as is with GTK+2.  With GTK+3 the
behaviour of GtkFixed (and so Gtk::Fixed) changed - in GTK+3 Fixed will
resize itself to meet the standard size allocations of all the widgets
put in the Fixed at the positions at which they have been placed in the
Fixed.  In GTK+2, Fixed will instead assume the size requested by
Gtk::Widget::set_size_request().

So the documentation is now wrong in saying "The GtkFixed widget is a
container which can place child widgets at fixed positions and with
fixed sizes".  That is how it used to be in GTK+2, mostly (see below
about "mostly"). What it should say in GTK+3 is that "The GtkFixed
widget is a container which can place child widgets at fixed positions".

The new behaviour isn't entirely wrong in concept, since even in GTK+2
widgets such as labels put in a Fixed were allowed to overlap rather
than being clipped, so the "with fixed sizes" was never entirely right.

So unless anyone on the list can think of an easy way of stopping
Gtk::Fixed resizing, I suppose you have three options: use GTK+2, use
another toolkit such as Qt or subclass Gtk::DrawingArea.

Chris




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