Re: GtkTextView Sizing Issues



Hi there,

Sorry for the bump, but there's also another issue that's frustrating
me. If I compile the test application with the gtk_widget_set_hexpand
line uncommented I see more unexpected behaviour resizing the window
horizontally.

Widening the window works as expected - except for the vertical
padding as noted below - but when I make the window narrower again,
the viewport (and the GtkTextViews inside it) seems to stay the same
size, suddenly requiring you to scroll horizontally to see all the
text (I had hoped for the GtkTextView to automatically resize to the
new width of the window). This happens regardless of what policy I set
for the horizontal scrollbar.

I'm sure I must be doing something fundamentally wrong as it seems
this should all be so simple; unfortunately I can't figure it out and
it's been driving me crazy for a couple of weeks now! I hope I don't
have to roll back to Gtk+ 2 where everything used to work for me! So
if anyone can offer any help whatsoever, I'd really appreciate it!

Thanks in advance,
Paul


On Sat, Apr 21, 2012 at 10:01 AM, Paul wrote:
Hi there,

I'm experiencing some issues trying to port an application of mine to
Gtk+ 3. I have a vertical stack of GtkTextViews that I want to appear
one after another without any vertical padding between them. I have
issues using both GtkVBoxes (as originally used in my Gtk+ 2 version)
and newer GtkGrids.

Having a quick look around I see the issues seem to be same as in bug
650267 [https://bugzilla.gnome.org/show_bug.cgi?id=650267] but there
hasn't been any updates on that since it was raised about a year ago,
so I thought I'd check for advice here.

I've attached a simple test program below (which I hope is right -- I
use gtkmm and haven't used the direct C API in a while). Like the
original report mentioned, the GtkTextViews appear narrow and very
tall by default. More difficult for me to understand is why there's
extra vertical padding in the widgets without the focus, i.e., the top
two of the three GtkTextViews in this example. Clicking on either of
the top two GtkTextViews will suddenly resize it down to the correct
size too!

Setting hexpand TRUE on the GtkTextViews does help with the initial
sizings: everything 'looks' OK until I resize the window, making it
wider so the text renders in fewer lines in the GtkTextViews. I then
get similar behaviour as before: the GtkTextViews without the focus
don't automatically resize, only suddenly doing so when they receive
focus.

So, does anyone have any suggestions or fixes? If so they'd be greatly
appreciated.

Thanks,
Paul


--8<--

#include <gtk/gtk.h>
#include <string.h>

const char text[] =
Â"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod "
Â"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
Â"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
Â"commodo consequat.";

static GtkWidget *create_widget() {
ÂGtkWidget *widget = gtk_text_view_new();
Âgtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)),
 Âtext, strlen(text));
Âgtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(widget), GTK_WRAP_WORD);
//gtk_widget_set_hexpand(widget, TRUE); Â/* helps with 'initial' sizings */
Âreturn widget;
}

int main(int argc, char **argv) {
Âgtk_init(&argc, &argv);

ÂGtkWidget *grid = gtk_grid_new();
Âgtk_grid_attach(GTK_GRID(grid), create_widget(), 0, 0, 1, 1);
Âgtk_grid_attach(GTK_GRID(grid), create_widget(), 0, 1, 1, 1);
Âgtk_grid_attach(GTK_GRID(grid), create_widget(), 0, 2, 1, 1);

ÂGtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
Âgtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
 Âgrid);

ÂGtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
Âgtk_window_set_default_size(GTK_WINDOW(window), 500, 300);
Âgtk_container_add(GTK_CONTAINER(window), scrolled_window);

Âg_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
Âgtk_widget_show_all(window);
Âgtk_main();
Âreturn 0;
}

--8<--



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