From 4ad5bb6c6699a2d635cc5a9cf8cfaf9dc52decd5 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Tue, 3 Feb 2015 01:04:29 +0800 Subject: [PATCH] should layout node with position: absolute --- sass_layout.scss | 18 +++++++++++------- test.scss | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/sass_layout.scss b/sass_layout.scss index 7ea0a3c..7e16843 100644 --- a/sass_layout.scss +++ b/sass_layout.scss @@ -49,7 +49,7 @@ $global-frame-map: () !global; $flexs: map-get($parent-node, flex-total) + map-get($layout, flex); $start-direction: map-get($parent-node, start-direction); $axis: if(is-vertical($start-direction), height, width); - $non-flex-pixels: if(map-get($layout, flex) == 0, spent-space-on-direction($layout, $start-direction), 0); + $non-flex-pixels: if(map-get($layout, flex) == 0 and map-get($layout, position) != absolute, spent-space-on-direction($layout, $start-direction), 0); $parent-node: map-merge($parent-node, ( child-nodes: $child-nodes, flex-total: $flexs, @@ -188,17 +188,21 @@ $global-frame-map: () !global; } @if has-parent($node) and $direction == map-get($parent-node, start-direction) { @if map-get($node, flex) > 0 { - $flexable-space: if(is-vertical($direction), - map-get($parent-node, height) - map-get($parent-node, padding-top) - map-get($parent-node, padding-bottom), - map-get($parent-node, width) - map-get($parent-node, padding-left) - map-get ($parent-node, padding-right) + $flexable-space: if( + is-vertical($direction), + map-get($parent-node, height) - map-get($parent-node, padding-top) - map-get($parent-node, padding-bottom), + map-get($parent-node, width) - map-get($parent-node, padding-left) - map-get($parent-node, padding-right) ); + $flexable-space: $flexable-space - map-get($parent-node, non-flex-pixels); $flex-total: map-get($parent-node, flex-total); $node: map-set($node, if(is-vertical($direction), height, width), $flexable-space * map-get($node, flex) / $flex-total); } - $used-property: $used-property + spent-space-on-direction($node, $direction); - $parent-node: map-set($parent-node, used-#{$direction}, $used-property); - $parent-node: save-layout($parent-node); + @if map-get($node, position) != absolute { + $used-property: $used-property + spent-space-on-direction($node, $direction); + $parent-node: map-set($parent-node, used-#{$direction}, $used-property); + $parent-node: save-layout($parent-node); + } } @if has-parent($node) and $direction == map-get($parent-node, cross-start-direction) { $align-self: map-get($node, align-self); diff --git a/test.scss b/test.scss index 6b86d09..24a38bc 100644 --- a/test.scss +++ b/test.scss @@ -431,6 +431,21 @@ @include assert-equal(render-node('.r'), (0, 0, 10, 0)); } + @include test('should layout node with position: absolute') { + $global-frame-map: () !global; + .r { + @include layout(( width: 500, flex-direction: row)); + .c_a { @include layout(( flex: 1 )) } + .c_b { @include layout(( position: absolute, width: 50 )) } + .c_c { @include layout(( flex: 1 )) } + } + @include render-layout; + @include assert-equal(render-node('.r'), (500, 0, 0, 0)); + @include assert-equal(render-node('.r .c_a'), (250, 0, 0, 0)); + @include assert-equal(render-node('.r .c_b'), (50, 0, 0, 250)); + @include assert-equal(render-node('.r .c_c'), (250, 0, 0, 250)); + } + } @include report;