Create Slider component with mouseDragged

Hi
I try to create a new slider in ignition with mouseDragged event handler to change the position of my slider.
I use this code to slide my drag icon in mouseDragged event handler:

orignal x position in template for 0%

oriX = 7.0

Get the new mouse dragged position

x = event.x
if x - oriX <= 300 and x - oriX >= 0:
system.gui.transform(event.source, x)
event.source.parent.Tag = (x - oriX)/3
and following code in propertychange event on template to update icon position regard input tag:
oriX = 7.0
system.gui.transform(event.source.getComponent(‘Grapper’), event.source.Tag*3 + oriX)

I face two major problem:
1 - When I dragged the slider icon the mouse snap to the left edge of the icon instead of middle even I click on middle og the icon. I check and see the center point of the icon is in the center. This cause I have always a small error related to my gauge.
2 - Scaling the slider template cause every thing get messy because I use absolute value position but I don’t have any idea to fix it.

Can someone give some help to current it?

MyFirst_Slider Type A_2018-11-03_1138.proj (12.7 KB)

Thanks.

1 Like