Scene2d - absolute positioning - libgdx

I want to add 3 numbers next to each other on the same row in a table, I also want there to be about 100 units padding between each number. Under these numbers are words that correspond to them, for example:
0 0 0
Total Wins Losses
However, if the I use padding, ie table.add(actor).padLeft(100);, then changing the number from say 0 to 160 would also move the number to the right, since I'm using padding. example:
160 0 0
Total Wins Losses
How can I avoid this behaviour? It must be a common scenario.

I suggest to create a custom class that extends the WidgetGroup.
Inside this class you manage two labels, one for the number and one for the "label" of the number.
Then you can easily set the relative position of the labels respect each other without keeping in mind where they are positioned inside the tabel.
Maybe the constructor of this special class could accept a String for the "label" and the initial value of the number.
Tell me if the idea it's clear or if you need more info.
Luca

What I would do is set all the cells in the table to be centred, by default, with a little padding on left and right, as follows:
Table table1 = new Table();
// Set defaults for all cells in table. Alignment and padding in this case.
table1.defaults().align(Align.center).pad(0, 20, 0, 20);
Label number1 = new Label("160", skin);
Label number2 = new Label("0", skin);
Label number3 = new Label("0", skin);
table1.add(number1);
table1.add(number2);
table1.add(number3);
table1.row();
Label label1 = new Label("Total", skin);
Label label2 = new Label("Wins", skin);
Label label3 = new Label("Losses", skin);
table1.add(label1);
table1.add(label2);
table1.add(label3);
table1.row();
Try that.

Related

Additional legend or text box window in a plot in octave

I would like to add to my plot a text or a legend box with comments.
At the moment my legend is plot at northeastoutside and i would like to add the new legend (or textbox) to the position southeastoutside.
Thanks!
Lacking more information about your case:
To the best of my knowledge one axes object can only have a single legend object. You can create a second legend with a second axes object. Each legend will only list data elements associated with each axes. Adapted from Matlab Newsgroup thread
a = [1:0.01:2*pi]; %create sample data
b = sin(a);
linehandle1 = line(a,b); %creates a line plot with handle object
axeshandle1 = gca; % gets the handle for the axes object just created
legendhandle1 = legend('y = sin(x)', 'location', 'northeastoutside'); %makes first legend
axeshandle2 = axes('Position',get(axeshandle1,'Position'),'xlim',get(axeshandle1,'xlim'),'ylim',get(axeshandle1,'ylim'),'Visible','off','Color','none'); %makes invisible axes with same position and scaling
linehandle2 = line(pi/2,1,'Color','r','Marker','o','Parent',axeshandle2); %puts data set on 2nd axes
linehandle3 = line(pi,0,'Color','b','Marker','x','Parent',axeshandle2);
legend_handle2 = legend('peak','zero','location','southeastoutside'); %creates legend to go with 2nd axes
If you just want text in that 2nd box, not necessarily legend info or data labels, you can play around with annotation as described above. This has the advantage of being simpler to call, but maybe harder to get the exact position/result you want. There are a large number of property options that can be adjusted to get the desired appearance. A few are shown in the example. It may be there are easier ways to set the size/position based on the legendhandle.
a = [1:0.01:2*pi]; %create sample data
b = sin(a);
plot(a,b);
legendhandle = legend('y = sin(x)','location','northeastoutside');
annotation('textbox',[0.875 0.1 0.1 0.1],'string','my text','edgecolor','k','linewidth',1,'fitboxtotext','off');

Item renderer for dynamic DataGrid

I have a problem with dynamic item renderer for data grids elements.
I'm initialiizng columns in my data grid dynamically, like this:
for each (var item in _collection)
{
var i:MyClass= item as MyClass;
var dgc:DataGridColumn = new DataGridColumn(i.Id.toString());
dgc.headerText = i.Name;
cols.push(dgc);
}
_myDataGrid.columns = cols;
To every cell I want to pass integer. When it has -1 value, cell should display specific text but when it's 0 or 1 it should contain checkbox.
Do you know how can I achieve that? I don't any ideas for now, despite I was thinking about this for quite long time. Can you help me with this?
Create itemRenderer with two states. One state with checkbox another with text

QTextBlockFormat.setLeftMargin(1em): How To?

In a html-list with bullets, on change of the fontsize via format.setFontPointSize() the bullets drive out of the editor. I figured out the bullets stay on the same position on fontsize-change if I set the padding-left to 1em (tried this in a html-editor).
How can I achieve this for a list entry in Qt? Can I only set it to a pixel value and not to an element value?
fmt=cur.charFormat()
charSize=fmt.fontPointSize()
if charSize==0.0:
charSize=14
if direction=="up":
fmt.setFontPointSize(charSize+1)
if textList:
blockFormat=cur.blockFormat()
#blockFormat.setLeftMargin(blockFormat.leftMargin()+0.4)
blockFormat.setLeftMargin(1em)
cur.mergeBlockFormat(blockFormat)
else:
fmt.setFontPointSize(charSize-1)
if textList:
blockFormat=cur.blockFormat()
#blockFormat.setLeftMargin(blockFormat.leftMargin()-0.4)
blockFormat.setLeftMargin(1em)
cur.mergeBlockFormat(blockFormat)
cur.mergeCharFormat(fmt)
You can set the default indentation for text lists in the QTextDocument instance that you are creating (I think the default is 40). Multiples of this value will be used for each indentation level in the list.
QTextDocument *doc = new QTextDocument();
doc->setIndentWidth(20);
QTextCursor *cursor = new QTextCursor(doc);
QTextListFormat listFormat;
listFormat.setIndent(1); // First indent level, indent is 20
cursor->insertList(listFormat);
// Insert items into the list
listFormat.setIndent(2); // Second indent level, indent is 40
cursor->insertList(listFormat);
// Insert nested list items

GWT Label alignments and CSS

I am having some trouble with GWT Labels and html/css.
I have a horizontalPanel, and I am trying to align the 2 labels so that each 1 is on an end of the Horizontal Panel
1) [Label 1 --~500px-- Label 2]
However, it seems that the 500 px is divided up into 250px each for a label, and theres a white space. (First I tried to make it like like this)
2) [Label 1 Label 2 --~500 whitespace px-- ]
but what happens is this
3) [Label 1 -~250 whitespace px- Label 2 -~250px whitespace-- ]
I would like It to be like 2) so then i can set the HorizontalAllignment on the Horizontal Panel to ALIGN_JUSTIFY which would put on one each end. I have no idea how to do it. I tried using display: inline but that doesnt seem to work as I hoped (it makes the border just go around the text but the whitespace is there)
Here is the code I am messing around with .border is just (border: 1px solid Red) so i can visualize how the border and size is calculated
HorizontalPanel p = new HorizontalPanel();
p.setWidth("500px");
//p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
//p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_JUSTIFY);
Label l1 = new Label("Label 1");
Label l2 = new Label("Label 2");
l1.addStyleName("border");
l2.addStyleName("border");
p.add(l1);
p.add(l2);
I just threw this together from memory, give it a try and let me know if it works like you expect.
HorizontalPanel p = new HorizontalPanel();
p.setWidth("500px");
p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_JUSTIFY);
Label l1 = new Label("Label 1");
Label l2 = new Label("Label 2");
l1.addStyleName("border");
l2.addStyleName("border");
p.add(l1);
p.setCellHorizontalAlignment(l1, HasHorizontalAlignment.ALIGN_LEFT);
p.add(l2);
p.setCellHorizontalAlignment(l2, HasHorizontalAlignment.ALIGN_RIGHT);
If that doesn't work, have you tried setting text-align:right; in your css for the second label?

Want to get cursor position within textInput

I am using textInput within grid using rendrer. I am populating a suggestion box just below the text input field on the basis of typed character and index of text input.Problem is that if i shrink grid column then suggestion box is not populating at the right place so I want global position of cursor in the text input field .
Something like that:
var inputTxt : TextInput = new TextInput;
var x : Number = inputTxt.cursorManager.currentCursorXOffset;
var y : Number = inputTxt.cursorManager.currentCursorYOffset;
Try using 'global coordinate'.
This might resolve your problem.