How use ShapeRenderer along with ScrollPane in LibGDX? - java

Am currently making a game in LibGDX for Android. So far I have a ScrollPane with a table inside that contains a list with custom rows [AS SHOWN IN THE ATTACHED IMAGE]. I want each of those rows surrounded by a rectangle. Is it possible to achieve this?
These are the rows of the list

Since this has been viewed 100 times I might as well contribute even though it's almost 3 years old.
You can set debug on the child widget attached to the Scrollpane (which is probably a Table, so debugAll() or whatever you wish), which outlines the boundaries of the actors automatically.
This internally uses a Shaperenderer to do it from the Stage, and you can change the colour through the Table.debugTableColor, Table.debugCellColor, and Table.debugActorColor static fields.
Table.debugTableColor is for outlining the entire table, Table.debugCellColor is for each of the table's cells, and Table.debugActorColor is for the actors contained within each of the cells.
But yeah, this should only be used for debugging the layout.

Related

Expandable grid Vaadin UI

I have a simple grid. Two columns with a variable amount of rows. I want to make it so i have a header row with an arrow that can collapse and show the whole grid. So when I bring up the app, only the header row is visible with an arrow, and I can click to expand/collapse to show the rest of the grid.
A TreeGrid seems like overkill since I don’t need any hierarchical structure, just the ability to collapse/expand one row. I exclusively use IE and I’ve read that Drawyer doesnt work with IE 8 and above. I return a list of the objects and the object just has two string variables.
Any help with this? I am new to Vaadin 8.
Set grid height (workaround)
As a workaround, you could set the height to be approximately the number of pixels you expect to be the height of the header.
See the Sampler demo. Click the gear icon at top to expose properties of the example Grid object. The last property shown is "Size (W x H)". Change 100% to 100px to see the effect.
Grid height set to 100%
Grid height set to 100px
You can also hide the footer (see checkbox in that property list).
I don't think this can be done with plain Vaadin. But I recommend the following simpler approach:
Initially call grid.setHeightByRows(1.5) (javadoc). This will show exactly one row and a half to indicate more data is available. A scrollbar will appear, too.
Make a new column within the grid that has a button or add a button below the grid that - when clicked - calls setHeightByRows with the number of elements in the grid and hides the button. This will show all rows.

Java Swing. Add custom items to scroll pane (Tile selector)

I am currently working on a TiledMap editor for a game I am working on. I am now at the part where I need to implement a tile selector. I am pretty sure I would be able to do this in canvas and draw each tile individually and draw a box around the selected tile but I want to know if there is an easier, more professional looking way already implemented in java swing before I start making my own.
Here is a basic drawing of what I want:
Green boxes in tile selector are individual tiles and the one with bold blue it the selected one (Just a basic example, colors don't matter to me).
Additional Info: Each tile has it's own object, so if the solution involves an ArrayList or something, it would work very well. Also I would like to be able to manipulate which objects are shown in the selector or not. I have a search bar that I want to use to narrow down the tiles shown.
Thanks in advance, if you need more details, please ask.
A JList can display a collection of tile images just fine and would be the likely candidate for the tile selector component on the left.
Ok looks pretty good. How do you tell the JList what you want to be displayed about each item in the list. For my case I want to JList to display a simple image, not text, is that possible?
If you add Icons to the JList, they will be automatically displayed correctly. If you need to fine tune the display, then you will want to write a ListCellRenderer as per the tutorials and API.
Also, can it do lists with multiple columns?
If you mean multiple columns of the same thing, such as a 4x4 grid of images, then yes a JList can handle this great, and you would call setLayoutOrientation(JList.HORIZONTAL_WRAP) (or vertical wrap if desired). If you mean columns which each hold a different data type such as an image, text, a checkbox, then go with a JTable.

Is there always a natural "space" between cells in a table?

I created a table with "buttons" aligned onto my screen for my game I am using to learn libgdx. I want the buttons to squeeze together perfectly to form a seamless menu, however there seems to be a natural padding of 1 to 2 pixels between every cell.
Is there a way to remove that padding?
The code seems unnecessary but this is the contents of my table anyways:
table.add(buttonTyce).size(150,60).expandX().expandY().bottom().left().row();
table.add(buttonGrokk).size(150,60).bottom().left().row();
table.add(buttonCeleste).size(150,60).bottom().left().row();
table.add(buttonDaem).size(150,60).bottom().left().row();
table.add(buttonRisp).size(150,60).bottom().left().padBottom(80).row();
table.setFillParent(true);
stage.addActor(table);
Thank you for any help.
I don't think there is default space. Are you sure that the texture you are using for your buttons doesn't contain any transparent edges? Also, there's table.debug() (or something like that, check the docs) to draw lines around table cells for debugging such issues.

SWT Label Drag'n'Drop

I'm surprised to see that this hasn't been done, or at least my research says so.
I have a Canvas with RowLayout and a bunch of Labels.
The title is pretty straight forward: I want to reorder my labels using DND.
Please don't tell me I have to engineer my own algorithm for calculating bounds and sizes and stuff like that.
Later edit:
I'm considering using Zest, but again, I can't find any example where graph nodes are snapped to eachother.
I did something like this about a year ago.
My method of solving this problem was to use a data model to hold the label information. Use the canvas.getChildren() and search for a separator composite between each object or the label that you dropped on top of. When a drag and drop operation was completed you would search for the item that you dropped on and move the reference to the appropriate position in the model. Then reset the information on each label. Only requirement to do this is to keep a data structure with the label info and a reference to the canvas.

How to determine how far a scrollbar has moved in SWT?

Before Scroll
After Scroll
I am working on creating an Eclipse plugin for tracking of collections (Arrays, Array List, etc.). And I was in need of an SWT Table with expandable columns. In order to implement this, I created several SWT buttons, and generated them before I created the table, and I linked them to the columns that need to be expanded. What I'm having a problem with now is that I need a way to determine how much a user scrolled the scroll bar in order to determine what the new location of the buttons should be. For instance, if the user scrolls 10 pixels to the left, I need to move the buttons 10 pixels to the left, etc.
Is there an easy way to accomplish this within the SWT ScrollBar framework?
Actually, I was able to solve the problem by using Scrollbars "getSelection" method. Turns out, the value that this method represents is the offset from 0 of the scrollbar. In order to solve the problem, I just subtracted the getSelection value from the X position of the buttons

Categories

Resources