Skip to content

Commit

Permalink
Merge branch 'v_simpleflex' into v_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
prepare committed Apr 20, 2015
2 parents 18c7bac + eae1ad2 commit 18b8cd7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ such as

7) debug view

8) more layout support eg. inline-block,relative, absolute , flex etc
8) more layout support eg. inline-block,relative, absolute ,fixed, flex etc

9) added custom controls eg. text editer control, scrollbar, gridbox etc.

Expand Down
11 changes: 6 additions & 5 deletions Source/HtmlRenderer.Demo/Samples/Basic/20_inlineblock4.htm
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
<body>
<div style="width:600px;">
<div style="display:inline-block;width:25%;height:50px;">
A
A0123
</div>
<div style="display:inline-block;width:25%;height:50px;">
B
B0123
</div>
<div style="display:inline-block;width:25%;height:50px;">
C
C0123
</div>
<div style="display:inline-block;width:25%;height:50px;">
D
D0123
</div>
</div>
</div>

</body>
</html>
6 changes: 6 additions & 0 deletions Source/HtmlRenderer.Demo/Samples/Css3Flex/1_simple_flex.htm
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@
<div style="flex-grow:1">3</div>
<div style="flex-grow:1">4</div>
</div>
<div style="display:flex;width:300px">
<div style="flex-grow:1">1</div>
<div style="flex-grow:0">2</div>
<div style="flex-grow:1">3</div>
<div style="flex-grow:1">4</div>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions Source/HtmlRenderer.Demo/Samples/Css3Flex/2_flex2.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<title>simple flex2</title>
</head>
<body>
<div style="display:flex;width:300px;height:60px;background-color:red;">
<div style="flex-grow:1;background-color:blue;">1</div>
<div style="flex-grow:1;background-color:blue;">2</div>
<div style="flex-grow:1;background-color:blue;">3</div>
<div style="flex-grow:1;background-color:blue;">4</div>
</div>
</body>
</html>
3 changes: 2 additions & 1 deletion Source/LayoutFarm.HtmlRenderer/2_Boxes/2_Runs/CssRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public override string ToString()

switch (this.Kind)
{
case CssRunKind.BlockRun:
case CssRunKind.SolidContent:
{
// not a text word - set full selection
Expand Down Expand Up @@ -307,7 +308,7 @@ public override string ToString()
selectionIndex = 0;
runSelectionOffset = (int)this.Width;
}
} break;
} break;
default:
{
throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,15 +980,10 @@ static void RearrangeWithFlexContext(CssBox box, LayoutVisitor lay)

//this is an experiment!,
var children = CssBox.UnsafeGetChildren(box);
var cnode = children.GetFirstLinkedNode();

float boxwidth = box.SizeWidth;
float boxheight = box.SizeHeight;
var cnode = children.GetFirstLinkedNode();

List<FlexItem> simpleFlexLine = new List<FlexItem>();
FlexLine flexLine = new FlexLine();
flexLine.AvaliableParentWidth = boxwidth;
flexLine.AvaliableParentHeight = boxheight;
FlexLine flexLine = new FlexLine(box);
while (cnode != null)
{
flexLine.AddChild(new FlexItem(cnode.Value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ public CssBox Box
class FlexLine
{
List<FlexItem> flexItems = new List<FlexItem>();
CssBox flexCssBox;
public FlexLine(CssBox flexCssBox)
{
this.flexCssBox = flexCssBox;
AvaliableParentWidth = flexCssBox.SizeWidth;
AvaliableParentHeight = flexCssBox.SizeHeight;
}
public void AddChild(FlexItem item)
{
this.flexItems.Add(item);
Expand All @@ -153,8 +160,8 @@ public FlexItem GetItem(int index)
return this.flexItems[index];
}

public float AvaliableParentWidth { get; set; }
public float AvaliableParentHeight { get; set; }
float AvaliableParentWidth { get; set; }
float AvaliableParentHeight { get; set; }

public float LineHeightAfterArrange { get; private set; }
public float LineWidthAfterArrange { get; private set; }
Expand Down Expand Up @@ -229,9 +236,13 @@ public void Arrange()
//find if it can shrink?

}

this.LineWidthAfterArrange = curX;

//-----------------------------------------------
//check for height
float maxHeight = 0;
for (int i = 0; i < j; ++i)
for (int i = flexItems.Count - 1; i >= 0; --i)
{
FlexItem flexItem = flexItems[i];
CssBox box = flexItem.Box;
Expand All @@ -240,8 +251,29 @@ public void Arrange()
maxHeight = box.SizeHeight;
}
}
this.LineHeightAfterArrange = maxHeight;
this.LineWidthAfterArrange = curX;
if (maxHeight < this.AvaliableParentHeight)
{
//expand item or shrink
if (this.flexCssBox.Height.IsEmptyOrAuto)
{
//autoheight
//then set new height for parent
this.LineHeightAfterArrange = maxHeight;
}
else
{
//try expand flex item
for (int i = flexItems.Count - 1; i >= 0; --i)
{
FlexItem flexItem = flexItems[i];
if (!flexItem.ReachMaxHeight)
{
flexItem.Box.SetHeight(this.AvaliableParentHeight);
}
}
this.LineHeightAfterArrange = this.AvaliableParentHeight;
}
}
}
}
}

0 comments on commit 18b8cd7

Please sign in to comment.