Re: Can I stop events for a while ??



Be sure to note I commented out the signal connection in the
contructor.. shoulda removed it altogether...

Sorry,

Bob

Bob Caryl wrote:

><rant> First off:  please, Please, PLEASE do not send html to the
>list.</rant>
>
>This will do what you asked, using the Pango::FontDescription::set_size
>method.  I made adjustments to the scaling to achieve acceptable
>behavior.   You will want to experiment with this code to get the final
>results you seek.  If it is not satisfactory, then you're on your own.
>
>Code follows:
>
>resizetest.h:
>
>#ifndef __RESIZE_TEST_
>#define __RESIZE_TEST_
>#include <gtkmm.h>
>
>class MyWindow : public Gtk::Window
>{
>public:
>    MyWindow(Gtk::Label *Label);
>protected:
>    bool on_size;   // used to limit number of calls to set_size
>    Gtk::Label *lbl;
>    virtual bool on_expose_event(GdkEventExpose*);
>    void set_size(void);
>};
>
>#endif
>
>
>resizetest.cpp:
>
>#include "resizetest.h"
>
>MyWindow::MyWindow(Gtk::Label *Label)
>{
>    on_size = TRUE;
>    lbl = Label;
>    add(*lbl);
>    show_all_children();
>    //   
>signal_expose_event().connect(sigc::bind(sigc::mem_fun(*this,&MyWindow::on_expose));
>}
>
>void MyWindow::set_size(void)
>{
>    int x,y,width,height,depth;
>   
>    on_size = TRUE;
>    Pango::FontDescription fd(lbl->get_text());
>    get_window()->get_geometry(x,y,width,height,depth);
>    fd.set_size((int)(height*Pango::SCALE*.5));
>    lbl->modify_font(fd);
>}
>
>bool MyWindow::on_expose_event(GdkEventExpose* event)
>{
>    Gtk::Window::on_expose_event(event);
>    if(on_size)
>    {
>        on_size = FALSE;
>        return TRUE;
>    }
>    set_size();
>    return TRUE;
>}
>
>main.cpp:
>
>#include "resizetest.h"
>
>int main(int argc, char *argv[])
>{
>    Gtk::Main app(argc,argv);
>    Gtk::Label label("XXXXXX");
>    MyWindow window(&label);
>    app.run(window);
>}
>
>Best results are gained by resizing diagonally (i.e. height and width
>simultaneously, since changes in width alone do not have any affect on
>point size.
>
>I hope this helps.
>
>Bob
>
>
>Sergio Trinidad wrote:
>
>  
>
>>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 <mailto: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 <mailto:gtkmm-list gnome org>
>>    >http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>    >
>>    >
>>
>>
>>    
>>
>_______________________________________________
>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]