On Saturday, 11 June 2016 at 21:14:43 UTC, Mike Wey wrote:
The way GTK manages width and height, usually widgets are given the minimum size they need. So when the button is the only widget in the grid the other rows and columns have a height/width of 0.

You can force the button / gird cell to the bottom left by setting the expand and alignment properties of the button.

this(int width, int height, string title){
        super(title);
        setDefaultSize(width,height);

        Button btn = new Button();
        btn.setSizeRequest(25,25);
        btn.setLabel("Exit");
        btn.setVexpand(true);
        btn.setHexpand(true);
        btn.setHalign(Align.END);
        btn.setValign(Align.END);
        auto call = &enterEvent;
        btn.addOnEnterNotify(call);
        btn.addOnLeaveNotify(call);

        Grid grid = new Grid();
        grid.setColumnSpacing(6);
        grid.setRowSpacing(6);
        grid.attach(btn,3,3,1,1);
        add(grid);

        showAll();
    }

Thanks for your reply, but now the button is always on the bottom right :(

    this(int width, int height, string title){
        super(title);
        setDefaultSize(width,height);

        Button btn = new Button();
        btn.setSizeRequest(25,25);
        btn.setLabel("Exit");
        btn.setVexpand(true);
        btn.setHexpand(true);
        btn.setHalign(Align.END);
        btn.setValign(Align.END);

        Grid grid = new Grid();
        grid.setColumnSpacing(6);
        grid.setRowSpacing(6);
        grid.attach(btn,4,4,1,1);
        add(grid);
        showAll();
    }

Reply via email to