mirror of
https://github.com/fjvallarino/monomer.git
synced 2024-09-21 00:38:01 +03:00
Use SizeReq factor in stack
This commit is contained in:
parent
cafe26e648
commit
091b234336
11
app/Main.hs
11
app/Main.hs
@ -81,9 +81,7 @@ main = do
|
|||||||
|
|
||||||
winSize <- getDrawableSize window
|
winSize <- getDrawableSize window
|
||||||
|
|
||||||
let model = def {
|
let model = def
|
||||||
_textField1 = "This is a test! Or not? Well, we'll see"
|
|
||||||
}
|
|
||||||
let devicePixelRate = _sW winSize / fromIntegral screenWidth
|
let devicePixelRate = _sW winSize / fromIntegral screenWidth
|
||||||
let appWidget = createApp model (Just InitApp) handleAppEvent buildUI
|
let appWidget = createApp model (Just InitApp) handleAppEvent buildUI
|
||||||
let monomerContext = initMonomerContext () winSize useHiDPI devicePixelRate
|
let monomerContext = initMonomerContext () winSize useHiDPI devicePixelRate
|
||||||
@ -150,9 +148,10 @@ buildUI model = trace "Creating UI" widgetTree where
|
|||||||
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"
|
||||||
],
|
],
|
||||||
hgrid [
|
hstack [
|
||||||
image "assets/images/pecans.jpg",
|
image_ "assets/images/pecans.jpg" [fitFill],
|
||||||
image_ "https://picsum.photos/600/400" [fitHeight, transparency 1]
|
spacer,
|
||||||
|
image_ "https://picsum.photos/600/400" [fitHeight]
|
||||||
],
|
],
|
||||||
hstack [
|
hstack [
|
||||||
label "Test"
|
label "Test"
|
||||||
|
@ -50,8 +50,8 @@ instance Monoid ThemeState where
|
|||||||
|
|
||||||
-- | Basic styling attributes
|
-- | Basic styling attributes
|
||||||
data SizeReq
|
data SizeReq
|
||||||
= FlexSize Coord Factor
|
= FixedSize Coord
|
||||||
| FixedSize Coord
|
| FlexSize Coord Factor
|
||||||
-- | MinSize Coord
|
-- | MinSize Coord
|
||||||
-- | MaxSize Coord
|
-- | MaxSize Coord
|
||||||
-- | RangeSize Coord Coord
|
-- | RangeSize Coord Coord
|
||||||
|
@ -4,6 +4,8 @@ module Monomer.Widget.Internal (
|
|||||||
handleStyleChange,
|
handleStyleChange,
|
||||||
isStrictReq,
|
isStrictReq,
|
||||||
getReqCoord,
|
getReqCoord,
|
||||||
|
getReqFactor,
|
||||||
|
getReqFactored,
|
||||||
modifyReqCoord
|
modifyReqCoord
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -68,12 +70,19 @@ isStrictReq FlexSize{} = False
|
|||||||
isStrictReq _ = True
|
isStrictReq _ = True
|
||||||
|
|
||||||
getReqCoord :: SizeReq -> Coord
|
getReqCoord :: SizeReq -> Coord
|
||||||
getReqCoord (FlexSize c _) = c
|
|
||||||
getReqCoord (FixedSize c) = c
|
getReqCoord (FixedSize c) = c
|
||||||
|
getReqCoord (FlexSize c _) = c
|
||||||
--getReqCoord (MinSize c) = c
|
--getReqCoord (MinSize c) = c
|
||||||
--getReqCoord (MaxSize c) = c
|
--getReqCoord (MaxSize c) = c
|
||||||
--getReqCoord (RangeSize c1 _) = c1
|
--getReqCoord (RangeSize c1 _) = c1
|
||||||
|
|
||||||
|
getReqFactor :: SizeReq -> Factor
|
||||||
|
getReqFactor (FixedSize _) = 1
|
||||||
|
getReqFactor (FlexSize _ f) = f
|
||||||
|
|
||||||
|
getReqFactored :: SizeReq -> Coord
|
||||||
|
getReqFactored req = getReqFactor req * getReqCoord req
|
||||||
|
|
||||||
modifyReqCoord :: SizeReq -> (Coord -> Coord) -> SizeReq
|
modifyReqCoord :: SizeReq -> (Coord -> Coord) -> SizeReq
|
||||||
modifyReqCoord (FlexSize c factor) f = FlexSize (f c) factor
|
modifyReqCoord (FlexSize c factor) f = FlexSize (f c) factor
|
||||||
modifyReqCoord (FixedSize c) f = FixedSize (f c)
|
modifyReqCoord (FixedSize c) f = FixedSize (f c)
|
||||||
|
@ -108,7 +108,8 @@ makeCheckbox widgetData config = widget where
|
|||||||
reqs = setValueReq ++ _ckcOnChangeReq config
|
reqs = setValueReq ++ _ckcOnChangeReq config
|
||||||
clickReqs = setFocusReq : reqs
|
clickReqs = setFocusReq : reqs
|
||||||
|
|
||||||
getSizeReq wenv inst = (FixedSize checkboxWidth, FixedSize checkboxWidth)
|
getSizeReq wenv inst =
|
||||||
|
(FixedSize checkboxWidth, FixedSize checkboxWidth)
|
||||||
|
|
||||||
render renderer wenv inst = do
|
render renderer wenv inst = do
|
||||||
renderCheckbox renderer config rarea fgColor
|
renderCheckbox renderer config rarea fgColor
|
||||||
|
@ -52,17 +52,18 @@ makeStack isHorizontal = widget where
|
|||||||
|
|
||||||
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
|
||||||
vchildren = Seq.filter _wiVisible children
|
|
||||||
mainSize = if isHorizontal then w else h
|
mainSize = if isHorizontal then w else h
|
||||||
mainStart = if isHorizontal then l else t
|
mainStart = if isHorizontal then l else t
|
||||||
|
vchildren = Seq.filter _wiVisible children
|
||||||
sChildren = Seq.filter (isStrictReq . mainReqSelector) vchildren
|
sChildren = Seq.filter (isStrictReq . mainReqSelector) vchildren
|
||||||
fChildren = Seq.filter (not . isStrictReq . mainReqSelector) vchildren
|
fChildren = Seq.filter (not . isStrictReq . mainReqSelector) vchildren
|
||||||
fExists = not $ null fChildren
|
fExists = not $ null fChildren
|
||||||
sSize = sizeSelector $ calcSize sChildren
|
sSize = sizeSelector $ calcSize sChildren
|
||||||
fSize = sizeSelector $ calcSize fChildren
|
fSize = sizeSelector $ calcSize fChildren
|
||||||
|
fSizeFactor = sizeSelector $ calcSizeFactor fChildren
|
||||||
rSize = max 0 (mainSize - sSize)
|
rSize = max 0 (mainSize - sSize)
|
||||||
fExtra
|
fExtra
|
||||||
| fExists && fSize > 0 = (rSize - fSize) / fSize
|
| fExists && fSize > 0 = (rSize - fSize) / fSizeFactor
|
||||||
| otherwise = 0
|
| otherwise = 0
|
||||||
assignedArea = Seq.zip newViewports newViewports
|
assignedArea = Seq.zip newViewports newViewports
|
||||||
(newViewports, _) = foldl' foldHelper (Seq.empty, mainStart) children
|
(newViewports, _) = foldl' foldHelper (Seq.empty, mainStart) children
|
||||||
@ -77,7 +78,8 @@ makeStack isHorizontal = widget where
|
|||||||
emptyRect = Rect l t 0 0
|
emptyRect = Rect l t 0 0
|
||||||
calcMainSize = case mainReqSelector child of
|
calcMainSize = case mainReqSelector child of
|
||||||
FixedSize sz -> sz
|
FixedSize sz -> sz
|
||||||
FlexSize sz factor -> (1 + fExtra) * sz -- factor still not accounted for
|
-- factor still not accounted for
|
||||||
|
FlexSize sz factor -> (1 + fExtra * factor) * sz -- (1 + fExtra) * sz
|
||||||
calcSndSize total = case sndReqSelector child of
|
calcSndSize total = case sndReqSelector child of
|
||||||
FixedSize sz -> sz
|
FixedSize sz -> sz
|
||||||
_ -> total
|
_ -> total
|
||||||
@ -88,26 +90,32 @@ makeStack isHorizontal = widget where
|
|||||||
| isHorizontal = hRect
|
| isHorizontal = hRect
|
||||||
| otherwise = vRect
|
| otherwise = vRect
|
||||||
|
|
||||||
calcSize vchildren = Size width height where
|
calcSize vchildren = calcSize_ vchildren False
|
||||||
(maxWidth, sumWidth, maxHeight, sumHeight) = calcDimensions vchildren
|
calcSizeFactor vchildren = calcSize_ vchildren True
|
||||||
width
|
|
||||||
| isHorizontal = sumWidth
|
|
||||||
| otherwise = maxWidth
|
|
||||||
height
|
|
||||||
| isHorizontal = maxHeight
|
|
||||||
| otherwise = sumHeight
|
|
||||||
|
|
||||||
calcDimensions vchildren = (maxWidth, sumWidth, maxHeight, sumHeight) where
|
calcSize_ vchildren useFactor = Size width height where
|
||||||
|
(maxW, sumW, maxH, sumH) = calcDimensions vchildren useFactor
|
||||||
|
width
|
||||||
|
| isHorizontal = sumW
|
||||||
|
| otherwise = maxW
|
||||||
|
height
|
||||||
|
| isHorizontal = maxH
|
||||||
|
| otherwise = sumH
|
||||||
|
|
||||||
|
calcDimensions vchildren useFactor = (maxW, sumW, maxH, sumH) where
|
||||||
|
getReqSize
|
||||||
|
| useFactor = getReqFactored
|
||||||
|
| otherwise = getReqCoord
|
||||||
vreqsW = _wiSizeReqW <$> vchildren
|
vreqsW = _wiSizeReqW <$> vchildren
|
||||||
vreqsH = _wiSizeReqH <$> vchildren
|
vreqsH = _wiSizeReqH <$> vchildren
|
||||||
sumWidth = (sum . fmap getReqCoord) vreqsW
|
sumW = (sum . fmap getReqSize) vreqsW
|
||||||
sumHeight = (sum . fmap getReqCoord) vreqsH
|
sumH = (sum . fmap getReqSize) vreqsH
|
||||||
maxWidth
|
maxW
|
||||||
| Seq.null vchildren = 0
|
| Seq.null vchildren = 0
|
||||||
| otherwise = (maximum . fmap getReqCoord) vreqsW
|
| otherwise = (maximum . fmap getReqSize) vreqsW
|
||||||
maxHeight
|
maxH
|
||||||
| Seq.null vchildren = 0
|
| Seq.null vchildren = 0
|
||||||
| otherwise = (maximum . fmap getReqCoord) vreqsH
|
| otherwise = (maximum . fmap getReqSize) vreqsH
|
||||||
|
|
||||||
mainReqSelector
|
mainReqSelector
|
||||||
| isHorizontal = _wiSizeReqW
|
| isHorizontal = _wiSizeReqW
|
||||||
|
Loading…
Reference in New Issue
Block a user