GtkGrid children and GTK_ALIGN_END

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

GtkGrid children and GTK_ALIGN_END

Bill Kelly
Hi,

Would it be correct to expect right-justification of a child in the
following situation?  (Assuming: GTK_ORIENTATION_HORIZONTAL,
GTK_TEXT_DIR_LTR.)

  GtkWindow
  |_ GtkGrid {hexpand=TRUE; halign=GTK_ALIGN_FILL}
     |_ GtkEntry {halign=GTK_ALIGN_END}

I believe GTK 3.12 used to place the GtkEntry flush with the right
edge of the window.

However, in GTK 3.22, the GtkEntry remains flush with the left edge,
regardless of GTK_ALIGN_END being set.

Here are the allocation values, and min & natural size values I'm
seeing:

alloc(   0,   0, 713, 715) min( 176,  38) nat( 176,  38) GtkWindow
alloc(   0,   0, 713,  38) min( 176,  38) nat( 176,  38)  GtkGrid
alloc(   4,   2, 168,  34) min( 176,  38) nat( 176,  38)   GtkEntry

We can see the allocation width of the GtkGrid did indeed expand as
requested.

But the halign=GTK_ALIGN_END setting of the GtkEntry child does not
appear to be honored.

I've perused the commit diffs in gtk/gtkgrid.c between 3.12 and 3.22,
but a fair amount has changed.

So I figured I'd better verify: *Should* we expect GTK_ALIGN_END to
be honored in the case above?


Thanks,

Bill


_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: GtkGrid children and GTK_ALIGN_END

Daniel Boles
On 12 October 2017 at 13:10, Daniel Boles <[hidden email]> wrote:
By my understanding, the explanation is this:
  • the Entry is right-aligned within its cell
  • but then the Grid is set to align fill and expand, so it expands empty space beyond the Entry and the cell it's in

Assuming I understand this guide right, then it does kinda make sense to me.

https://developer.gnome.org/gtk3/stable/ch30s02.html

I found that hexpanding the Entry too got around this, but it may not be exactly what you want.


since a test case is always useful...

#include <gtk/gtk.h>

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

  GtkWidget *grid = gtk_grid_new ();
  gtk_widget_set_hexpand (grid, TRUE);
  gtk_widget_set_halign (grid, GTK_ALIGN_FILL);
  gtk_orientable_set_orientation ((GtkOrientable *)grid, GTK_ORIENTATION_HORIZONTAL);

  GtkWidget *entry = gtk_entry_new ();
  gtk_widget_set_halign (entry, GTK_ALIGN_END);
  gtk_container_add ((GtkContainer *)grid, entry);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_add ((GtkContainer *)window, grid);
  gtk_widget_show_all (window);

  gtk_main ();
}


_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: GtkGrid children and GTK_ALIGN_END

Bill Kelly

Daniel Boles wrote:
> Assuming I understand this guide right, then it does kinda make sense to me.
>
> https://developer.gnome.org/gtk3/stable/ch30s02.html

Thanks, that's a handy link.


> I found that hexpanding the Entry too got around this, but it may not be
> exactly what you want.

I'd noticed that too, though it's indeed not what I'd wanted in this case.

But, I can imagine some potential workarounds.


Thanks for your help!

Bill

_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: GtkGrid children and GTK_ALIGN_END

Daniel Boles
The wildcard here, and what makes me confused as to whether my own rationale makes sense, is that you have the grid expanding; I can't immediately think of cases where I've used such a construct, so I don't know what I expect it to do! It's also been a while since I thought about how alignment and expansion interact - I think once you get your program to a point where it works, the brain begins to remove that information ;) - so I don't know if anything I've said makes much sense, and would like an opinion from someone else.


_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: GtkGrid children and GTK_ALIGN_END

Bill Kelly
In reply to this post by Bill Kelly
Bill Kelly wrote:
> Daniel Boles wrote:
>
>> I found that hexpanding the Entry too got around this, but it may not be
>> exactly what you want.
>
> I'd noticed that too, though it's indeed not what I'd wanted in this case.

In case anyone encounters this thread later looking for a solution:

I was mistaken.  Setting hexpand on the GtkEntry indeed *did* produce the
result I'd wanted.

I thought I'd tried all the permutations, but it seems I was conflating
'expand' and 'fill'.

So: Apologies for the noise.


Regards,

Bill



_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list