Fix issue with strict sized elements in grid widget

This commit is contained in:
Francisco Vallarino 2020-09-30 00:25:27 -03:00
parent 28c124b791
commit 56b9c1f6a5
2 changed files with 18 additions and 33 deletions

View File

@ -134,31 +134,6 @@ handleAppEvent model evt = case evt of
_ -> Model model _ -> Model model
buildUI model = trace "Creating UI" widgetTree where buildUI model = trace "Creating UI" widgetTree where
-- widgetTree1 = scroll $ vstack (newLabel <$> [0..100::Int])
-- widgetTree2 = vstack [
-- label (showt $ model ^. clickCount),
-- textField textField1 `style` bgColor lightGray,
-- hstack [
-- radio fruit Apple,
-- radio fruit Orange,
-- radio fruit Pear
-- ],
-- hstack [
-- checkbox condition1,
-- checkbox condition2,
-- checkbox condition3,
-- checkbox condition1
-- ],
-- --`style` bgColor lightGray <> textSize 40
-- --`focus` bgColor darkGray <> textSize 400,
-- --hstack labels `key` "Labels",
-- --hstack [
-- -- label "Label 1",
-- -- label "Label 2"
-- --],
-- listView textField1 items id,
-- button IncButton "Click!"
-- ] `key` "Main"
widgetTree = vstack [ widgetTree = vstack [
hstack [ hstack [
radioV (model ^. fruit) RadioSt Apple, radioV (model ^. fruit) RadioSt Apple,
@ -171,7 +146,7 @@ buildUI model = trace "Creating UI" widgetTree where
checkbox condition3, checkbox condition3,
checkbox_ condition1 [onChange CheckboxSt] checkbox_ condition1 [onChange CheckboxSt]
], ],
hstack [ hgrid [
label_ "This is a really long label used to check what I did works fine" [textEllipsis], label_ "This is a really long label used to check what I did works fine" [textEllipsis],
label "Short label" label "Short label"
], ],

View File

@ -34,19 +34,29 @@ makeFixedGrid isHorizontal = widget where
getSizeReq wenv widgetInst children = reqSize where getSizeReq wenv widgetInst children = reqSize where
vchildren = Seq.filter _wiVisible children vchildren = Seq.filter _wiVisible children
vreqs = _wiSizeReq <$> vchildren vreqs = _wiSizeReq <$> vchildren
reqSize = SizeReq (Size width height) FlexibleSize FlexibleSize nReqs = length vreqs
width strictReqs policy = Seq.filter (\r -> policy r == StrictSize) vreqs
| Seq.null vchildren = 0 strictH = nReqs > 0 && Seq.length (strictReqs _srPolicyW) == nReqs
| otherwise = wMul * (maximum . fmap (_sW . _srSize)) vreqs strictV = nReqs > 0 && Seq.length (strictReqs _srPolicyH) == nReqs
height
| Seq.null vchildren = 0
| otherwise = hMul * (maximum . fmap (_sH . _srSize)) vreqs
wMul wMul
| isHorizontal = fromIntegral (length vchildren) | isHorizontal = fromIntegral (length vchildren)
| otherwise = 1 | otherwise = 1
hMul hMul
| isHorizontal = 1 | isHorizontal = 1
| otherwise = fromIntegral (length vchildren) | otherwise = fromIntegral (length vchildren)
width
| Seq.null vchildren = 0
| otherwise = wMul * (maximum . fmap (_sW . _srSize)) vreqs
height
| Seq.null vchildren = 0
| otherwise = hMul * (maximum . fmap (_sH . _srSize)) vreqs
hPolicy
| not isHorizontal && strictH = StrictSize
| otherwise = FlexibleSize
vPolicy
| isHorizontal && strictV = StrictSize
| otherwise = FlexibleSize
reqSize = SizeReq (Size width height) hPolicy vPolicy
resize wenv viewport renderArea children widgetInst = resized where resize wenv viewport renderArea children widgetInst = resized where
Rect l t w h = renderArea Rect l t w h = renderArea