User Tools

Site Tools


script_always_top_indicator

====== About the script ====== * Purpose : This is a script that places an item as an indicator always on top, that is replaced by the next one when reached. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/+TrianguloY/posts/CR2Mj15DTLe (with video) ====== How to use the script ====== Instructions: - Label the items "indicator 0", "indicator 1", and so on starting from top, otherwise it will behave wrong. - Unzoom (or zoom) to move all the items to their positions. Use this specially when editing. - Newly created items are prepared (tag saved and detached from grid) automatically. But - To modify a previously saved one, run the script from the item (to save only that item), or from the container (to save all items, make sure all are in the right position) Important note: For me it works smooth and lag-free with 3,4 items. Didn't tested with more but if it works slow for you, try to change the AUTOREFRESH to false, keeping in mind you will need to run the script after any change you make, even when adding new items. ====== Script code ====== <sxh javascript> //Indicators by +TrianguloY /*Reminder: the items need to be labeled "indicator 0" "indicator 1" "indicator 2" ... Unzoom (or zoom) to move all indicators to their original positions, then you can edit easily. Running the script in the container (save all) or item (save that item) to force a save of the position of the indicator. Use this after modifying manually one. (not necessary with newly created ones) Set the AUTOREFRESH to true if you have a lot of indicators and it lags a bit. Keep in mind you will need to unzoom/force a save/restart the launcher to apply new changes */ var AUTOREFRESH = true; var ev=LL.getEvent(); var cont=ev.getContainer(); var cy=cont.getPositionY(); //flags var inactive=cont.getPositionScale()!=1;//to disable when zoom var reset=ev.getSource()!="C_POSITION_CHANGED";//to reset at desired var resetid=-1; if(reset&&ev.getItem()!=null){resetid=ev.getItem().getId();reset=false;} if(AUTOREFRESH||reset||resetid!=-1||!("indicator_items" in this)){ //create the array of indicators (indicator_items) indicator_items=[]; var l=0; while(true){ var p=cont.getItemByName("indicator "+l); if(p==null)break; indicator_items[l++]=p; } } //asignating position var last=Math.infinity; for(var t=indicator_items.length-1;t>=0;--t){ var item=indicator_items[t]; var iy=getiy(item); var ny; if((cy<=iy&&t!=0)||inactive||reset){ //set the item in their position ny=iy; }else{ //set the item above the previous one var o=item.getHeight()-last; ny=cy-(o>0?o:0); } //set and save item.setPosition(item.getPositionX(),ny); last=ny-cy; } function getiy(item){ //get the saved tag, otherwise, prepare the item; var d=item.getTag("indicator"); if(d!=null && !reset && resetid!=item.getId())return parseInt(d); //if no tag found or reset active d=item.getPositionY(); item.setTag("indicator",d); item.getProperties().edit().setBoolean("i.onGrid",false).commit();//properties set return d; } </sxh>

script_always_top_indicator.txt · Last modified: 2018/08/14 16:53 by f43nd1r