LibGDX internal button spacing - java

I am trying to a create a gui in libGDX, but I am having problems with my buttons.
I am currently using a 9patch image for my button, which looks like this:
This button scales perfectly well, it's just that when I add text to the button there is too much space between the top of the button, and the top of this text. Like this:
The red line marks the amount of space between the top of the button and the top of the text. This space is too large, and I am wondering if there is any way to reduce it.
The font I am using is not scaled, and it is a normal BitmapFont with no filter. Regardless of the scale, the space between the text and the top edge is always proportionate, meaning that the space still looks the same size when I am using a small font or a large font, relative to the text size.
Any suggestions would be appreciated.

To solve this problem I did the following.
When adding the button to the table, I used the following Code.
table.add(button).height(HEIGHT).width(WIDTH);
This did not solve the mentioned issue, but it allowed me to explicitly set the desired width and height of the button, which played a part in solving the actual issue.
When creating the button, the button, being an extension of Cell, I used to add() function to re-position the text.
button = new TextButton("button", style);
button.add(button.getLabel()).padBottom(CONSTANT);
combined with the Cell.height() function, I was able to use a constant padding variable to position the button's text (or label) in the middle of the button.

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.

Blackberry (Java) - Setting scrolling be not focused on objects on the screen

I have a mainscreen which currently scrolls (and I have the arrows on the right) but the scrolling seems to be focused on the ButtonField objects that I have on the page. Is there any way to set the scrolling to be non-focused scrolling (moving a few pixels each time). Is there a way to set this?
Other ideas I have had (which sound hacky so I want to avoid):
- Placing NullFields around to scroll
- Manually listening to the trackwheelRoll event and moving appropriately
That's not really how scrolling works on trackball BlackBerry devices. It's always based on the change of focus from one field to another. The only time the whole screen may scroll "smoothly" is when there are no fields that accept focus (or on touchscreen devices such as the Storm).
To use an analogy: just think of each focusable field on the screen as being like a line of text in a text editor. Just by moving the cursor with the arrow keys, you can get the screen to scroll but only when the cursor hits the edge of the current visible screen, and then only to the next line in a one-line increment. On trackball BlackBerrys, the trackball is the equivalent of the arrow keys -- and unfortunately there isn't an analog to "smoothly dragging the scrollbar with a mouse" in the text editor. Hope this makes sense!

SWT ScrolledComposite cutting off information.

I'm making an application that has many lines of data coming back from a Database stub(which will become an Oracle database), and for some reason the scroll bar stops at about the 500th element. I'm wondering if there's anyway to have all the elements show within the scroll bar.
I'm assuming here that you're using Windows, because there is a fairly general problem with scrollbars on Windows: the maximum value is a short int, 32,768. Therefore, if the height of the inner composite of a ScrolledComposite is greater than 32,768 pixels, the composite will be clipped.
I haven't found a robust way of fixing this, but there is a workaround: separate the scrollbar from the composite that you wish to scroll. You can't create a ScrollBar, but you can make a ScrolledComposite that is precisely as wide as a ScrollBar, then attach a ScrollListener to it and have it adjust the layout position of the scrolling composite.
Somewhere I have a snippet, but I'm not even exactly sure if this diagnosis applies to your scenario.
You might need to set the minimum and maximum values of the ScrollBar. You would use the setMinimum() and setMaximum() methods, respectively.
It's also a good idea to set the page increment. This is the number of scroll lines that the selected value changes by when the user clicks the area between the thumb and the arrow buttons, or presses the Page Up or Page Down buttons. You would use the setPageIncrement() method.
Finally, Oracle may impose a maximum number of rows you can retrieve from a table. I believe the default is 500 rows.

Dynamically changing the tooltip of a draw2d figure

We are currently using Eclipse Draw2D/GEF for an information page describing a process in our application. This basically consists of a matrix of large squares, each containing a matrix of smaller squares. We originally had all the squares as GEF objects, but because of the large volume of them being shown, we found that this did not scale very well and the view took a very long time to open. We then changed it so that only the large squares are Figures and we then draw the smaller squares using the graphic in paintFigure.
The problem that we are running into is that we still want the tooltip to change depending on which small square you are hovering over. I tried to do this by adding a mouseMotionListener and setting the tooltip, through setTooltip, depending on where the mouse currently is. The problem is that once the tooltip is displayed, it does not change any more when setTooltip is called.
Does any one know of an alternative way of doing this? Is there a way of getting the viewpart's PopupHelper and using that? Any help would be appreciated.
Thanks
Hmnn.. interesting problem. Since you paint your own Grid within the Figure, I would think that you have two options.
Try posting SWT events to fool Eclipse. I'd try a focus lost followed by a focused gained, to trigger tooltip machinery, at which point you could get the coordinates and display the appropriate contents.
Don't use the Figure#getTooltip strategy at all. Just show your own composite.
To dynamically change the tooltip, you can hold an instance of the tooltip Figure in your parent Figure. In the constructor of the parent Figure, create a new tooltip Figure (e.g. a Label) and use setToolTip() method to set the tooltip Figure to parent Figure.
When data model is changed, the updated tooltip text/icon can be set to the tooltip Figure. Then you just call setToolTip(tooltipFigure) method again.
You can have a method like:
protected Label toolTipLabel;
protected void updateToolTip(String text, Image icon){
toolTipLabel.setText(text);
toolTipLabel.setIcon(icon);
setToolTip(toolTipLabel);
}
The updateToolTip() method can be invoked in parent Figure's conturctor to initialize the tooltip. And this method can be invoked each time after the data model is changed.
I encountered the same problem in my code and solved it with that method. In my code, I invoked the updateToolTip() in the parentFigure.paintFigure() method.

Libgdx ImageButton padding?

so I have this problem with ImageButton class of libgdx, the problem is that in android the image doesnt expand to the full size of the button, and in desktop it does or at least it does more, so I have to ask if theres a way to force the image to get the size of the background(button)? so i can try to make an equal visualitation on both plataforms.
heres a screen shot, the back space button is the ImageButton...
edit: heres the code....
private void createButtons() {
ImageButtonStyle ibs = new ImageButtonStyle(buttonD,buttonD_p,buttonD,bsIcon,bsIcon,bsIcon);
buttonBS = new ImageButton(ibs); // This is the backspace button
....
}
private void addButtonsToTable() {
float pad = 1;
float BUTTON_SIZE = this.BUTTON_SIZE - pad *3;
table.top();
table.center();
table.add(buttonBS).width(BUTTON_SIZE).height(BUTTON_SIZE).pad(pad);
table.row();
...
}
If you want the image to be the background instead of just an icon, you should consider using plain Button or TextButton instead of ImageButton. ImageButton should be used only for buttons that draw an icon additionally to its background. An example of ImageButton usage could be the window closing button with the "X" (cross) image, or music toggle button with a loudspeaker icon.
When you need the image to fill the whole button area, set it as ButtonStyle#up - it will become button's background. ImageButton#imageUp is just an icon that will not be scaled in any way (by default), so that might be the reason why your application behaves differently on each platform.
(Although it still shouldn't, unless you use different assets.)
If you need an icon and still want to use ImageButton, consider that internally it is just a Button with an Image instance added to one of its cells (Button is a Table). You can use ImageButton#getImageCell() to access Cell in which the Image is stored and modify it - for example, force a specific width and height. You might also want to use ImageButton#getImage() to change scaling with Image#setScaling(Scaling).
Anyway, creating styles at runtime can be error-prone - the style constructor is huge and I'm honestly unable to guess which drawable draws what without checking out image button style sources. You should consider using Skin and define your styles with JSON files (you can find some free themes here).

Categories

Resources