Re: Questions about St.Label

On 21 June 2012 22:29, César García Tapia <tapia openshine com> wrote:

I'm working in a shell extension, but I have some problems with St.Label sizing and positioning.

First problem: I want to vertical-align a label inside a container (St.BoxLayout, if it helps). I've tried this:

let box = new St.BoxLayout ();
box.add (some_really_high_widget);
let label = St.Label ();
label.set_text ("blah blah");
box.add (label, {expand: true, y_fill: true, y_align: St.Align.MIDDLE});

but nothing happens. The label is shown in the top of the widget, not vertical centered.

For this first problem, the problem is that you are setting the label to expand to fill its entire space, but the text is top-aligned within the label.

The `y_align` argument determines how the *entire label* is aligned within its available space, not how the text is aligned within the label. So when you set the label to take up all itsavailable space, `y_align` has no effect.

You can do:

    box.add(label, {y_fill: false, y_align: St.Align.MIDDLE})

which will make the label just as big as it needs to be to display its contents, and positions the label vertically in its BoxLayout cell (try doing ` = 'border: 1px solid blue'` and ` = 'border: 1px solid red'` to see how the label and boxlayout are positioned).

Second problem: I need a multi-line label, to show a long string. But all I get is a one-line label, it doesn't resize to fit all the text. The code:

label = new St.Label ();
label.clutter_text.line_wrap = true;
label.clutter_text.line_wrap_mode = Pango.WrapMode.WORD;
label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
label.set_text ("some really long text");
container.add (label, {expand:true});

But it only shows the first line. The ellipsis is OK, and if I force the label height through the stylesheet.css, it shows all the lines. But it's not a good idea, since I don't know the length of the string.

Any idea about how could I solve this two problems?

Thank you very much.

gnome-shell-list mailing list
gnome-shell-list gnome org

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