Re: centered and right justified label in the same line.



On Mon, 2018-02-26 at 09:23 +0100, Stefan Salewski wrote:
On Mon, 2018-02-26 at 09:16 +0100, Wojciech Puchar wrote:
How to do this in GTK 2. whatever i try i'm getting first label
centered 
relative to space remaining after second label not to whole hbox. how
to 
do this properly?



That may be not that easy.

Maybe try a hbox, which again contains 3 hboxes. 3 because so it may
allow center the middle one. Then put your labels into some of these 3
boxes.

I dont think 3 boxes will change anything, as size requisition will
just pass through to a widget which actually requested size.

A decent approach is to ensure that there are 3 widgets in the box,
while the left widget shows no content (this could be anything; an
empty label or an empty box would do it).

Need to make sure that the first and last widget in your horizontal box
requested to "expand" while the middle label which you want centered
does not ask to "expand".

To set this, you need to set the *packing* properties of the children
of the main horizontal box, e.g. like this:

   gtk_container_child_set(GTK_CONTAINER(box), first_child,
                           "expand", TRUE,
                           NULL);
   gtk_container_child_set(GTK_CONTAINER(box), second_child,
           
               "expand", FALSE,
                           NULL);
  
gtk_container_child_set(GTK_CONTAINER(box), third_child,
               
           "expand", TRUE,
                           NULL);

Alternatively, you could probably achieve similar by adding the first
and last child to a GtkSizeGroup; this would additionally cause the
horizontal box to have a minimum size which honors the appearance you
want to achieve (without a size group, the minimum possible size would
allow both center and right justified labels to appear side by side).

Cheers,
    -Tristan



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