www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - GTKD - Attach Button to Grid in specific column and row

reply TheDGuy <a.b gmail.com> writes:
Hi,
i am wondering why this code doesn't work, even though i set the 
column and row position of the button it is always placed at the 
top left (so basically first row and first column):

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

         Button btn = new Button();
         btn.setSizeRequest(25,25);
         btn.setLabel("Exit");
         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();
     }
Jun 11 2016
parent reply Mike Wey <mike-wey example.com> writes:
On 06/11/2016 04:57 PM, TheDGuy wrote:
 Hi,
 i am wondering why this code doesn't work, even though i set the column
 and row position of the button it is always placed at the top left (so
 basically first row and first column):

    ... Code ...
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(); } -- Mike Wey
Jun 11 2016
parent reply TheDGuy <a.b gmail.com> writes:
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(); }
Jun 14 2016
parent Mike Wey <mike-wey example.com> writes:
On 06/14/2016 04:54 PM, TheDGuy wrote:
 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.

 ....
Thanks for your reply, but now the button is always on the bottom right :( ....
What are you trying to accomplish? -- Mike Wey
Jun 14 2016