After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 733981 - Label with GTK_ALIGN_START does not work when width set by SizeGroup
Label with GTK_ALIGN_START does not work when width set by SizeGroup
Status: RESOLVED NOTABUG
Product: gtk+
Classification: Platform
Component: Widget: GtkLabel
3.13.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2014-07-30 14:33 UTC by Jussi Kukkonen
Modified: 2015-08-28 20:14 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jussi Kukkonen 2014-07-30 14:33:40 UTC
gupnp-universal-cp has some labels that should be left aligned and should all have the same width. A GtkSizeGroup is used to achieve the sizing (because the labels don't all have the same parent). Unfortunately this seems to break alignment. Below is example code to demonstrate: the labels align horizontally roughly in the middle even though I ask for GTK_ALIGN_START. 


/* gcc `pkg-config --libs --cflags gtk+-3.0` label-align-test.c */
#include <gtk/gtk.h>

int main(int argc, char **argv)
{
  GtkSizeGroup *group;
  GtkWidget *window, *grid, *label1, *label2;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  grid = gtk_grid_new ();
  gtk_container_add (GTK_CONTAINER (window), grid);

  label1 = gtk_label_new ("label 1");
  gtk_widget_set_halign (label1, GTK_ALIGN_START);
  gtk_grid_attach_next_to (GTK_GRID (grid), label1,
                           NULL, GTK_POS_BOTTOM,
                           1, 1);

  label2 = gtk_label_new ("label 2 with longer text");
  gtk_widget_set_halign (label2, GTK_ALIGN_START);
  gtk_grid_attach_next_to (GTK_GRID (grid), label2,
                           label1, GTK_POS_BOTTOM,
                           1, 1);

  group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
  gtk_size_group_add_widget (group, label1);
  gtk_size_group_add_widget (group, label2);

  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}


If I remove the sizegroup the labels align to start as they should. Also, if I add a new container parent for each label and put the labels in the size group, things work as expected.
Comment 1 Jussi Kukkonen 2014-07-30 14:35:05 UTC
(In reply to comment #0)
> If I remove the sizegroup the labels align to start as they should. Also, if I
> add a new container parent for each label and put the labels in the size group,
> things work as expected.

Was supposed to say "Also, if I add a new container parent for each label and put the _containers_ in the size group, things work as expected.
Comment 2 Matthias Clasen 2014-07-30 22:03:14 UTC
You still need to add gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5), unfortunately.
Comment 3 Emmanuele Bassi (:ebassi) 2015-08-24 09:36:51 UTC
Starting from GTK+ 3.16, you can use gtk_label_set_[xy]align() instead of using GtkMisc.
Comment 4 Matthias Clasen 2015-08-28 20:14:23 UTC
Don't think there is anything for us to fix here.