GtkTextView Sizing Issues

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

 



Hi there,

I've been trying to port an application of mine to Gtk+ 3 and have
been having some issues. Well, only one issue, but I've been
struggling with it for a whole month now. I posted to
gtk-app-devel-list but never had any responses there; so thought this
might be a more appropriate forum (apologies for the cross post for
those who subscribe to both).

My application has a vertical stack of GtkTextViews that I want to
appear immediately one after another. Under Gtk+ 2 everything worked
fine in a VBox, but with Gtk+ 3 I started getting extra vertical
padding or spacing between some of GtkTextViews. Seemingly random, but
I suppose there's a pattern in there somewhere. I thought I'd try
rewriting the application to use the new GtkGrids to see if that
helped, but it didn't.

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,
which took me to gtk-app-devel-list first, and now here.

There's a simple test program below which seems to reproduce the issue
in the bug above. 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. Just clicking on either of the top two GtkTextViews will
suddenly resize it down to the correct size!

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 and jarringly doing so when
they receive focus. Moreover, if I then narrow the window again the
GtkTextViews don't resize down horizontally, as if the viewport
doesn't automatically contract (regardless of the policy I set on the
horizontal scrollbar of the GtkScrolledWindow).

So, can anyone offer me any help; or an explanation as to what's going
on? I've spent a large amount of time looking at the source code
trying to figure out what's happening with the new height-for-width
geometry management, but I'm not sure I get it. My current thinking is
that I might need to write a custom widget to wrap each GtkTextView
that will size "how I want" (which is really just "how Gtk+ 2 used to
do it") using the new height-for-width approach, and I've got that
going "about 80% right", but it's got its issues and I fear that's
going in the wrong direction altogether and that I'm missing something
fundamental!

Any ideas?

Thanks in advance,
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<--
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux