Re: Can I stop events for a while ??



And then how can I do it?

I explain:
I want a GtkLabel to resize its text when his container or window resizes, to fill all the area that his container has.

An example:

int main(int argc, char* argv[])
{
Gtk::Main aplicacion(argc, argv);
Gtk::Window ventana;
Gtk::Label lbl("XXXX");

ventana.add(lbl);
ventana.set_default_size(150,150);
ventana.show_all();

aplicacion.run(ventana);

return 0;
}

I write this simple program, that shows a label within a window, how can i resize the label text when the window size is modified ?


2005/12/15, Bob Caryl <bob fis-cal com>:
Creating another function to modify the font and calling it from the
on_size_allocate override will prevent the endless loop, but the
practical results are not too good.  The label font gets very large very
fast.  This is probably a dreadful idea.

Example code follows:

// code starts
class miMaquina : public VBox
{
    miMaquina(bool homogeneous,int spacing) {
Gtk::VBox::VBox(homogeneous,spacing); no_resize = FALSE; }
    Gtk::Label *lbl;
protected:
    bool no_resize;
    resize_font(int height);
    on_size_allocate(Gtk::Allocation &alloc);
}

void miMaquina::resize_font(int height)
{
    no_resize = TRUE;  // setting this to true before modifying
                                     // the font will prevent the
on_size_allocate
                                     // override from calling this
function repeatedly.
    Pango::FontDescription fd;
    fd.set_size((height * Pango::SCALE));
    lbl->modify_font(fd);
}

void miMaquina::on_size_allocate(Gtk::Allocation &alloc)
{
    int alto = alloc.get_height();
    Gtk::VBox::on_size_allocate(alloc);
    if(no_resize)
    {
       no_resize = FALSE;
       return;
    }
    resize_font(alto);
}
// code ends

Oh yeah, be sure to set miMaquina::lbl to point to whatever label you
are packing into your miMaquina instance.

Bob

Sergio Trinidad wrote:

> I have the next code
>
> class miMaquina : public VBox
> {
>       Gtk:Label *lbl;
>         .....
>
> };
> ....
> ....
>
> void miMaquina::on_size_allocate(Gtk::Allocation &alloc)
> {
>     int alto = alloc.get_height();
>     int ancho = alloc.get_width();
>     Gtk::VBox::on_size_allocate(alloc);
>
>     Pango::FontDescription fd;
>     fd.set_size((alto*Pango::SCALE));
>     lbl->modify_font(fd);
>
> }
>
>
> The problem is that when the events ocurrs the lbl->modify_font(fd)
> activates
> a new on_size_allocate event, because the size of label changes with
> the size
> of new text, and a infinite loop is launchet until X server gets an
> error.
> Can I stop signal emiting for a while, then apply 'lbl->modify_font'
> and later
> activate again the event??
>
>------------------------------------------------------------------------
>
>_______________________________________________
>gtkmm-list mailing list
>gtkmm-list gnome org
>http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>



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