Slick Forums

Discuss the Slick 2D Library
It is currently Thu Jun 20, 2013 12:22 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Tables and layout
PostPosted: Wed Aug 22, 2012 5:08 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
By default, my table is all mushed up and have to drag the window down. I've override layout() but can't get it to come in correctly:

http://i.imgur.com/fFlK5.png

Also, code wise, is there any better way to do this?

I'm using an old TWLComboBoxCellWidgetCreator class that extends CellWidgetCreator in addition to a ComboBoxValue extends SimpleIntegerModel from TWLExamples TableDemoDialog1.java.

Is there a better way to do a table?


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Wed Aug 22, 2012 5:37 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
Hmm - did you put the Table into a ScrollPane? You could try to apply a "minHeight" parameter to the ScrollPane (or to the Table if you don't use a ScrollPane).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Wed Aug 22, 2012 6:08 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
No, should I be? I add the table to the dialoglayout widget (which was added to resizableframe-title)

also this is weird, if I set VSYNC (in slick via lwjgl); it doesn't render right: http://i.imgur.com/CXqV3.png

hrm, it looks like I could use this as a new staring point? http://hg.l33tlabs.org/twlexamples/file ... alog1.java


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Wed Aug 22, 2012 4:59 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
Huh - how can Vsync affect the rendering ?!?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Thu Aug 23, 2012 3:11 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
not sure about vsync, only happens on one computer so I'll check more.

But in regards to tables, trying to start fresh using this as an example: http://hg.l33tlabs.org/twlexamples/file ... alog1.java

I'm trying to add it to a DialogLayout, but comes out funny if I set nothing or try setSize, setMinSize, @override layout, etc, etc... just looks odd: http://i.imgur.com/pxnUP.png

It seems that Table has different behavior than other widgets in regards to sizing?

Code:
public class DialogAdvancedSettingsTest  extends DialogLayout {

   private ScrollPane scrollPane;

   public DialogAdvancedSettingsTest() {
      setTheme("AdvancedSettings");
      
      final ListModel<String> cbm = new SimpleChangableListModel<String>("Hallo", "Welt", "Test");
      final ComboBoxValue cbv = new ComboBoxValue(0, cbm);
      TableModel m = new AbstractTableModel() {
         public int getNumRows() {
            return 20;
         }

         public int getNumColumns() {
            return 3;
         }

         public String getColumnHeaderText(int column) {
            return "Column " + column;
         }

         public Object getCell(int row, int column) {
            if (row == 7 && column == 1) {
               // This cell will contain a ComboBoxValue - via registerCellRenderer
               // below this will cause a comobox to appear
               return cbv;
            }
            if (row == 6 && column == 1) {
               return "Selected: " + cbv.getValue();
            }
            return "Row " + row + (((row * getNumColumns() + column) % 17 == 0) ? "\n" : "") + " Column " + column;
         }

         @Override
         public Object getTooltipContent(int row, int column) {
            return "X:" + (column + 1) + " Y:" + (row + 1);
         }

      };

      Table t = new Table(m);
      // register the ComboBoxValue class (see below) and it's cell widget creator
      // this will change the behavior of cells when they contain a data valzue of
      // the type "ComboBoxValue"
      t.registerCellRenderer(ComboBoxValue.class, new ComboBoxCellWidgetCreator());

      t.setTheme("table");
      t.setVaribleRowHeight(true);
      t.setDefaultSelectionManager();

   
      
      add(t);
      
      
   }

   public void centerScrollPane() {
      scrollPane.updateScrollbarSizes();
      scrollPane.setScrollPositionX(scrollPane.getMaxScrollPosX() / 2);
      scrollPane.setScrollPositionY(scrollPane.getMaxScrollPosY() / 2);
   }

   /**
    * This is a very simple model class which will store the currently selected entry of the combobox and the model for
    * the combobox.
    *
    * It is also the "key" type which will cause the cell to become a ComboBox
    */
   public static class ComboBoxValue extends SimpleIntegerModel {
      private final ListModel<String> model;

      public ComboBoxValue(int value, ListModel<String> model) {
         super(0, model.getNumEntries() - 1, value);
         this.model = model;
      }

      public ListModel<String> getModel() {
         return model;
      }
   }

   /**
    * A CellWidgetCreator instance is used to create and position the ComboBox widget inside the table cell. This class
    * is also responsible to connect all listeners so that updates to/from the combobox can happen.
    *
    * Only a single ComboBoxCellWidgetCreator will be created per table. But it can manage several widgets/cells.
    *
    * As this is a simple example only the listener ComboBox -> ComboBoxValue is implemeted.
    */
   private static class ComboBoxCellWidgetCreator implements CellWidgetCreator {
      private int comboBoxHeight;
      private ComboBoxValue data;

      public void applyTheme(ThemeInfo themeInfo) {
         comboBoxHeight = themeInfo.getParameter("comboBoxHeight", 0);
      }

      public String getTheme() {
         return "ComboBoxCellRenderer";
      }

      /**
       * Update or create the ComboBox widget.
       *
       * @param existingWidget
       *            null on first call per cell or the previous widget when an update has been send to that cell.
       * @return the widget to use for this cell
       */
      public Widget updateWidget(Widget existingWidget) {
         MyComboBox cb = (MyComboBox) existingWidget;
         if (cb == null) {
            cb = new MyComboBox();
         }
         // in this example there should be no update to cells
         // but the code pattern here can also be used when updates are
         // generated. Care should be taken that the above type cast
         // does not fail.
         cb.setData(data);
         return cb;
      }

      public void positionWidget(Widget widget, int x, int y, int w, int h) {
         // this method will size and position the ComboBox
         // If the widget should be centered (like a check box) then this
         // would be done here
         widget.setPosition(x, y);
         widget.setSize(w, h);
      }

      public void setCellData(int row, int column, Object data) {
         // we have to remember the cell data for the next call of updateWidget
         this.data = (ComboBoxValue) data;
      }

      public Widget getCellRenderWidget(int x, int y, int width, int height, boolean isSelected) {
         // this cell does not render anything itself
         return null;
      }

      public int getColumnSpan() {
         // no column spanning
         return 1;
      }

      public int getPreferredHeight() {
         // we have to inform the table about the required cell height before
         // we can create the widget - so we need to get the required height
         // from the theme - see applyTheme/getTheme
         return comboBoxHeight;
      }

      /**
       * We need a subclass of ComboBox to contain ("be" in this example) the listeners.
       */
      private static class MyComboBox extends ComboBox<String> implements Runnable {
         ComboBoxValue data;

         public MyComboBox() {
            setTheme("combobox"); // keep default theme name
            addCallback(this);
         }

         void setData(ComboBoxValue data) {
            this.data = null;
            setModel(data.getModel());
            setSelected(data.getValue());
            this.data = data;
         }

         public void run() {
            if (data != null) {
               data.setValue(getSelected());
            }
         }
      }
   }

   @Override
   public void saveSettings() {

   }

}


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Thu Aug 23, 2012 7:04 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
Hmm - the table should report the needed size as preferred width/height but it didn't seem to compute that correctly. Try with this patch.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Mon Aug 27, 2012 2:36 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
Hmm - the table should report the needed size as preferred width/height but it didn't seem to compute that correctly. Try with this patch.



Is there a nightly build I can download that has this in? I tried the TWL.jar from main page and still occurring, dated the 26th (gmt +6)


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Mon Aug 27, 2012 8:03 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
You should have seen a warning "Dialog layout has incomplete state" as your DialogLayout has no groups defined - so it doesn't know how to place any of the children. Besides this obvious bug - I need a test case which shows the issue - as my tests seem to work.

As for the TWL.jar - this is the nightly build and it is up to date. You can check this with the VERSION file inside the TWL.jar

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Tue Aug 28, 2012 1:05 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
You should have seen a warning "Dialog layout has incomplete state" as your DialogLayout has no groups defined -


fixed, thanks.

Quote:
o it doesn't know how to place any of the children. Besides this obvious bug - I need a test case which shows the issue - as my tests seem to work.


I'm putting a Table into a DialogLayout inside a DialogLayout inside a ResiableFrame-title. Would that affect it?

Also I don't need a table per say, just for the columns to line up nicely. Is there a simple way to do that inside DialogLayout?

Quote:
As for the TWL.jar - this is the nightly build and it is up to date. You can check this with the VERSION file inside the TWL.jar


thanks, good to know.


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Tue Aug 28, 2012 5:39 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
Sure - you can just make a grid with DialogLayout - one parallel horizontal group for each column organized in a sequential group, and the other way around the rows.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Tue Aug 28, 2012 10:48 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
That's what I have, I think:
Code:
this.setHorizontalGroup(this
            .createParallelGroup()
            .addGroup(
                  this.createSequentialGroup(labelMusicVolume, musicVolumeAdjuster, labelMusicDisable,
                        musicDisableCheckBox))
            .addGroup(
                  this.createSequentialGroup(labelSoundVolume, soundVolumeAdjuster, labelSoundDisable,
                        soundDisableCheckBox))

      );
      this.setVerticalGroup(this
            .createSequentialGroup()
            .addGroup(
                  this.createParallelGroup(labelMusicVolume, musicVolumeAdjuster, labelMusicDisable,
                        musicDisableCheckBox))
            .addGroup(
                  this.createParallelGroup(labelSoundVolume, soundVolumeAdjuster, labelSoundDisable,
                        soundDisableCheckBox)));



By default it looks like this:
Image

But would like the columns lined up (sorry for bad photoshop skills):
Image


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Wed Aug 29, 2012 4:54 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
You need to make a parallel group for every columns like this (incomplete example):
Code:
Group h1 = createParallelGroup(labelMusicVolume, labelSoundVolume);
Group h2 = createParallelGroup(musicVolumeAdjuster, soundVolumeAdjuster);
..
setHorizontalGroup(createSequentialGroup(h1, h2, ...));


You could also use the ColumnLayout which makes this a bit easier.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Thu Aug 30, 2012 12:32 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
You need to make a parallel group for every columns like this (incomplete example):
Code:
Group h1 = createParallelGroup(labelMusicVolume, labelSoundVolume);
Group h2 = createParallelGroup(musicVolumeAdjuster, soundVolumeAdjuster);
..
setHorizontalGroup(createSequentialGroup(h1, h2, ...));


You could also use the ColumnLayout which makes this a bit easier.


Thanks. In regards to ColumnLayout, do any of the demo/examples use this? I tried to find some example code, but not sure any of them use it.


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Thu Aug 30, 2012 5:17 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1190
Currently not. You can use it like this:
Code:
Columns col = cl.getColumns("label", "adjuster", "label", "enable");
cl.addRow(cl).add(labelMusicVolume).add(musicVolumeAdjuster).add(labelMusicDisable).add(musicDisableCheckBox);
...
It is best suited for vertical dialogs like a property panel.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Tables and layout
PostPosted: Fri Aug 31, 2012 12:44 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
How to add to DialogLayout?

Code:
   ColumnLayout cl = new ColumnLayout();
      cl.addRow("label", "adjust", "label", "enable");
      Columns col = cl.getColumns("label", "adjuster", "label", "enable");
      cl.addRow(col).add(labelMusicVolume).add(musicVolumeAdjuster).add(labelMusicDisable).add(musicDisableCheckBox);

      setHorizontalGroup(cl.getHorizontalGroup());

      setVerticalGroup(cl.getVerticalGroup());
throws this:

Code:
[2012-08-30 19:39:47](SEVERE): Exception Error: Can't add group from different layout
[2012-08-30 19:39:47](SEVERE): java.lang.IllegalArgumentException: Can't add group from different layout


Code:
   ColumnLayout cl = new ColumnLayout();
      cl.addRow("label", "adjust", "label", "enable");
      Columns col = cl.getColumns("label", "adjuster", "label", "enable");
      cl.addRow(col).add(labelMusicVolume).add(musicVolumeAdjuster).add(labelMusicDisable).add(musicDisableCheckBox);

      add(cl);


This gives this error:
Code:
Aug 30, 2012 7:41:15 PM de.matthiasmann.twl.DialogLayout warnOnIncomplete
WARNING: Dialog layout has incomplete state


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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