Commit ef19043b authored by Bas Lijnse's avatar Bas Lijnse

Refactored removeSubUIs layout rule to a combination of layoutSubUIs and hideUI

parent 555690ee
......@@ -82,16 +82,15 @@ wrapUI :: UIType -> LayoutRule
unwrapUI :: LayoutRule
/*
* Insert a (static) element into a UI
* Hide a (piece of a) UI
*/
insertChildUI :: Int UI -> LayoutRule
hideUI :: LayoutRule
removeSubUIs selection :== layoutSubUIs selection hideUI
/**
* Remove all elements that match the predicate, but keep the removed elements in the state.
* Further changes to these elements are processed in the background. When the predicate no longer holds, the elements are inserted back into the UI.
* When new elements are added dynamically they are also tested against the predicate
/*
* Insert a (static) element into a UI
*/
removeSubUIs :: UISelection -> LayoutRule
insertChildUI :: Int UI -> LayoutRule
/**
* Move all elements that match the predicate to a particular location in the tree.
......@@ -102,6 +101,8 @@ moveSubUIs :: UISelection UIPath Int -> LayoutRule
/**
* Applying a rule locally to matching parts of a UI
* When the predicate no longer holds, the elements are inserted back into the UI.
* When new elements are added dynamically they are also tested against the predicate.
*/
layoutSubUIs :: UISelection LayoutRule -> LayoutRule
......
......@@ -299,6 +299,18 @@ where
= updateSubNode_ ruleNo [0] (rule ruleNo) (lui,moves)
rule ruleNo (lui,moves) = (lui,moves)
hideUI :: LayoutRule
hideUI = rule
where
rule ruleNo (lui,moves) = updateNode_ ruleNo (apply ruleNo) (lui,moves)
apply ruleNo (LUINode type attr items changes effects=:{hidden},moves)
# hidden = case hidden of
ESNotApplied = ESToBeApplied ruleNo
ESToBeApplied _ = ESToBeApplied ruleNo
ESApplied _ = ESApplied ruleNo
ESToBeRemoved _ = ESApplied ruleNo
= (LUINode type attr items changes {effects & hidden=hidden},moves)
insertChildUI :: Int UI -> LayoutRule
insertChildUI position insertion = rule
where
......@@ -335,37 +347,6 @@ where
= lui
undo lui = lui
removeSubUIs :: UISelection -> LayoutRule
removeSubUIs selection = rule
where
rule ruleId (lui=:(LUINode type attr items changes=:{toBeReplaced=Just replacement} effects), moves)
# (replacement,moves) = rule ruleId (replacement, moves)
= (LUINode type attr items {changes & toBeReplaced=Just replacement} effects, moves)
rule ruleNo (lui,moves) = remove [] (lui,moves)
where
remove path (lui=:(LUINode type attr items changes effects),moves)
//Check if this matches the selection
| nodeSelected_ ruleNo selection path lui moves
= (LUINode type attr (map clear items) changes (hide ruleNo effects),moves)
| otherwise
# (items,moves) = updateChildNodes_ ruleNo (\i (item,moves) -> remove (path ++ [i]) (item,moves)) (items,moves)
= (LUINode type attr items changes (unhide ruleNo effects),moves)
remove path (lui,moves) = (lui,moves)
clear (LUINode type attr items changes effects) = LUINode type attr (map clear items) changes (unhide ruleNo effects)
clear lui = lui
hide ruleId effects=:{hidden=ESNotApplied} = {effects & hidden = ESToBeApplied ruleId}
hide ruleId effects=:{hidden=ESToBeApplied _} = {effects & hidden = ESToBeApplied ruleId}
hide ruleId effects=:{hidden=ESApplied _} = {effects & hidden = ESApplied ruleId}
hide ruleId effects=:{hidden=ESToBeRemoved _} = {effects & hidden = ESApplied ruleId}
unhide ruleId effects=:{hidden=ESNotApplied} = {effects & hidden = ESNotApplied}
unhide ruleId effects=:{hidden=ESToBeApplied _} = {effects & hidden = ESNotApplied}
unhide ruleId effects=:{hidden=ESApplied _} = {effects & hidden = ESToBeRemoved ruleId}
unhide ruleId effects=:{hidden=ESToBeRemoved _} = {effects & hidden = ESToBeRemoved ruleId}
moveSubUIs :: UISelection UIPath Int -> LayoutRule
moveSubUIs selection path pos = rule
where
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment