Question about styling with multiple concurrent states #475
Replies: 1 comment 4 replies
-
If it were me, I would probably use attributes to indicate some of those states and textual decorations to indicate others. Since that is a lot of potential simultaneous states to be in, I'd be concerned that trying to use attributes to indicate them all would be hard to get right and also hard to be visibly usable. (E.g. I might put But, with that said, assuming an approach based solely on attributes, if you want to have later rules take priority, then I think that's a job for attribute name hierarchy, e.g., cellBaseAttr, matchAttr, selectedAttr, focusAttr, givenAttr, blankOrInputAttr :: AttrName
cellBaseAttr = attrName "cell"
matchAttr = cellBaseAttr <> attrName "match"
selectedAttr = matchAttr <> attrName "selected"
focusAttr = selectedAttr <> attrName "focus"
givenAttr = focusAttr <> attrName "given"
blankOrInputAttr = givenAttr <> attrName "blankOrInput" Then, in the drawing code itself, for each cell, use |
Beta Was this translation helpful? Give feedback.
-
Off the back of this tweet, I'm wondering how you would go about implementing this.
I have a sudoku game.
Each cell has multiple concurrent states which can affect how the cells should look:
For example, a cell could be all of: input, matched, selected, and focussed at the same time.
I wanted to style with the following pseudocode rules (later rules have greater priority):
I do have something which "works" and is somewhat pleasing to use, but I would like to understand how someone more in the know would tackle this scenario.
Edit
Here's roughly what I'm currently using:
I'm generating attribute map entries for each possible combination of states.
In which the
with*
functions define a "pattern", by specifying which refinement of states the rule applies to.So
withMatched [True]
means{ matched is True, selected is *, focussed is *, content is * }
, i.e 12 different attribute names.The rules apply in order; and the rule "body" defines a transformation to apply – letting me specify, for example, that the background colour should become bright in the focussed case.
For any two identical rule patterns, the transformations are composed – such that later modifications take priority.
To see the full code look at lines 229-411 of this file.
Edit 2
I've simplified this a lot.
Beta Was this translation helpful? Give feedback.
All reactions