Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 7:54 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Oct 11, 2012 8:15 pm 
Offline

Joined: Tue Sep 18, 2012 12:33 pm
Posts: 10
Hi there,

I am having some troubles with the DialogLayout. After I figured out, how to set the position of all widgets in a DialogLayout, now I have the problem to set the sizes of the widgets.
The problem is the following: I have just three buttons in one DialogLayout, all centered to the middle of the screen (horizontally).
But every button has a different size (depending on its caption).

Here is a screen picture of the program:
http://s14.directupload.net/file/d/3040/n626hh3z_png.htm

I already read that you should not call setSize() or something equals somewhere else than in the layout() method.
So, is it possible, to make the buttons have all the same size, but all depending on the size of the screen (for different resolutions).

My code is here:
Code:
private void initMainMenu(){
      mainMenu = new DialogLayout();
      mainMenu.setClip(true);
      mainMenu.setTheme("");
      
      startGameButton.setTheme("button");
      startGameButton.setModel(new SimpleButtonModel());
      startGameButton.setFont(theme.getDefaultFont());
      startGameButton.addCallback(new Runnable() {
         
         @Override
         public void run() {
            startGameMenu.setVisible(true);
            mainMenu.setVisible(false);
         }
      });
      

      loadSettingButton.setTheme("button");
      loadSettingButton.setModel(new SimpleButtonModel());
      loadSettingButton.setFont(theme.getDefaultFont());
      loadSettingButton.addCallback(new Runnable() {
         
         @Override
         public void run() {
            // TODO Auto-generated method stub
         }
      });

      endGameButton.setTheme("button");
      endGameButton.setModel(new SimpleButtonModel());
      endGameButton.setFont(theme.getDefaultFont());
      endGameButton.addCallback(new Runnable() {
         
         @Override
         public void run() {
            System.exit(0);
         }
      });
      
      mainMenu.setDefaultGap(new Dimension(0, solution.y/5));
      
      DialogLayout.Group mainMenuGroupHorizontal = mainMenu.createParallelGroup();
      DialogLayout.Group mainMenuGroupVertical = mainMenu.createSequentialGroup();
      
      mainMenuGroupHorizontal.addWidget(startGameButton, Alignment.CENTER);
      mainMenuGroupHorizontal.addWidget(loadSettingButton, Alignment.CENTER);
      mainMenuGroupHorizontal.addWidget(endGameButton, Alignment.CENTER);
      
      mainMenuGroupVertical.addGap(solution.y/5);
      mainMenuGroupVertical.addWidget(startGameButton);
      mainMenuGroupVertical.addWidget(loadSettingButton);
      mainMenuGroupVertical.addWidget(endGameButton);
      
      mainMenu.setHorizontalGroup(mainMenuGroupHorizontal);
      mainMenu.setVerticalGroup(mainMenuGroupVertical);
   }


Greetings,
M0rgenstern


Last edited by M0rgenstern on Thu Oct 11, 2012 10:10 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Oct 11, 2012 8:31 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Set a maxWidth of MAX for these buttons in the theme:
Code:
<param name="maxWidth"><constant>MAX</constant></param>
alternatively set the maxWidth to 32767 which is the same as MAX.

Use a sequential group for horizontal which will have 3 children:
1) a flexible gap: addGap()
2) a parallel group which contains all your buttons and a fixed width gap: addGap(int)
3) another flexible gap

The flexible gap on both sides will center the buttons horizontally by consuming half of the remaining space each.
The fixed gap in parallel enforces a width on the variable sized buttons (read the javadoc of Widget.setMaxSize).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Oct 12, 2012 5:04 pm 
Offline

Joined: Tue Sep 18, 2012 12:33 pm
Posts: 10
Hey.
Thank you for your response.
I think, I did what you suggested, but that does not help. Actually nothing really changed.

Here is the new code of the Layout-Part:

Code:
mainMenu.setDefaultGap(new Dimension(0, solution.y/5));
      
      DialogLayout.Group mainMenuGroupHorizontal = mainMenu.createSequentialGroup();
      DialogLayout.Group mainMenuGroupVertical = mainMenu.createSequentialGroup();
      
      mainMenuGroupHorizontal.addGap();
      
      DialogLayout.Group mainMenuHorizontalMid = mainMenu.createParallelGroup();
      mainMenuHorizontalMid.addWidget(startGameButton, Alignment.CENTER);
      mainMenuHorizontalMid.addWidget(loadSettingButton, Alignment.CENTER);
      mainMenuHorizontalMid.addWidget(endGameButton, Alignment.CENTER);
      mainMenuHorizontalMid.addGap(solution.x/3);
      
      mainMenuGroupHorizontal.addGroup(mainMenuHorizontalMid);
      
      mainMenuGroupHorizontal.addGap();
      
      mainMenuGroupVertical.addGap(solution.y/5);
      mainMenuGroupVertical.addWidget(startGameButton);
      mainMenuGroupVertical.addWidget(loadSettingButton);
      mainMenuGroupVertical.addWidget(endGameButton);
      
      mainMenu.setHorizontalGroup(mainMenuGroupHorizontal);
      mainMenu.setVerticalGroup(mainMenuGroupVertical);


Top
 Profile  
 
PostPosted: Fri Oct 12, 2012 5:55 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Try changing the Alignment.CENTER to Alignment.FILL

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group