Hi, I’m writing a small script to add an item to desktop
Hi, I’m writing a small script to add an item to desktop
var l = LL.getCurrentDesktop();
var item=l.getItemByLabel(“foo”);
if (!item){
var item=l.addShortcut(“foo”,new Intent(),600,1200);
}
ce=item.getProperties().edit();
ce.setBoolean(“i.onGrid”,false);
ce.setString(“s.labelVsIconPosition”,”RIGHT”);
box=ce.getBox(“i.box”);
box.setAlignment(“LEFT”,”MIDDLE”);
ce.commit();
item.setSize(150,150);
item.setRotation(315);
Android.makeNewToast(“Done”,true).show();
It works, but item’s position is X 544,934 Y 1134,648. How to fix it?
If you create a new item, it’s normally attached to the grid, so you are setting it 1200 cells away. It’s best to first create an item at 0/0, then detach and move it.
Lukas Morawietz I need to check, but I think that when you use addShortcut, the x and y are always set in ‘detached mode’
Azariasz Trzciński the problem is that, as Lukas said, the item is set by default on grid mode, and it’s position is slightly altered to match the cell. For this reason when you detach it, it has different x and y.
You can either follow Lukas suggestion (I recommend that too) or in the container properties, layout, check ‘detach by default’
TrianguloY you’re right, the shortcut is created in the nearest cell.
Thanks!!! You’re very helpfull!
I think it’s because of rotation
Jappie Toutenhoofd is right too.
When you rotate an item, it is rotated keeping it’s center, it’s position is the top left corner of the minimum box containing the item and it change.
You should set the scale/size, rotation, and position in that order for exact precision