Re: Why does this behave the way it does?



Ian Martin said the following at 02/28/2012 02:16 AM :

>> column. The /homogeneous/ property defaults to false.

I specifically set this property to "true" in the constructor:
 Gtk::Table  table(N_ROWS, N_COLS, true);

( The documentation shows that the boolean third parameter of the
constructor controls whether the cells are homogeneous:
  Gtk::Table::Table 	( 	guint  	n_rows = 1,
		guint  	n_columns = 1,
		bool  	homogeneous = false
	) 		[explicit]
)

> So your table may well, by default, change size based on the size of the widgets 
> in it. Which it does.

Why? Firstly, all the cells are, by virtue of the constructor, the same
size. That would explain why the width of the first widget changes when the
second widget is added *if the second widget caused the width of the cells
to change*. That in turn would be true if the second widget needed to
expand in order to contain its text. But it doesn't -- the text in the
second widget is much shorter than the widget's twelve-cell width:

The first widget is attached with:
  table.attach(textview1, 30, 35, 3, 4);  // left, right+1, top, bottom+1
So its width is five cells, and the length of the textview is what is
required to hold "1234*".

The second widget is attached with:
  table.attach(textview2, 20, 32, 2, 3);  // left, right+1, top, bottom+1
So its width is twelve cells, and the length of the textview is what is
required to hold "5678*".

So under these circumstances, why does adding the twelve-cell widget
increase the width of the table (and the cell width of the cells it contains)?

As far as I can tell, I have been quite careful to make sure that this will
not happen; but it does. That is at the heart of the behaviour I don't
understand.

> 
> The second issue is the size of the window. That's sort of related, because the 

Yes, I thought it was probably related to the first issue. Taking things
one step at a time, once we've got the table so that it doesn't change size
when adding the second textview, I'll see if the window-size issue still
exists.

For ease of reference, I'll leave the code in place below.

  Doc

>>
>> ----
>>
>> /*
>>   * gtk-test-1.cpp
>>   *
>>   */
>>
>> #include<gtkmm.h>
>>
>> using namespace std;
>> using namespace Gdk;
>> using namespace Gtk;
>>
>> int main(int argc, char *argv[])
>> { const int N_ROWS = 25;
>>    const int N_COLS = 80;
>>    const int SCREEN_WIDTH = 640;
>>    const int SCREEN_HEIGHT = 400;
>>
>>    Gtk::Main INIT(argc, argv);                    // needed to init gtkmm
>>    Gtk::Window window;                            // the initial window
>>
>> // the table into which we will place textviews
>>    Gtk::Table  table(N_ROWS, N_COLS, true);
>>
>> // set the main window to the desired size and make it non-resizable
>>    window.set_size_request(SCREEN_WIDTH, SCREEN_HEIGHT);
>>    window.set_resizable(false);
>>
>> // we want no space in the table
>>    table.set_row_spacings(0);
>>    table.set_col_spacings(0);
>>
>> // add the table to the window
>>    window.add(table);
>>
>>    window.show_all_children();
>>
>> // create and populate two textviews
>>    Gtk::TextView * textview_p1 = new Gtk::TextView;
>>    Gtk::TextView * textview_p2 = new Gtk::TextView;
>>
>>    Gtk::TextView&  textview1 = *textview_p1;
>>    Gtk::TextView&  textview2 = *textview_p2;
>>
>>    Pango::FontDescription fdesc("Courier New, medium, 12");
>>
>>    textview1.override_font(fdesc);
>>    textview2.override_font(fdesc);
>>
>> // first textview -- width depends on whether second textview is present
>>    textview1.override_color(RGBA("White"));
>>    textview1.override_background_color(RGBA("Black"));
>>    textview1.set_editable(false);
>>    textview1.set_cursor_visible(false);
>>
>>    textview1.get_buffer()->set_text("1234*");
>>
>>    table.show();
>>
>>    table.attach(textview1, 30, 35, 3, 4);  // left, right+1, top, bottom+1
>>
>>    table.show_all_children();
>>
>> // second textview
>> // variant 1 does not compile the following code; variant 2 does compile it
>> // the size of the window that contains the text "1234*"  varies depending
>> // on which variant we execute
>> #if 0
>>    textview2.override_color(RGBA("White"));
>>    textview2.override_background_color(RGBA("Black"));
>>    textview2.set_editable(false);
>>    textview2.set_cursor_visible(false);
>>
>>    textview2.get_buffer()->set_text("5678*");
>>
>>    table.attach(textview2, 20, 32, 2, 3);  // left, right+1, top, bottom+1
>>
>>    table.show();
>>    table.show_all_children();
>> #endif    // 0
>>
>>    INIT.run(window);    // draw the window and its contents
>>
>>    return EXIT_SUCCESS;
>> }
>>
>> ----
>>
>>    Doc
>>
>>
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> gtkmm-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 


-- 
Web:  http://www.sff.net/people/N7DR

Attachment: signature.asc
Description: OpenPGP digital signature



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