Go back to old widgetUpdateSizeReq signature

This commit is contained in:
Francisco Vallarino 2020-12-13 21:13:59 -03:00
parent a9e1bb829a
commit e9da76f812
11 changed files with 62 additions and 67 deletions

View File

@ -32,7 +32,6 @@ makeLensesWith abbreviatedFields ''Theme
makeLensesWith abbreviatedFields ''WidgetEnv
makeLensesWith abbreviatedFields ''WidgetRequest
makeLensesWith abbreviatedFields ''WidgetResult
makeLensesWith abbreviatedFields ''WidgetSizeReq
makeLensesWith abbreviatedFields ''WidgetData
makeLensesWith abbreviatedFields ''WidgetNode
makeLensesWith abbreviatedFields ''WidgetNodeInfo

View File

@ -96,12 +96,6 @@ instance Semigroup (WidgetResult s e) where
_wrEvents = _wrEvents er1 <> _wrEvents er2
}
data WidgetSizeReq s e = WidgetSizeReq {
_wsrWidget :: WidgetNode s e,
_wsrSizeReqW :: SizeReq,
_wsrSizeReqH :: SizeReq
} deriving (Show)
data WidgetEnv s e = WidgetEnv {
_weOS :: Text,
_weRenderer :: Renderer,
@ -211,10 +205,10 @@ data Widget s e =
-> WidgetNode s e
-> Maybe (WidgetResult s e),
-- | Updates the sizeReq field for the widget
widgetGetSizeReq
widgetUpdateSizeReq
:: WidgetEnv s e
-> WidgetNode s e
-> WidgetSizeReq s e,
-> WidgetNode s e,
-- | Resizes the children of this widget
--
-- Vieport assigned to the widget

View File

@ -217,7 +217,7 @@ createComposite comp state = widget where
widgetFindByPoint = compositeFindByPoint comp state,
widgetHandleEvent = compositeHandleEvent comp state,
widgetHandleMessage = compositeHandleMessage comp state,
widgetGetSizeReq = compositeGetSizeReq comp state,
widgetUpdateSizeReq = compositeUpdateSizeReq comp state,
widgetResize = compositeResize comp state,
widgetRender = compositeRender comp state
}
@ -395,33 +395,30 @@ compositeHandleMessage comp state@CompositeState{..} wenv target arg widgetComp
result = widgetHandleMessage cmpWidget cwenv target arg _cpsRoot
-- Preferred size
compositeGetSizeReq
compositeUpdateSizeReq
:: (CompositeModel s, CompositeEvent e, ParentModel sp)
=> Composite s e sp ep
-> CompositeState s e sp
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetSizeReq sp ep
compositeGetSizeReq comp state wenv widgetComp = newSizeReq where
-> WidgetNode sp ep
compositeUpdateSizeReq comp state wenv widgetComp = newComp where
CompositeState{..} = state
style = activeStyle wenv widgetComp
widget = _cpsRoot ^. L.widget
model = getModel comp wenv
cwenv = convertWidgetEnv wenv _cpsGlobalKeys model
tempChildReq = widgetGetSizeReq widget cwenv _cpsRoot
newChildReq = sizeReqAddStyle style tempChildReq
childRoot = newChildReq ^. L.widget
childReqW = newChildReq ^. L.sizeReqW
childReqH = newChildReq ^. L.sizeReqH
newRoot = childRoot
& L.info . L.sizeReqW .~ childReqW
& L.info . L.sizeReqH .~ childReqH
newRoot = widgetUpdateSizeReq widget cwenv _cpsRoot
currReqW = newRoot ^. L.info . L.sizeReqW
currReqH = newRoot ^. L.info . L.sizeReqH
(newReqW, newReqH) = sizeReqAddStyle style (currReqW, currReqH)
newState = state {
_cpsRoot = newRoot
}
newComp = widgetComp
& L.widget .~ createComposite comp newState
newSizeReq = WidgetSizeReq newComp childReqW childReqH
& L.info . L.sizeReqW .~ newReqW
& L.info . L.sizeReqH .~ newReqH
-- Resize
compositeResize

View File

@ -176,7 +176,7 @@ createContainer container = Widget {
widgetFindByPoint = findByPointWrapper container,
widgetHandleEvent = handleEventWrapper container,
widgetHandleMessage = handleMessageWrapper container,
widgetGetSizeReq = getSizeReqWrapper container,
widgetUpdateSizeReq = getSizeReqWrapper container,
widgetResize = resizeWrapper container,
widgetRender = renderWrapper container
}
@ -536,23 +536,21 @@ getSizeReqWrapper
:: Container s e
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetSizeReq s e
getSizeReqWrapper container wenv node = newSizeReq & L.widget .~ newNode where
-> WidgetNode s e
getSizeReqWrapper container wenv node = newNode where
resizeRequired = containerResizeRequired container
psHandler = containerGetSizeReq container
style = activeStyle wenv node
children = node ^. L.children
updateChild child = newChild where
childReq = widgetGetSizeReq (child ^. L.widget) wenv child
WidgetSizeReq cWidget cReqW cReqH = childReq
newChild = cWidget
& L.info . L.sizeReqW .~ cReqW
& L.info . L.sizeReqH .~ cReqH
updateChild child = widgetUpdateSizeReq (child ^. L.widget) wenv child
newChildren = fmap updateChild children
(sizeReqW, sizeReqH) = psHandler wenv node newChildren
newSizeReq = sizeReqAddStyle style (WidgetSizeReq node sizeReqW sizeReqH)
reqs = psHandler wenv node newChildren
(newReqW, newReqH) = sizeReqAddStyle style reqs
newNode
| resizeRequired = node & L.children .~ newChildren
| resizeRequired = node
& L.children .~ newChildren
& L.info . L.sizeReqW .~ newReqW
& L.info . L.sizeReqH .~ newReqH
| otherwise = node
-- | Resize

View File

@ -299,9 +299,9 @@ makeDropdown widgetData items makeMain makeRow config state = widget where
getSizeReq wenv node children = (newReqW, newReqH) where
child = Seq.index children 0
childReq = widgetGetSizeReq (child ^. L.widget) wenv child
newReqW = childReq ^. L.sizeReqW
newReqH = childReq ^. L.sizeReqH
childReq = widgetUpdateSizeReq (child ^. L.widget) wenv child
newReqW = childReq ^. L.info . L.sizeReqW
newReqH = childReq ^. L.info . L.sizeReqH
resize wenv viewport renderArea children node = resized where
Size winW winH = _weWindowSize wenv

View File

@ -137,7 +137,7 @@ createSingle single = Widget {
widgetFindByPoint = singleFindByPoint single,
widgetHandleEvent = handleEventWrapper single,
widgetHandleMessage = singleHandleMessage single,
widgetGetSizeReq = getSizeReqWrapper single,
widgetUpdateSizeReq = getSizeReqWrapper single,
widgetResize = resizeHandlerWrapper single,
widgetRender = renderWrapper single
}
@ -230,12 +230,15 @@ getSizeReqWrapper
:: Single s e
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetSizeReq s e
getSizeReqWrapper single wenv node = newSizeReq where
-> WidgetNode s e
getSizeReqWrapper single wenv node = newNode where
handler = singleGetSizeReq single
style = activeStyle wenv node
(sizeReqW, sizeReqH) = handler wenv node
newSizeReq = sizeReqAddStyle style (WidgetSizeReq node sizeReqW sizeReqH)
reqs = handler wenv node
(newReqW, newReqH) = sizeReqAddStyle style reqs
newNode = node
& L.info . L.sizeReqW .~ newReqW
& L.info . L.sizeReqH .~ newReqH
defaultResize :: SingleResizeHandler s e
defaultResize wenv viewport renderArea node = node

View File

@ -29,15 +29,13 @@ isSizeReqFlex :: SizeReq -> Bool
isSizeReqFlex FlexSize{} = True
isSizeReqFlex _ = False
sizeReqAddStyle :: StyleState -> WidgetSizeReq s e -> WidgetSizeReq s e
sizeReqAddStyle style sizeReq = newSizeReq where
WidgetSizeReq widget reqW reqH = sizeReq
sizeReqAddStyle :: StyleState -> (SizeReq, SizeReq) -> (SizeReq, SizeReq)
sizeReqAddStyle style (reqW, reqH) = (newReqW, newReqH) where
Size w h = fromMaybe def (addOuterSize style def)
realReqW = fromMaybe reqW (_sstSizeReqW style)
realReqH = fromMaybe reqH (_sstSizeReqH style)
newReqW = modifySizeReq realReqW (+w)
newReqH = modifySizeReq realReqH (+h)
newSizeReq = WidgetSizeReq widget newReqW newReqH
sizeReqMin :: SizeReq -> Double
sizeReqMin (FixedSize c) = c

View File

@ -151,11 +151,11 @@ handleSizeChange wenv target evt cfg node = reqs where
focusChanged = isOnFocus evt || isOnBlur evt
-- Size
checkSize = hoverChanged || focusChanged
nodeReqs = widgetGetSizeReq widget wenv node
newReqs = widgetUpdateSizeReq widget wenv node
oldSizeReqW = info ^. L.sizeReqW
oldSizeReqH = info ^. L.sizeReqH
newSizeReqW = nodeReqs ^. L.sizeReqW
newSizeReqH = nodeReqs ^. L.sizeReqH
newSizeReqW = newReqs ^. L.info . L.sizeReqW
newSizeReqH = newReqs ^. L.info . L.sizeReqH
sizeReqChanged = oldSizeReqW /= newSizeReqW || oldSizeReqH /= newSizeReqH
-- Result
resizeReq = [ ResizeWidgets | checkSize && sizeReqChanged ]

View File

@ -139,13 +139,8 @@ resizeWidget
-> WidgetNode s e
-> WidgetNode s e
resizeWidget wenv viewport renderArea widgetRoot = newRoot where
sizeReq = widgetGetSizeReq (_wnWidget widgetRoot) wenv widgetRoot
reqRoot = sizeReq ^. L.widget
& L.info . L.sizeReqW .~ sizeReq ^. L.sizeReqW
& L.info . L.sizeReqH .~ sizeReq ^. L.sizeReqH
reqRootWidget = sizeReq ^. L.widget . L.widget
newRoot = widgetResize reqRootWidget wenv viewport renderArea reqRoot
reqNode = widgetUpdateSizeReq (_wnWidget widgetRoot) wenv widgetRoot
newRoot = widgetResize (reqNode ^. L.widget) wenv viewport renderArea reqNode
findWidgetByKey
:: WidgetKey

View File

@ -320,6 +320,8 @@
- Do not hover if mouse drag on different widget
- Fix selectOnBlur for dropdown
- Rename WidgetInstance to WidgetNodeStatus (or similar)
- Check dropdown's list not being properly located after resize/scroll (not clear)
- Rename WidgetResult's widget to node
- Pending
- Add testing
@ -337,24 +339,21 @@
- Add user documentation
Maybe postponed after release?
- Remove createThemed and move Alert/Dialog to use composite
- Draw close button on Dialog
- Check why putting box reduces label's space
- scroll $ vstack $ (\i -> box $ label ("Label: " <> showt i)) <$> [0..100::Int]
- Set focus on ButtonDown, not Click
- Can it be handled in Single/Container?
- Restore focus to previous widget when zstack changes (dialog situation)
- Also think about not losing focus because of click (when onlyTopFocusable is active)
- ZStack should set _weIsTopLayer based on used space
- Avoid resizing non visible elements (stack/grid)
- Avoid findNextFocus on unfocusable children (listView items)
- Does this make sense? Check with a composite listView item
- Focus event may need to be handled to update highlighted item
- Check dropdown's list not being properly located after resize/scroll (not clear)
- Draw close button on Dialog
- Remove createThemed and move Alert/Dialog to use composite
- Set focus on ButtonDown, not Click
- Can it be handled in Single/Container?
- Image
- Can performance be improved? Use sbt functions?
- Does adding function to return imgData from Renderer make sense? Replace imageExists?
- Remove delay logic when adding an image
- When adding image, on failure remove an the least used image and retry
- Make sure WidgetTask/Node association is preserved if node location changes
- Make sure WidgetTask/Node association is preserved if node location in tree changes
- Further textField improvements
- Handle undo history
- Handle mouse selection
@ -362,6 +361,18 @@ Maybe postponed after release?
- Scroll wheel rate should be configurable, or even depend on content size
- Check if SDL can be initialized headless (for tests that involve the API)
- https://discourse.libsdl.org/t/possible-to-run-sdl2-headless/25665/2
- Does it make sense to handle offset
- It would avoid resizing on scroll
- We need transform stack on Renderer (also rotate?)
- We need to transform events
- This way we avoid having to translate widgets
- We need current transform in WidgetEnv
- Only used for rendering
- hovered would also use it
- We need to set transform on render (and clear it)
- Check scroll in scroll (one with max height)
- Remove getSizeReq from Widget interface. Keep it in Single/Container
- Other Widgets should take care of updating those fields during init/merge/handleEvent/handleMessage
- Create Keystroke component (shortcuts and general key handling like Esc for dialog)
- Create Tooltip component. It just wraps a given component and draws the tooltip with renderOverlay
- Create Theme widget to override global theme

View File

@ -137,7 +137,7 @@ nodeInit wenv node = newNode where
nodeUpdateSizeReq :: WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
nodeUpdateSizeReq wenv node = (sizeReqW, sizeReqH) where
WidgetResult node2 _ _ = widgetInit (node ^. L.widget) wenv node
reqNode = widgetGetSizeReq (node2 ^. L.widget) wenv node2
reqNode = widgetUpdateSizeReq (node2 ^. L.widget) wenv node2
sizeReqW = reqNode ^. L.sizeReqW
sizeReqH = reqNode ^. L.sizeReqH