0

Is there a way to force a label to never try to re-size when the text changes?

The problem I'm trying to solve is that on my system re-sizing and re-drawing the 500+ widgets in my application takes on the order of 300-400ms. All the widgets are in the widget hierarchy of the displayed window under the top level window with different views stored in a Gtk::Stack. I have several data readouts that need to be updated about about 4Hz.

My frustration is that the minimum size of the label never approaches the allocated size. Even so, the minimum size change triggers recalculation of every widget in the hierarchy.

I tried switching from a label to a text view per this discussion on the gnome mailing list with no luck. I've included an example of how things shift around as the scale moves. Is there any way to fix the size of the left widget that prevents total windows redraws at it changes size?

#include <gtkmm.h>

int main( int argc, char* argv[]) {
    Glib::RefPtr<Gtk::Application> app =
        Gtk::Application::create( argc, argv, "test" );

    Gtk::Window window;
    Gtk::Box box;
    Gtk::TextView left;
    Gtk::Label right( "right" );

    Glib::RefPtr<Gtk::Adjustment> adjustment =
        Gtk::Adjustment::create( 0.0, 0.0, 10.0 );
    Gtk::Scale scale( adjustment, Gtk::Orientation::ORIENTATION_VERTICAL );
    scale.set_draw_value( false );

    window.set_size_request(200, 200);

    window.add( box );
    box.pack_start( left, true, true );
    box.pack_start( right, true, true );
    box.pack_start( scale );

    adjustment->signal_value_changed().connect( [&]() {
        Glib::ustring str;
        for( int i = 0; i <= (int)adjustment->get_value(); i++ ) {
            str += "X";
        }
        left.get_buffer()->set_text( str );
    } );

    window.show_all();

    return app->run( window );
}
MikeMB
  • 20,029
  • 9
  • 57
  • 102
Blake
  • 368
  • 1
  • 11
  • Have you tried Gtk::Label::set_width_chars()? https://developer.gnome.org/gtkmm/stable/classGtk_1_1Label.html#a68576e81de5db72faa88c9a539ec495e However, having 500 widgets in one window sounds like a problem in itself. I guess you'd be better off trying to display all this data in less widgets, maybe via a GtkTextView or something custom. A screenshot might help me to give a more specific suggestion. – murrayc Nov 26 '15 at 09:53
  • I realized that the issue isn't with Gtk::Label. If I fix the size in a variety of ways it stops propagation of the redraw as I would expect. My problem was my use of Gtk::Frame. I tried to ask a better version of the question over [here](http://stackoverflow.com/questions/34030423/why-does-gtkframe-force-a-redraw-resize). – Blake Dec 01 '15 at 21:25

0 Answers0