Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Improvements to flow containers and fixes for texture containers (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que committed Jun 4, 2017
1 parent 26fd9e5 commit 0ce57e1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
25 changes: 23 additions & 2 deletions Protogame/UserInterface/Control/Container/FlowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void SetChildSize(IContainer child, string size)
_sizes.Insert(index, size);
}

public void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
public virtual void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
{
foreach (var kv in ChildrenWithLayouts(layout))
{
Expand All @@ -112,7 +112,7 @@ public void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime,
}
}

public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
public virtual bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
{
foreach (var kv in ChildrenWithLayouts(layout))
{
Expand All @@ -124,6 +124,27 @@ public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext c

return false;
}

protected int? GetPureChildrenSize()
{
var acc = 0;
foreach (var s in _sizes)
{
if (s.EndsWith("%", StringComparison.Ordinal))
{
return null;
}
else if (s == "*")
{
return null;
}
else
{
acc += Convert.ToInt32(s);
}
}
return acc;
}

protected abstract Rectangle CreateChildLayout(Rectangle layout, int accumulated, int size);

Expand Down
15 changes: 13 additions & 2 deletions Protogame/UserInterface/Control/Container/HorizontalContainer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
namespace Protogame
{
using System;
using System.Linq;
using Microsoft.Xna.Framework;
public class HorizontalContainer : FlowContainer

public class HorizontalContainer : FlowContainer, IHasDesiredSize
{
public int? GetDesiredHeight(ISkinLayout skin)
{
return null;
}

public int? GetDesiredWidth(ISkinLayout skin)
{
return GetPureChildrenSize();
}

public override void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
{
skinDelegator.Render(context, layout, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegato
case "stretch":
default:
// Nothing to do.
return;
break;
}

_renderUtilities.RenderTexture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegato
case "stretch":
default:
// Nothing to do.
return;
break;
}

_renderUtilities.RenderTexture(
Expand Down
15 changes: 13 additions & 2 deletions Protogame/UserInterface/Control/Container/VerticalContainer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
namespace Protogame
{
using System;
using System.Linq;
using Microsoft.Xna.Framework;
public class VerticalContainer : FlowContainer

public class VerticalContainer : FlowContainer, IHasDesiredSize
{
public int? GetDesiredHeight(ISkinLayout skin)
{
return GetPureChildrenSize();
}

public int? GetDesiredWidth(ISkinLayout skin)
{
return null;
}

public override void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
{
skinDelegator.Render(context, layout, this);
Expand Down

0 comments on commit 0ce57e1

Please sign in to comment.