@@ -20,7 +20,7 @@ type CachedMeasurement struct {
20
20
// layouts should not require more than 16 entries to fit within the cache.
21
21
const maxCachedResultCount = 16
22
22
23
- // Layout describes layout
23
+ // Layout describes position information after layout is finished
24
24
type Layout struct {
25
25
Position [4 ]float32
26
26
Dimensions [2 ]float32
@@ -46,7 +46,7 @@ type Layout struct {
46
46
cachedLayout CachedMeasurement
47
47
}
48
48
49
- // Style describes a style
49
+ // Style describes CSS flexbox style of the node
50
50
type Style struct {
51
51
Direction Direction
52
52
FlexDirection FlexDirection
@@ -84,7 +84,7 @@ type Config struct {
84
84
Context interface {}
85
85
}
86
86
87
- // Node describes a node
87
+ // Node describes a an element
88
88
type Node struct {
89
89
Style Style
90
90
Layout Layout
@@ -297,7 +297,7 @@ func NewNode() *Node {
297
297
return NewNodeWithConfig (& configDefaults )
298
298
}
299
299
300
- // NodeReset resets a node
300
+ // Reset resets a node
301
301
func (node * Node ) Reset () {
302
302
assertWithNode (node , len (node .Children ) == 0 , "Cannot reset a node which still has children attached" )
303
303
assertWithNode (node , node .Parent == nil , "Cannot reset a node still attached to a parent" )
@@ -390,7 +390,7 @@ func (node *Node) deleteChild(child *Node) *Node {
390
390
return nil
391
391
}
392
392
393
- // RemoveChild removes the child
393
+ // RemoveChild removes child node
394
394
func (node * Node ) RemoveChild (child * Node ) {
395
395
if node .deleteChild (child ) != nil {
396
396
child .Layout = nodeDefaults .Layout // layout is no longer valid
@@ -399,7 +399,7 @@ func (node *Node) RemoveChild(child *Node) {
399
399
}
400
400
}
401
401
402
- // GetChild returns a child
402
+ // GetChild returns a child at a given index
403
403
func (node * Node ) GetChild (idx int ) * Node {
404
404
if idx < len (node .Children ) {
405
405
return node .Children [idx ]
@@ -752,13 +752,11 @@ func flexDirectionCross(flexDirection FlexDirection, direction Direction) FlexDi
752
752
return FlexDirectionColumn
753
753
}
754
754
755
- // nodeIsFlex returns true if node is flex
756
755
func nodeIsFlex (node * Node ) bool {
757
756
return (node .Style .PositionType == PositionTypeRelative &&
758
757
(resolveFlexGrow (node ) != 0 || nodeResolveFlexShrink (node ) != 0 ))
759
758
}
760
759
761
- // isBaselineLayout returns true if it's baseline layout
762
760
func isBaselineLayout (node * Node ) bool {
763
761
if flexDirectionIsColumn (node .Style .FlexDirection ) {
764
762
return false
@@ -898,7 +896,6 @@ func nodeSetChildTrailingPosition(node *Node, child *Node, axis FlexDirection) {
898
896
node .Layout .measuredDimensions [dim [axis ]] - size - child .Layout .Position [pos [axis ]]
899
897
}
900
898
901
- // nodeRelativePosition gets relative position.
902
899
// If both left and right are defined, then use left. Otherwise return
903
900
// +left or -right depending on which is defined.
904
901
func nodeRelativePosition (node * Node , axis FlexDirection , axisSize float32 ) float32 {
@@ -980,7 +977,7 @@ func nodeComputeFlexBasisForChild(node *Node,
980
977
981
978
if ! FloatIsUndefined (resolvedFlexBasis ) && ! FloatIsUndefined (mainAxisSize ) {
982
979
if FloatIsUndefined (child .Layout .computedFlexBasis ) ||
983
- (ConfigIsExperimentalFeatureEnabled ( child .Config , ExperimentalFeatureWebFlexBasis ) &&
980
+ (child .Config . IsExperimentalFeatureEnabled ( ExperimentalFeatureWebFlexBasis ) &&
984
981
child .Layout .computedFlexBasisGeneration != currentGenerationCount ) {
985
982
child .Layout .computedFlexBasis =
986
983
fmaxf (resolvedFlexBasis , nodePaddingAndBorderForAxis (child , mainAxis , parentWidth ))
@@ -3051,17 +3048,16 @@ func CalculateLayout(node *Node, parentWidth float32, parentHeight float32, pare
3051
3048
}
3052
3049
}
3053
3050
3054
- // ConfigSetExperimentalFeatureEnabled enables experimental feature
3055
- func ConfigSetExperimentalFeatureEnabled (config * Config , feature ExperimentalFeature , enabled bool ) {
3051
+ // SetExperimentalFeatureEnabled enables experimental feature
3052
+ func (config * Config ) SetExperimentalFeatureEnabled ( feature ExperimentalFeature , enabled bool ) {
3056
3053
config .experimentalFeatures [feature ] = enabled
3057
3054
}
3058
3055
3059
- // ConfigIsExperimentalFeatureEnabled returns if experimental feature is enabled
3060
- func ConfigIsExperimentalFeatureEnabled (config * Config , feature ExperimentalFeature ) bool {
3056
+ // IsExperimentalFeatureEnabled returns if experimental feature is enabled
3057
+ func (config * Config ) IsExperimentalFeatureEnabled ( feature ExperimentalFeature ) bool {
3061
3058
return config .experimentalFeatures [feature ]
3062
3059
}
3063
3060
3064
- // log logs
3065
3061
func log (node * Node , level LogLevel , format string , args ... interface {}) {
3066
3062
fmt .Printf (format , args ... )
3067
3063
}
@@ -3072,12 +3068,10 @@ func assertCond(cond bool, format string, args ...interface{}) {
3072
3068
}
3073
3069
}
3074
3070
3075
- // assertWithNode assert if cond is not true
3076
3071
func assertWithNode (node * Node , cond bool , format string , args ... interface {}) {
3077
3072
assertCond (cond , format , args ... )
3078
3073
}
3079
3074
3080
- // assertWithConfig asserts with config
3081
3075
func assertWithConfig (config * Config , condition bool , message string ) {
3082
3076
if ! condition {
3083
3077
panic (message )
0 commit comments