UI project

This is my first project in codea and the ipad and i think the controls i made turned out neat and ust felt like sharing

--main

supportedOrientations(PORTRAIT)


function grossWeightChanged()
    grossWeight.value=math.floor(grossWeight.value/100)*100
    grossWeightLabel.txt="GW: "..tostring(grossWeight.value)
end

function pressureAltitudeChanged()
    pressureAltitude.value=math.floor(pressureAltitude.value/100)*100
    pressureAltitudeLabel.txt="PA: "..tostring(pressureAltitude.value)
end

function tempChanged()
    temperature.value=math.floor(temperature.value)
    temperatureLabel.txt="Temp: "..tostring(temperature.value)
end

function calc()
    sound(DATA, "ZgBAOzllf2h4f39AAAAAAAAAAADf/Qo+AABzf3JiYkB/f0AA")
    pa=pressureAltitude.value
    temp=temperature.value
    tempF=temp*1.8+32
    gw=grossWeight.value
    isa=pa/500+temp-15
    da=math.ceil((pa+120*isa)/500)*500--need to get more accurate formula
    
    isaLabel.txt="ISA: "..isa
    densityAltitudeLabel.txt="DA: "..da
end

function setup()
    displayMode(FULLSCREEN)
    grossWeight=Slider(497,980,260,38000,53000,44000,grossWeightChanged)
    grossWeightLabel=LabelC(445,980,"GW: ",color(0, 0, 0, 255))
    
    pressureAltitude=Slider(497,940,260,0,9000,4300,pressureAltitudeChanged)
    pressureAltitudeLabel=LabelC(445,940,"PA: ",color(0, 0, 0, 255))

    temperature=Slider(497,900,260,0,50,20,tempChanged)
    temperatureLabel=LabelC(445,900,"Temp: ",color(0, 0, 0, 255))
    
    isaLabel=LabelC(55,980,"ISA: ",color(0,60,0,255))
    densityAltitudeLabel=LabelC(55,940,"DA: ",color(0,60,0,255))
    
    calc=Button(334,835,90,40,"Calculate",calc)
end

function draw()
    background(194, 197, 207, 255)
    drawControls()
end

function touched(touch)
    touchControls(touch)
end
--controls

Button = class()
LabelC = class()
Slider = class()

controls=0
controlArray={}

function addControl(control)
    controls = controls + 1
    controlArray[controls]=control
end

function drawControls()
    for i = 1,controls do
        controlArray[i]:draw()
    end
end

function touchControls(touch)
    for i = 1,controls do
        controlArray[i]:touched(touch)
    end
end

function Slider:init(x,y,w,min,max,val,changed)
    self.x=x
    self.y=y
    self.w=w
    self.min=min
    self.max=max
    self.value=val
    self.changed=changed
    self.touchid=0
    self.tooltip=LabelC(0,0,"0",color(0,0,0,255))
    self.tooltip.hidden=1
    addControl(self)
end

function Slider:draw()
    pushStyle()
    stroke(101, 117, 133, 255)
    fill(202, 195, 191, 255)
    strokeWidth(3)
    line(self.x,self.y,self.x+self.w,self.y)
    if self.touchid>0 then
        self.tooltip.txt=self.value
        fill(91, 51, 51, 255)
    end
    stroke(35, 35, 35, 255)
    strokeWidth(2)
    x=((self.value - self.min)/(self.max - self.min)*self.w)
    ellipse(self.x+x,self.y,20,20)
    popStyle()
end

function Slider:touched(touch)
    x=((self.value - self.min)/(self.max - self.min)*self.w)+self.x
    y=self.y
    dist=math.abs(math.sqrt((touch.x-x)^2+(touch.y-y)^2))
    if dist<25 and touch.state==BEGAN then
        self.touchid=touch.id
        self.tooltip.hidden=false
    end  
    
    if touch.id==self.touchid then
        self.tooltip.x=touch.x+50
        self.tooltip.y=touch.y+50
        if touch.x<self.x then
            self.value=self.min 
        elseif touch.x>self.x+self.w then 
            self.value=self.max 
        else
            self.value=((touch.x-self.x)/self.w)*(self.max-self.min)+self.min
        end
        self.changed()
        if touch.state==ENDED then 
            self.touchid=0 
            self.tooltip.hidden=true
        end  
    end      
end

function LabelC:init(x,y,txt,color)
    self.x=x
    self.y=y
    self.txt=txt
    self.color=color
    self.hidden=false
    addControl(self)
end

function LabelC:touched(touch)
end

function LabelC:draw()
    if self.hidden then return end
    pushStyle()
    fill(self.color)
    text(self.txt,self.x,self.y)
    popStyle()
end


function Button:init(x,y,w,h,txt,clicked)
    -- you can accept and set parameters here
    self.x = x
    self.y = y
    self.w=w
    self.h=h
    self.txt=txt
    self.state=0
    self.touchid=0
    self.clicked=clicked
    addControl(self)
end

function Button:draw()
    pushStyle()
    stroke(83, 89, 68, 255)   
    fill(184, 179, 170, 255)
    strokeWidth(2)
    if self.state==1 then strokeWidth(3) end
    if self.state>1 then 
        strokeWidth(self.state) 
        self.state = self.state - 1
        fontSize(16)
        if self.state==2 then 
            self.state=0 
            fill(55, 89, 64, 255)
        end
    end
    rect(self.x,self.y,self.w,self.h)
    fill(0, 0, 0, 255)
    text(self.txt,(self.x*2+self.w)/2,(self.y*2+self.h)/2)
    popStyle()
end

function Button:touched(touch)
    if touch.x>=self.x and touch.x<=self.x+self.w and 
        touch.y>=self.y and touch.y <=self.y+self.h then
        if touch.state==BEGAN then
            self.touchid=touch.id
            self.state=1
        end
        if touch.state==ENDED and self.touchid==touch.id then
            self.state=5
            self.clicked()
        end
    else
        if touch.state==ENDED and self.touchid==touch.id then
            self.state=0
        end
    end

end

While changing values on sliders the value follows the touch.y and by blocking that the bug is fixed
function Slider:touched(touch)

    -- self.tooltip.y=touch.y+50

Hello Dteel;

I will test your code because i want to develop a UI, i will send you my comments.

Greetings