mirror of
https://github.com/fjvallarino/monomer.git
synced 2024-09-11 12:05:35 +03:00
Modify distribution of space in stack
This commit is contained in:
parent
7ca1a8c401
commit
f585dd3320
@ -1,8 +1,6 @@
|
||||
{-# LANGUAGE BangPatterns #-}
|
||||
{-# LANGUAGE ConstraintKinds #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MultiWayIf #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main where
|
||||
|
@ -1,8 +1,7 @@
|
||||
module Monomer.Graphics.Types where
|
||||
|
||||
import Data.Default
|
||||
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
|
||||
data Color = Color {
|
||||
_r :: Int,
|
||||
@ -17,7 +16,7 @@ instance Semigroup Color where
|
||||
instance Default Color where
|
||||
def = Color 0 0 0 1.0
|
||||
|
||||
type Font = T.Text
|
||||
type Font = Text
|
||||
type FontSize = Double
|
||||
|
||||
data Align = Align AlignH AlignV deriving (Show, Eq)
|
||||
|
@ -53,11 +53,11 @@ makeStack isHorizontal = createContainer {
|
||||
remainderExist = not $ null rChildren
|
||||
sSize = sizeSelector $ calcPreferredSize sChildren
|
||||
fSize = sizeSelector $ calcPreferredSize fChildren
|
||||
fRatio = if | mSize - sSize > fSize && remainderExist -> 1
|
||||
-- | mSize - sSize > fSize && not remainderExist -> (mSize - sSize) / fSize
|
||||
| mSize - sSize > 0 -> (mSize - sSize) / fSize
|
||||
| otherwise -> 0
|
||||
remainderTotal = mSize - (sSize + fSize * fRatio)
|
||||
fCount = fromIntegral $ length fChildren
|
||||
fExtra = if fCount > 0 && not remainderExist
|
||||
then (mSize - sSize - fSize) / fCount
|
||||
else 0
|
||||
remainderTotal = mSize - (sSize + fCount * fExtra)
|
||||
remainderUnit = if remainderExist then max 0 remainderTotal / fromIntegral remainderCount else 0
|
||||
newViewports = Seq.reverse revViewports
|
||||
assignedArea = Seq.zip newViewports newViewports
|
||||
@ -72,19 +72,22 @@ makeStack isHorizontal = createContainer {
|
||||
req = nodeValue $ snd childPair
|
||||
srSize = _sizeRequested req
|
||||
emptyRect = Rect l t 0 0
|
||||
hRect = Rect offset t newSize h
|
||||
vRect = Rect l offset w newSize
|
||||
newSize = case policySelector req of
|
||||
hRect = Rect offset t calcNewSize h
|
||||
vRect = Rect l offset w calcNewSize
|
||||
calcNewSize = case policySelector req of
|
||||
StrictSize -> sizeSelector srSize
|
||||
FlexibleSize -> sizeSelector srSize * fRatio
|
||||
FlexibleSize -> sizeSelector srSize + fExtra
|
||||
RemainderSize -> remainderUnit
|
||||
|
||||
calcPreferredSize childrenPairs = Size width height where
|
||||
(maxWidth, sumWidth, maxHeight, sumHeight) = calcDimensions childrenPairs
|
||||
width = if isHorizontal then sumWidth else maxWidth
|
||||
height = if isHorizontal then maxHeight else sumHeight
|
||||
|
||||
calcDimensions childrenPairs = (maxWidth, sumWidth, maxHeight, sumHeight) where
|
||||
visiblePairs = Seq.filter (_instanceVisible . fst) childrenPairs
|
||||
visibleChildren = fmap (nodeValue . snd) visiblePairs
|
||||
maxWidth = if Seq.null visibleChildren then 0 else (maximum . fmap (_w . _sizeRequested)) visibleChildren
|
||||
sumWidth = (sum . fmap (_w . _sizeRequested)) visibleChildren
|
||||
maxHeight = if null visibleChildren then 0 else (maximum . fmap (_h . _sizeRequested)) visibleChildren
|
||||
sumHeight = (sum . fmap (_h . _sizeRequested)) visibleChildren
|
||||
width = if isHorizontal then sumWidth else maxWidth
|
||||
height = if isHorizontal then maxHeight else sumHeight
|
||||
|
@ -15,7 +15,7 @@
|
||||
# resolver:
|
||||
# name: custom-snapshot
|
||||
# location: "./custom-snapshot.yaml"
|
||||
resolver: lts-14.4
|
||||
resolver: lts-14.27
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
|
@ -48,7 +48,7 @@ packages:
|
||||
commit: 647c5611e23ad2822e974d9868faa481059258ca
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 523884
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/4.yaml
|
||||
sha256: 16f24be248b42c9e16d59db84378836b1e7c239448a041cae46d32daffa45a8b
|
||||
original: lts-14.4
|
||||
size: 524996
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/27.yaml
|
||||
sha256: 7ea31a280c56bf36ff591a7397cc384d0dff622e7f9e4225b47d8980f019a0f0
|
||||
original: lts-14.27
|
||||
|
Loading…
Reference in New Issue
Block a user