At some point, I have this function which updates a color picker according the the mouse position, according to whether the user clicked a mouse button and according to its previous state:
updateColorPickerState :: ColorPicker -> (GLfloat, GLfloat) -> Bool -> ColorPicker
updateColorPickerState c (x,y) mouseClicked = if isPointWithinColorPicker c (x, y)
then if mouseClicked
then if state c == Opened
then c {state = Idle, selectedColor = getColorAt (x',y')}
else c {state = Opened}
else if state c == Opened
then c
else c {state = Hovered}
else if state c == Opened
then if mouseClicked
then c {state = Idle}
else c
else c {state = Idle}
where (posX, posY) = pos c
(sizeX, sizeY) = openedSize c
x' = truncate ((x - posX) * 25 / sizeX)
y' = truncate (((-y) - posY) * 11 / sizeY)
How can I change the if-then-else tree to something more readable?