Sign up

Mysterious vertical padding in Box

Hi. I can't figure out why there is a massive space between the vertical borders and the box in the middle?

    ~ "should not be taking up the entire             " ~ "width allocated to it, but automatically "
    ~ "wraps the words to fit.\n" ~ "     It supports multiple paragraphs correctly, "
    ~ "and  correctly   adds " ~ "many          extra  spaces. ";

int main(string[] args) {
    import gio.Application : GioApp = Application;
    import gtk.Application : Application;
    import gtk.ApplicationWindow : ApplicationWindow, GApplicationFlags;

    auto app = new Application("org.gitlab.radagast.gtkdnotes", GApplicationFlags.FLAGS_NONE);
    app.addOnActivate(delegate void(GioApp _) {
        auto aw = new ApplicationWindow(app);
        scope (success)
            aw.showAll();
        aw.setTitlebar(() {
            import gtk.HeaderBar : HeaderBar;

            auto hb = new HeaderBar();
            hb.setTitle("Label");
            hb.setSubtitle("Demo");
            hb.setShowCloseButton(true);
            return hb;
        }());
        aw.add(() {
            import gtk.Label : Label;
            import gtk.Box : Box;
            import gtkc.gtktypes : GtkOrientation;

            auto vbox = new Box(GtkOrientation.VERTICAL, 5);
            vbox.packStart(() {
                auto hbox = new Box(GtkOrientation.HORIZONTAL, 10);
                hbox.packStart(new Label("This is a normal label"), true, true, 0);
                hbox.packStart(() {
                    auto lb = new Label(L1);
                    lb.setLineWrap(true);
                    return lb;
                }(), true, true, 0);
                return hbox;
            }(), true, true, 0);
            return vbox;
        }());
    });
    return app.run(args);
}

Note that the window cannot be shrunk vertically.

output

Re: Mysterious vertical padding in Box

On Tue, 09 Oct 2018 16:47:04 GMT, aedt wrote:

Hi. I can't figure out why there is a massive space between the vertical borders and the box in the middle?

    ~ "should not be taking up the entire             " ~ "width allocated to it, but automatically "
    ~ "wraps the words to fit.\n" ~ "     It supports multiple paragraphs correctly, "
    ~ "and  correctly   adds " ~ "many          extra  spaces. ";

int main(string[] args) {
    import gio.Application : GioApp = Application;
    import gtk.Application : Application;
    import gtk.ApplicationWindow : ApplicationWindow, GApplicationFlags;

    auto app = new Application("org.gitlab.radagast.gtkdnotes", GApplicationFlags.FLAGS_NONE);
    app.addOnActivate(delegate void(GioApp _) {
        auto aw = new ApplicationWindow(app);
        scope (success)
            aw.showAll();
        aw.setTitlebar(() {
            import gtk.HeaderBar : HeaderBar;

            auto hb = new HeaderBar();
            hb.setTitle("Label");
            hb.setSubtitle("Demo");
            hb.setShowCloseButton(true);
            return hb;
        }());
        aw.add(() {
            import gtk.Label : Label;
            import gtk.Box : Box;
            import gtkc.gtktypes : GtkOrientation;

            auto vbox = new Box(GtkOrientation.VERTICAL, 5);
            vbox.packStart(() {
                auto hbox = new Box(GtkOrientation.HORIZONTAL, 10);
                hbox.packStart(new Label("This is a normal label"), true, true, 0);
                hbox.packStart(() {
                    auto lb = new Label(L1);
                    lb.setLineWrap(true);
                    return lb;
                }(), true, true, 0);
                return hbox;
            }(), true, true, 0);
            return vbox;
        }());
    });
    return app.run(args);
}

Note that the window cannot be shrunk vertically.

output

pardon the incomplete code, here is the complete code:


immutable string L1 = "This is an example of a line-wrapped label.  It "
    ~ "should not be taking up the entire             " ~ "width allocated to it, but automatically "
    ~ "wraps the words to fit.\n" ~ "     It supports multiple paragraphs correctly, "
    ~ "and  correctly   adds " ~ "many          extra  spaces. ";

int main(string[] args) {
    import gio.Application : GioApp = Application;
    import gtk.Application : Application;
    import gtk.ApplicationWindow : ApplicationWindow, GApplicationFlags;

    auto app = new Application("org.gitlab.radagast.gtkdnotes", GApplicationFlags.FLAGS_NONE);
    app.addOnActivate(delegate void(GioApp _) {
        auto aw = new ApplicationWindow(app);
        scope (success)
            aw.showAll();
        aw.setTitlebar(() {
            import gtk.HeaderBar : HeaderBar;

            auto hb = new HeaderBar();
            hb.setTitle("Label");
            hb.setSubtitle("Demo");
            hb.setShowCloseButton(true);
            return hb;
        }());
        aw.add(() {
            import gtk.Label : Label;
            import gtk.Box : Box;
            import gtkc.gtktypes : GtkOrientation;

            auto vbox = new Box(GtkOrientation.VERTICAL, 5);
            vbox.packStart(() {
                auto hbox = new Box(GtkOrientation.HORIZONTAL, 10);
                hbox.packStart(new Label("This is a normal label"), true, true, 0);
                hbox.packStart(() {
                    auto lb = new Label(L1);
                    lb.setLineWrap(true);
                    return lb;
                }(), true, true, 0);
                return hbox;
            }(), true, true, 0);
            return vbox;
        }());
    });
    return app.run(args);
}

Re: Mysterious vertical padding in Box

On 10/9/18 6:47 PM, aedt wrote:

Hi. I can't figure out why there is a massive space between the vertical borders and the box in the middle?

Try setting the minimum height/width of the label with
setSizeRequest(width, height) the label can't base it's requested with
on the with of the parent container.

On my machine this lead to a label with a minimum height based on the
height needed when every word is wrapped, leading to a lot of empty
space above and below the label, unless i drag the window to its minimum
with.

Re: Mysterious vertical padding in Box

On Tue, 9 Oct 2018 19:37:14 +0200, Mike Wey wrote:

On 10/9/18 6:47 PM, aedt wrote:

Hi. I can't figure out why there is a massive space between the vertical borders and the box in the middle?

Try setting the minimum height/width of the label with
setSizeRequest(width, height) the label can't base it's requested with
on the with of the parent container.

On my machine this lead to a label with a minimum height based on the
height needed when every word is wrapped, leading to a lot of empty
space above and below the label, unless i drag the window to its minimum
with.

Thanks, that helped.