mattercontrol/CustomWidgets/AltGroupBox.cs

124 lines
3 KiB
C#
Raw Normal View History

2015-04-08 15:20:10 -07:00
using MatterHackers.Agg;
2014-09-18 17:06:45 -07:00
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
public class AltGroupBox : FlowLayoutWidget
{
private GuiWidget groupBoxLabel;
private RGBA_Bytes borderColor = RGBA_Bytes.Black;
private GuiWidget clientArea;
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public RGBA_Bytes TextColor
{
get
{
TextWidget textBox = groupBoxLabel as TextWidget;
if (textBox != null)
{
return textBox.TextColor;
}
return RGBA_Bytes.White;
}
set
{
TextWidget textBox = groupBoxLabel as TextWidget;
if (textBox != null)
{
textBox.TextColor = value;
}
}
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public RGBA_Bytes BorderColor
{
get
{
return this.borderColor;
}
set
{
this.borderColor = value;
}
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public GuiWidget ClientArea
{
get
{
return clientArea;
}
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public AltGroupBox()
: this("")
{
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public AltGroupBox(GuiWidget groupBoxLabel)
: base(FlowDirection.TopToBottom)
{
this.Padding = new BorderDouble(5);
this.Margin = new BorderDouble(0);
this.groupBoxLabel = groupBoxLabel;
this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
this.BackgroundColor = ActiveTheme.Instance.TertiaryBackgroundColor;
2014-09-18 17:06:45 -07:00
2015-09-22 10:41:29 -07:00
if (groupBoxLabel != null)
{
groupBoxLabel.Margin = new BorderDouble(0);
groupBoxLabel.HAnchor = HAnchor.ParentLeftRight;
base.AddChild(groupBoxLabel);
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
clientArea = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren);
base.AddChild(clientArea);
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public AltGroupBox(string title)
: this(new TextWidget(title, pointSize: 12))
{
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
{
clientArea.AddChild(childToAdd, indexInChildrenList);
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public override string Text
{
get
{
2015-09-22 10:41:29 -07:00
if (groupBoxLabel != null)
{
return groupBoxLabel.Text;
}
return "";
2015-04-08 15:20:10 -07:00
}
set
{
2015-09-22 10:41:29 -07:00
if (groupBoxLabel != null)
{
groupBoxLabel.Text = value;
}
2015-04-08 15:20:10 -07:00
}
}
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
public override void OnDraw(Graphics2D graphics2D)
{
RectangleDouble localBounds = LocalBounds;
//// bottom
//graphics2D.Line(localBounds.Left + lineInset, localBounds.Bottom + lineInset, localBounds.Left + Width - lineInset, localBounds.Bottom + lineInset, this.borderColor);
//// left
//graphics2D.Line(localBounds.Left + lineInset, localBounds.Bottom + lineInset, localBounds.Left + lineInset, localBounds.Bottom + Height - lineInset, this.borderColor);
//// right
//graphics2D.Line(localBounds.Left + Width - lineInset, localBounds.Bottom + lineInset, localBounds.Left + Width - lineInset, localBounds.Bottom + Height - lineInset, this.borderColor);
//// top
//graphics2D.Line(localBounds.Left + lineInset, localBounds.Bottom + Height - lineInset, groupBoxLabel.BoundsRelativeToParent.Left - 2, localBounds.Bottom + Height - lineInset, this.borderColor);
//graphics2D.Line(groupBoxLabel.BoundsRelativeToParent.Right + 2, localBounds.Bottom + Height - lineInset, localBounds.Left + Width - lineInset, localBounds.Bottom + Height - lineInset, this.borderColor);
2014-09-18 17:06:45 -07:00
2015-04-08 15:20:10 -07:00
base.OnDraw(graphics2D);
}
}
}