Skip to content

Commit

Permalink
Rename activeStyle/activeTheme to currentStyle/currentTheme (avoid am…
Browse files Browse the repository at this point in the history
…biguity with active style state)
  • Loading branch information
fjvallarino committed Jul 26, 2021
1 parent 1a05151 commit 918ffc2
Show file tree
Hide file tree
Showing 35 changed files with 157 additions and 156 deletions.
2 changes: 1 addition & 1 deletion examples/generative/Widgets/BoxesPalette.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ makeBoxesPalette cfg state = widget where
colors <- makePalette (cfg ^. paletteType) (cfg ^. paletteSize)
mapM_ (drawRectangle renderer state colors vp cols rows) [0..cols * rows - 1]
where
style = activeStyle wenv node
style = currentStyle wenv node
vp = getContentArea node style
iw = cfg ^. itemWidth
fw = 0.5 + 5 * (state ^. mouseX - vp ^. L.x) / vp ^. L.w
Expand Down
2 changes: 1 addition & 1 deletion examples/generative/Widgets/CirclesGrid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ makeCirclesGrid cfg state = widget where

mapM_ (drawCircle renderer state vp iw cols) [0..cols * rows - 1]
where
style = activeStyle wenv node
style = currentStyle wenv node
vp = getContentArea node style
iw = cfg ^. itemWidth
cols = round (vp ^. L.w / iw)
Expand Down
2 changes: 1 addition & 1 deletion src/Monomer/Core/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ isResetOverlay _ = False

{-|
Sets the current active cursor icon. This acts as a stack, so removing means
going back a step.
going back a step to the cursor set by a parent widget.
-}
isSetCursorIcon :: WidgetRequest s e -> Bool
isSetCursorIcon SetCursorIcon{} = True
Expand Down
4 changes: 2 additions & 2 deletions src/Monomer/Widgets/Composite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ compositeGetSizeReq
-> (SizeReq, SizeReq)
compositeGetSizeReq comp state wenv widgetComp = (newReqW, newReqH) where
CompositeState{..} = state
style = activeStyle wenv widgetComp
style = currentStyle wenv widgetComp
widget = _cpsRoot ^. L.widget
currReqW = _cpsRoot ^. L.info . L.sizeReqW
currReqH = _cpsRoot ^. L.info . L.sizeReqH
Expand Down Expand Up @@ -654,7 +654,7 @@ compositeResize
-> WidgetResult sp ep
compositeResize comp state wenv widgetComp viewport = resizedRes where
CompositeState{..} = state
style = activeStyle wenv widgetComp
style = currentStyle wenv widgetComp
contentArea = fromMaybe def (removeOuterBounds style viewport)
widget = _cpsRoot ^. L.widget
model = getModel comp wenv
Expand Down
22 changes: 11 additions & 11 deletions src/Monomer/Widgets/Container.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Monomer.Widgets.Container (
module Monomer.Widgets.Util,

ContainerGetBaseStyle,
ContainerGetActiveStyle,
ContainerGetCurrentStyle,
ContainerUpdateCWenvHandler,
ContainerInitHandler,
ContainerInitPostHandler,
Expand Down Expand Up @@ -89,7 +89,7 @@ the full content rect.
An example can be found in "Monomer.Widgets.Containers.Tooltip".
-}
type ContainerGetActiveStyle s e
type ContainerGetCurrentStyle s e
= WidgetEnv s e -- ^ The widget environment.
-> WidgetNode s e -- ^ The widget node.
-> StyleState -- ^ The active style for the node.
Expand Down Expand Up @@ -347,8 +347,8 @@ data Container s e a = Container {
containerUseScissor :: Bool,
-- | Returns the base style for this type of widget.
containerGetBaseStyle :: ContainerGetBaseStyle s e,
-- | Returns the active style, depending on the status of the widget.
containerGetActiveStyle :: ContainerGetActiveStyle s e,
-- | Returns the current style, depending on the status of the widget.
containerGetCurrentStyle :: ContainerGetCurrentStyle s e,
-- | Updates the widget environment before passing it down to children.
containerUpdateCWenv :: ContainerUpdateCWenvHandler s e,
-- | Initializes the given node.
Expand Down Expand Up @@ -396,7 +396,7 @@ instance Default (Container s e a) where
containerUseChildrenSizes = False,
containerUseScissor = False,
containerGetBaseStyle = defaultGetBaseStyle,
containerGetActiveStyle = defaultGetActiveStyle,
containerGetCurrentStyle = defaultGetCurrentStyle,
containerUpdateCWenv = defaultUpdateCWenv,
containerInit = defaultInit,
containerInitPost = defaultInitPost,
Expand Down Expand Up @@ -452,8 +452,8 @@ createContainer state container = Widget {
defaultGetBaseStyle :: ContainerGetBaseStyle s e
defaultGetBaseStyle wenv node = Nothing

defaultGetActiveStyle :: ContainerGetActiveStyle s e
defaultGetActiveStyle wenv node = activeStyle wenv node
defaultGetCurrentStyle :: ContainerGetCurrentStyle s e
defaultGetCurrentStyle wenv node = currentStyle wenv node

defaultUpdateCWenv :: ContainerUpdateCWenvHandler s e
defaultUpdateCWenv wenv node cnode cidx = wenv
Expand Down Expand Up @@ -865,7 +865,7 @@ handleEventWrapper container wenv node baseTarget baseEvt
-- For example, Composite has its own tree of child widgets with (possibly)
-- different types for Model and Events, and is candidate for the next step
offset = fromMaybe def (containerChildrenOffset container)
style = containerGetActiveStyle container wenv node
style = containerGetCurrentStyle container wenv node
doCursor = not (containerUseCustomCursor container)
updateCWenv = getUpdateCWenv container
filterHandler = containerFilterEvent container
Expand Down Expand Up @@ -979,7 +979,7 @@ getSizeReqWrapper
getSizeReqWrapper container wenv node = (newReqW, newReqH) where
addStyleReq = containerAddStyleReq container
handler = containerGetSizeReq container
style = containerGetActiveStyle container wenv node
style = containerGetCurrentStyle container wenv node

children = node ^. L.children
reqs = handler wenv node children
Expand Down Expand Up @@ -1021,7 +1021,7 @@ handleSizeReqChange container wenv node evt mResult = result where
-- | Resize
defaultResize :: ContainerResizeHandler s e
defaultResize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
contentArea = fromMaybe def (removeOuterBounds style viewport)
childrenSizes = Seq.replicate (Seq.length children) contentArea
resized = (resultNode node, childrenSizes)
Expand Down Expand Up @@ -1098,7 +1098,7 @@ renderWrapper container wenv node renderer =
-- Outside children scissor
renderAfter wenv node renderer
where
style = containerGetActiveStyle container wenv node
style = containerGetCurrentStyle container wenv node
updateCWenv = getUpdateCWenv container
useScissor = containerUseScissor container
childrenScissor = containerChildrenScissor container
Expand Down
8 changes: 4 additions & 4 deletions src/Monomer/Widgets/Containers/Box.hs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ makeBox
makeBox config state = widget where
widget = createContainer state def {
containerIgnoreEmptyArea = ignoreEmptyArea && emptyHandlersCount == 0,
containerGetActiveStyle = getActiveStyle,
containerGetCurrentStyle = getCurrentStyle,
containerInit = init,
containerMergeChildrenReq = mergeRequired,
containerMerge = merge,
Expand Down Expand Up @@ -317,8 +317,8 @@ makeBox config state = widget where
newNode = node
& L.widget .~ makeBox config newState

getActiveStyle = activeStyle_ activeStyleConfig where
activeStyleConfig = def
getCurrentStyle = currentStyle_ currentStyleConfig where
currentStyleConfig = def
& L.isActive .~ isNodeTreeActive

handleEvent wenv node target evt = case evt of
Expand Down Expand Up @@ -381,7 +381,7 @@ makeBox config state = widget where
newSizeReq = updateSizeReq (newReqW, newReqH)

resize wenv node viewport children = resized where
style = getActiveStyle wenv node
style = getCurrentStyle wenv node
child = Seq.index children 0
contentArea = fromMaybe def (removeOuterBounds style viewport)
Rect cx cy cw ch = contentArea
Expand Down
2 changes: 1 addition & 1 deletion src/Monomer/Widgets/Containers/Draggable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ makeDraggable msg config = widget where

resize :: ContainerResizeHandler s e
resize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
contentArea = fromMaybe def (removeOuterBounds style viewport)
resized = (resultNode node, Seq.singleton contentArea)

Expand Down
6 changes: 3 additions & 3 deletions src/Monomer/Widgets/Containers/DropTarget.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ makeDropTarget
:: (DragMsg a, WidgetEvent e) => (a -> e) -> DropTargetCfg -> Widget s e
makeDropTarget dropEvt config = widget where
widget = createContainer () def {
containerGetActiveStyle = getActiveStyle,
containerGetCurrentStyle = getCurrentStyle,
containerHandleEvent = handleEvent
}

getActiveStyle wenv node
getCurrentStyle wenv node
| isDropTarget wenv node && isHovered && isJust style = fromJust style
| otherwise = activeStyle wenv node
| otherwise = currentStyle wenv node
where
mousePos = wenv ^. L.inputStatus . L.mousePos
isHovered = isPointInNodeVp node mousePos
Expand Down
8 changes: 4 additions & 4 deletions src/Monomer/Widgets/Containers/Dropdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ makeDropdown widgetData items makeMain makeRow config state = widget where
| not isOpen -> Just $ resultReqs node [IgnoreChildrenEvents]
| otherwise -> Nothing
where
style = activeStyle wenv node
style = currentStyle wenv node
widgetId = node ^. L.info . L.widgetId
path = node ^. L.info . L.path
focusedPath = wenv ^. L.focusedPath
Expand Down Expand Up @@ -439,7 +439,7 @@ makeDropdown widgetData items makeMain makeRow config state = widget where

listHeight wenv node = maxHeight where
Size _ winH = _weWindowSize wenv
theme = activeTheme wenv node
theme = currentTheme wenv node
maxHeightTheme = theme ^. L.dropdownMaxHeight
cfgMaxHeight = _ddcMaxHeight config
-- Avoid having an invisible list if style/theme is not set
Expand All @@ -460,7 +460,7 @@ makeDropdown widgetData items makeMain makeRow config state = widget where
| otherwise = 0

resize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
Rect rx ry rw rh = viewport
!mainArea = viewport
!listArea = viewport {
Expand All @@ -481,7 +481,7 @@ makeDropdown widgetData items makeMain makeRow config state = widget where
drawInTranslation renderer totalOffset $ do
renderOverlay renderer cwenv listOverlay
where
style = activeStyle wenv node
style = currentStyle wenv node
viewport = node ^. L.info . L.viewport
mainNode = Seq.index (node ^. L.children) mainIdx
-- List view is rendered with an offset to accommodate for window height
Expand Down
2 changes: 1 addition & 1 deletion src/Monomer/Widgets/Containers/Grid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ makeFixedGrid isHorizontal config = widget where
maxSize = foldl1 sizeReqMergeMax vreqs

resize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
contentArea = fromMaybe def (removeOuterBounds style viewport)
Rect l t w h = contentArea
vchildren = Seq.filter (_wniVisible . _wnInfo) children
Expand Down
26 changes: 13 additions & 13 deletions src/Monomer/Widgets/Containers/Scroll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ makeScroll config state = widget where
containerChildrenScissor = Just (_sstScissor state),
containerLayoutDirection = layoutDirection,
containerGetBaseStyle = getBaseStyle,
containerGetActiveStyle = scrollActiveStyle,
containerGetCurrentStyle = scrollCurrentStyle,
containerInit = init,
containerMerge = merge,
containerFindByPoint = findByPoint,
Expand Down Expand Up @@ -490,8 +490,8 @@ makeScroll config state = widget where

_ -> Nothing
where
theme = activeTheme wenv node
style = scrollActiveStyle wenv node
theme = currentTheme wenv node
style = scrollCurrentStyle wenv node
contentArea = getContentArea node style
mousePos = wenv ^. L.inputStatus . L.mousePos

Expand All @@ -516,7 +516,7 @@ makeScroll config state = widget where
result = cast message >>= handleScrollMessage

scrollTo wenv node targetRect = result where
style = scrollActiveStyle wenv node
style = scrollCurrentStyle wenv node
contentArea = getContentArea node style

rect = moveRect offset targetRect
Expand Down Expand Up @@ -582,7 +582,7 @@ makeScroll config state = widget where

getSizeReq :: ContainerGetSizeReqHandler s e
getSizeReq wenv node children = sizeReq where
style = scrollActiveStyle wenv node
style = scrollCurrentStyle wenv node
child = Seq.index children 0

tw = sizeReqMaxBounded $ child ^. L.info . L.sizeReqW
Expand All @@ -594,8 +594,8 @@ makeScroll config state = widget where
sizeReq = (expandSize w factor, expandSize h factor)

resize wenv node viewport children = result where
theme = activeTheme wenv node
style = scrollActiveStyle wenv node
theme = currentTheme wenv node
style = scrollCurrentStyle wenv node

Rect cl ct cw ch = fromMaybe def (removeOuterBounds style viewport)
dx = _sstDeltaX state
Expand Down Expand Up @@ -663,7 +663,7 @@ makeScroll config state = widget where
draggingV = _sstDragging state == Just VBar

theme = wenv ^. L.theme
athm = activeTheme wenv node
athm = currentTheme wenv node
tmpRad = fromMaybe (athm ^. L.scrollThumbRadius) (_scThumbRadius config)
thumbRadius
| tmpRad > 0 = Just (radius tmpRad)
Expand Down Expand Up @@ -693,10 +693,10 @@ makeScroll config state = widget where
| vMouseInThumb || draggingV = thumbHCol
| otherwise = thumbBCol

scrollActiveStyle :: WidgetEnv s e -> WidgetNode s e -> StyleState
scrollActiveStyle wenv node
scrollCurrentStyle :: WidgetEnv s e -> WidgetNode s e -> StyleState
scrollCurrentStyle wenv node
| isNodeFocused wenv child = focusedStyle wenv node
| otherwise = activeStyle wenv node
| otherwise = currentStyle wenv node
where
child = node ^. L.children ^?! ix 0

Expand All @@ -711,8 +711,8 @@ scrollStatus config wenv node scrollState mousePos = ScrollContext{..} where
ScrollState _ dx dy _ _ _ = scrollState
Size childWidth childHeight = _sstChildSize scrollState
Size vpWidth vpHeight = _sstVpSize scrollState
theme = activeTheme wenv node
style = scrollActiveStyle wenv node
theme = currentTheme wenv node
style = scrollCurrentStyle wenv node
contentArea = getContentArea node style

barW = fromMaybe (theme ^. L.scrollBarWidth) (_scBarWidth config)
Expand Down
2 changes: 1 addition & 1 deletion src/Monomer/Widgets/Containers/Split.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ makeSplit isHorizontal config state = widget where
| otherwise = foldl1 sizeReqMergeSum [reqWS, reqH1, reqH2]

resize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
contentArea = fromMaybe def (removeOuterBounds style viewport)
Rect rx ry rw rh = contentArea
(areas, newSize) = assignStackAreas isHorizontal contentArea children
Expand Down
2 changes: 1 addition & 1 deletion src/Monomer/Widgets/Containers/Stack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ makeStack isHorizontal config = widget where
vreqs = accesor <$> vchildren

resize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
contentArea = fromMaybe def (removeOuterBounds style viewport)
(newVps, newDim) = assignStackAreas isHorizontal contentArea children
newCa
Expand Down
4 changes: 2 additions & 2 deletions src/Monomer/Widgets/Containers/ThemeSwitch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ makeThemeSwitch :: Theme -> ThemeSwitchCfg -> ThemeSwitchState -> Widget s e
makeThemeSwitch theme config state = widget where
widget = createContainer state def {
containerUpdateCWenv = updateCWenv,
containerGetActiveStyle = getActiveStyle,
containerGetCurrentStyle = getCurrentStyle,
containerInit = init,
containerMerge = merge
}
Expand All @@ -105,7 +105,7 @@ makeThemeSwitch theme config state = widget where
& L.theme .~ theme
& L.themeChanged .~ (themeChanged || parentChanged)

getActiveStyle wenv node = style where
getCurrentStyle wenv node = style where
clearBg = _tmcClearBg config == Just True
clearColor = theme ^. L.clearColor
style
Expand Down
2 changes: 1 addition & 1 deletion src/Monomer/Widgets/Containers/Tooltip.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ makeTooltip caption config state = widget where
forM_ textLines (drawTextLine renderer style)
where
fontMgr = wenv ^. L.fontManager
style = activeStyle wenv node
style = currentStyle wenv node
children = node ^. L.children
mousePos = wenv ^. L.inputStatus . L.mousePos

Expand Down
4 changes: 2 additions & 2 deletions src/Monomer/Widgets/Containers/ZStack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ makeZStack config state = widget where
vreqs = accesor <$> vchildren

resize wenv node viewport children = resized where
style = activeStyle wenv node
style = currentStyle wenv node
vpChild = fromMaybe def (removeOuterBounds style viewport)
assignedAreas = fmap (const vpChild) children
resized = (resultNode node, assignedAreas)
Expand All @@ -191,7 +191,7 @@ makeZStack config state = widget where
drawStyledAction renderer viewport style $ \_ ->
void $ Seq.traverseWithIndex renderChild children
where
style = activeStyle wenv node
style = currentStyle wenv node
children = Seq.reverse $ node ^. L.children
viewport = node ^. L.info . L.viewport
isVisible c = c ^. L.info . L.visible
Expand Down
Loading

0 comments on commit 918ffc2

Please sign in to comment.