module DynRadioGroupF where
import Fudgets

dynRadioGroupF :: [(b, lbl)] -> b -> F ([(b, lbl)], b) ([(b, lbl)], b)
dynRadioGroupF [(b, lbl)]
alts b
startalt = (RadioGroupF -> RadioGroupF)
-> [(b, lbl)] -> b -> F ([(b, lbl)], b) ([(b, lbl)], b)
forall lbl b.
(Graphic lbl, Eq b) =>
(RadioGroupF -> RadioGroupF)
-> [(b, lbl)] -> b -> F ([(b, lbl)], b) ([(b, lbl)], b)
dynRadioGroupF' RadioGroupF -> RadioGroupF
forall a. Customiser a
standard [(b, lbl)]
alts b
startalt

dynRadioGroupF' :: (RadioGroupF -> RadioGroupF)
-> [(b, lbl)] -> b -> F ([(b, lbl)], b) ([(b, lbl)], b)
dynRadioGroupF' RadioGroupF -> RadioGroupF
pm [(b, lbl)]
alts b
startalt =
    F (Either b ([(b, lbl)], b))
  (Either (Either (F b b) b) ([(b, lbl)], b))
-> F (Either (F b b) b) b -> F ([(b, lbl)], b) ([(b, lbl)], b)
forall a b c d. F (Either a b) (Either c d) -> F c a -> F b d
loopThroughRightF ((([(b, lbl)], b)
 -> Either b ([(b, lbl)], b)
 -> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)]))
-> ([(b, lbl)], b)
-> F (Either b ([(b, lbl)], b))
     (Either (Either (F b b) b) ([(b, lbl)], b))
forall t a b. (t -> a -> (t, [b])) -> t -> F a b
mapstateF ([(b, lbl)], b)
-> Either b ([(b, lbl)], b)
-> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)])
forall b.
([(b, lbl)], b)
-> Either b ([(b, lbl)], b)
-> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)])
ctrl ([(b, lbl)]
alts,b
startalt))
                      (F b b -> F (Either (F b b) b) b
forall a b. F a b -> F (Either (F a b) a) b
dynF ([(b, lbl)] -> b -> F b b
rgF [(b, lbl)]
alts b
startalt))
  where
    rgF :: [(b, lbl)] -> b -> F b b
rgF = (RadioGroupF -> RadioGroupF) -> [(b, lbl)] -> b -> F b b
forall lbl alt.
(Graphic lbl, Eq alt) =>
(RadioGroupF -> RadioGroupF) -> [(alt, lbl)] -> alt -> F alt alt
radioGroupF' RadioGroupF -> RadioGroupF
pm

    ctrl :: ([(b, lbl)], b)
-> Either b ([(b, lbl)], b)
-> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)])
ctrl ([(b, lbl)]
alts,b
current) = (b
 -> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)]))
-> (([(b, lbl)], b)
    -> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)]))
-> Either b ([(b, lbl)], b)
-> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)])
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either b -> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)])
forall b a. b -> (([(b, lbl)], b), [Either a ([(b, lbl)], b)])
fromRadioGroupF ([(b, lbl)], b)
-> (([(b, lbl)], b), [Either (Either (F b b) b) ([(b, lbl)], b)])
forall b.
([(b, lbl)], b) -> (([(b, lbl)], b), [Either (Either (F b b) b) b])
fromOutside
      where
        fromRadioGroupF :: b -> (([(b, lbl)], b), [Either a ([(b, lbl)], b)])
fromRadioGroupF b
choice = (([(b, lbl)]
alts,b
choice),[([(b, lbl)], b) -> Either a ([(b, lbl)], b)
forall a b. b -> Either a b
Right ([(b, lbl)]
alts,b
choice)])
	fromOutside :: ([(b, lbl)], b) -> (([(b, lbl)], b), [Either (Either (F b b) b) b])
fromOutside ([(b, lbl)]
alts',b
current') =
	  (([(b, lbl)]
alts',b
current'),
	   if ((b, lbl) -> b) -> [(b, lbl)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (b, lbl) -> b
forall a b. (a, b) -> a
fst [(b, lbl)]
alts' [b] -> [b] -> Bool
forall a. Eq a => a -> a -> Bool
== ((b, lbl) -> b) -> [(b, lbl)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (b, lbl) -> b
forall a b. (a, b) -> a
fst [(b, lbl)]
alts
	   then [Either (F b b) b -> Either (Either (F b b) b) b
forall a b. a -> Either a b
Left (b -> Either (F b b) b
forall a b. b -> Either a b
Right b
current')]
	   else [Either (F b b) b -> Either (Either (F b b) b) b
forall a b. a -> Either a b
Left (F b b -> Either (F b b) b
forall a b. a -> Either a b
Left ([(b, lbl)] -> b -> F b b
rgF [(b, lbl)]
alts' b
current'))])