-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use nested sum type to simplify panel enumeration #876
Conversation
8b4b7b7
to
8973fe7
Compare
8973fe7
to
b98cec6
Compare
mouseCoordsM <- Brick.zoom gameState (mouseLocToWorldCoords mouseLoc) | ||
uiState . uiWorldCursor .= mouseCoordsM | ||
REPLInput -> do | ||
setFocus REPLPanel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moved to here.
InventoryList -> Just RobotPanel | ||
InventoryListItem _ -> Just RobotPanel | ||
InfoViewport -> Just InfoPanel | ||
REPLInput -> Just REPLPanel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I assume the purpose is that now we can add new focusable panels without having to touch quite as many places in the code, since e.g. in some places you can just say listEnum
and it will pick up all the focusable panels?
Yes, exactly. I add a new panel in #873. |
b98cec6
to
0677da9
Compare
0677da9
to
15ffaa0
Compare
Just (FocusablePanel x) -> ($ ev) $ case x of | ||
REPLPanel -> handleREPLEvent | ||
WorldPanel -> handleWorldEvent | ||
RobotPanel -> handleRobotPanelEvent | ||
InfoPanel -> handleInfoPanelEvent infoScroll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's one more benefit of a dedicated sum type for Panel
s: we utilize exhuastiveness checking from the compiler here. The catch-all _
case no longer allows us to forget about a Panel
; it instead handles all the non-panel Name
s.
Code simplification, improved type safety (see [this comment](#876 (comment))). This technique may also simplify the implementation of `CReverse` (see #950) if we choose to do so.
This trick facilitates use of
listEnums
and more concise pattern matching.Towards #873.