@ -9,6 +9,15 @@ class FlexContainerComponent extends Component {
* @ type { boolean }
* /
_ distributeEvenglyAfterGenerate ;
/ * *
* @ type { number } the amount that should be left out of the total space before the children
* space is set .
* /
# distributionRecess ;
/ * *
* @ type { number } the additional gap that should be left for children before their space is set
* /
# distributionGapPerChild ;
/ * *
* @ type { string }
* /
@ -68,14 +77,86 @@ class FlexContainerComponent extends Component {
}
/ * *
*
*
* @ param { number } [ recessFraction = 0.0 ] recessFraction a fraction / percentage ( < 1.0 ) of the recess
* that should be left out before distributing the remaining space .
* @ param { number } [ gapPerChild = 1 ] gapPerChild the gap per child , therefore the recess between children
* /
_ distributingSpacing ( recessFraction = 0.0 , gapPerChild = 1 ) {
if ( this . _ children && this . _ children . length > 1 ) {
let distributableSpace = 100 - 100 * recessFraction - ( this . _ children . length - 1 ) * gapPerChild ;
let childDistributionFraction = Math . floor (
( distributableSpace / this . _ children . length ) * 100
) / 100 ;
let direction = ( this . _ flexDirection === 'column' ? 'height' : "width" ) ;
for ( const icomp of this . _ children ) {
/ * s e t s t h e w i d t h f o r a l l e l e m e n t s ,
to avoid overlapping or line break because of lacking width ,
a percent is subtracted for every child element * /
/ * T o e n a b l e " o v e r r i d e " a n e w M o d i f i e r i s g e n e r a t e d a n d j o i n e d
with the modifier of the component * /
icomp . _ modifier . _ modifications [ direction ] = childDistributionFraction + "%" ;
icomp . _ modifier . _ modifications [ "max-" + direction ] = childDistributionFraction + "%" ;
}
}
}
/ * *
* Distributes the spacing of the childrens evengly ,
* according to the flexdirection of this component .
* By default this will be executed imediately when called .
* The spacing is distributed by :
* 100 - 100 * recessFraction - ( children ) * gapPerChild
*
* @ param { boolean } [ rightNow = true ] if set to false it will set properties accordingly
* so that the distribution will be executed on generate
* @ param { number } [ recessFraction = 0.0 ] recessFraction a fraction / percentage ( < 1.0 ) of the recess
* that should be left out before distributing the remaining space .
* @ param { number } [ gapPerChild = 1 ] gapPerChild the gap per child , therefore the recess between children
* @ returns { FlexContainerComponent }
* /
distibuteSpacingEvenly ( ) {
this . _ distributeEvenglyAfterGenerate = true ;
distibuteSpacingEvenly ( rightNow = true , recessFraction = 0.0 , gapPerChild = 1 ) {
if ( rightNow ) {
this . _ distributingSpacing ( recessFraction , gapPerChild ) ;
} else {
this . # distributionRecess = recessFraction ;
this . # distributionGapPerChild = gapPerChild ;
this . _ distributeEvenglyAfterGenerate = true ;
}
return this ;
}
/ * *
* Adds , sets , updates or overwrites the Modification of / f o r t h e c h i l d r e n o f t h i s c o m p o n e n t .
* Just calls . modifier ( modifier ) on each child .
*
* @ param { Modifier } modifier
* @ param { boolean | ExtStorage | ExtStoreType | OverwriteBehaviour } [ extStore = null ]
* @ returns { FlexContainerComponent } this component object
* /
modifyChildren ( modifier , underTheName = "" , extStore = false ) {
if ( underTheName === "" ) {
underTheName = ` . ${ this . _ compName } -style-children ` ;
}
if ( ! extStore ) {
for ( const child of this . _ children ) {
child . modifier ( modifier )
}
} else {
this . addStyleClass ( underTheName ) ;
this . _ styles . push (
new SStoreDefinition (
underTheName ,
modifier . ensureModifier ( )
)
) ;
}
return this ;
}
/ * *
* @ override
@ -83,25 +164,8 @@ class FlexContainerComponent extends Component {
* @ extends Component . generate ( )
* /
generate ( generator = singlepage , styleStore = null , functionStore = null ) {
if ( this . _ children && this . _ children . length > 1 ) {
if ( this . _ distributeEvenglyAfterGenerate ) {
let childDistributionFraction = Math . floor (
( ( 100 - this . _ children . length ) / this . _ children . length ) * 100
) / 100 ;
let direction = ( this . _ flexDirection === 'column' ? 'height' : "width" ) ;
for ( const icomp of this . _ children ) {
/ * s e t s t h e w i d t h f o r a l l e l e m e n t s ,
to avoid overlapping or line break because of lacking width ,
a percent is subtracted for every child element * /
/ * T o e n a b l e " o v e r r i d e " a n e w M o d i f i e r i s g e n e r a t e d a n d j o i n e d
with the modifier of the component * /
icomp . _ modifier . _ modifications [ direction ] = childDistributionFraction + "%" ;
icomp . _ modifier . _ modifications [ "max-" + direction ] = childDistributionFraction + "%" ;
}
}
if ( this . _ distributeEvenglyAfterGenerate ) {
this . _ distributingSpacing ( this . # distributionRecess , this . # distributionGapPerChild ) ;
}
return super . generate ( generator , styleStore , functionStore ) ;