Skip to content

Commit

Permalink
Add group box and tab control containers
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Feb 12, 2024
1 parent eb451f8 commit 10da3b3
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Bonsai.Gui/ControlBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Bonsai.Gui
{
/// <summary>
/// Provides an abstract base class with common UI control functionality.
/// Provides an abstract base class for common UI control functionality.
/// </summary>
public abstract class ControlBuilderBase : ZeroArgumentExpressionBuilder, INamedElement
{
Expand Down
14 changes: 14 additions & 0 deletions src/Bonsai.Gui/GroupBoxBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel;

namespace Bonsai.Gui
{
/// <summary>
/// Represents an operator that specifies a mashup visualizer that displays a frame
/// around a group of other visualizers with an optional caption.
/// </summary>
[TypeVisualizer(typeof(GroupBoxVisualizer))]
[Description("Specifies a mashup visualizer that displays a frame around a group of other visualizers with an optional caption.")]
public class GroupBoxBuilder : TextControlBuilderBase
{
}
}
34 changes: 34 additions & 0 deletions src/Bonsai.Gui/GroupBoxVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Bonsai.Design;
using Bonsai.Gui;
using Bonsai;

[assembly: TypeVisualizer(typeof(DialogTypeVisualizer), Target = typeof(MashupSource<GroupBoxVisualizer>))]

namespace Bonsai.Gui
{
/// <summary>
/// Provides a type visualizer that displays a frame around a group of other
/// visualizers with an optional caption.
/// </summary>
public class GroupBoxVisualizer : ContainerControlVisualizerBase<GroupBox, GroupBoxBuilder>
{
/// <inheritdoc/>
protected override void AddControl(int index, Control control)
{
Control.Controls.Add(control);
}

/// <inheritdoc/>
protected override GroupBox CreateControl(IServiceProvider provider, GroupBoxBuilder builder)
{
var groupBox = new GroupBox();
groupBox.Dock = DockStyle.Fill;
groupBox.Size = new Size(320, 240);
groupBox.SubscribeTo(builder._Text, value => groupBox.Text = value);
return groupBox;
}
}
}
14 changes: 14 additions & 0 deletions src/Bonsai.Gui/TabControlBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel;

namespace Bonsai.Gui
{
/// <summary>
/// Represents an operator that specifies a mashup visualizer that can be used
/// to arrange other visualizers using a related set of tab pages.
/// </summary>
[TypeVisualizer(typeof(TabControlVisualizer))]
[Description("Specifies a mashup visualizer that can be used to arrange other visualizers using a related set of tab pages.")]
public class TabControlBuilder : ControlBuilderBase
{
}
}
35 changes: 35 additions & 0 deletions src/Bonsai.Gui/TabControlVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Bonsai.Design;
using Bonsai.Gui;
using Bonsai;
using System.Windows.Forms;
using System.Drawing;

[assembly: TypeVisualizer(typeof(DialogTypeVisualizer), Target = typeof(MashupSource<TabControlVisualizer>))]

namespace Bonsai.Gui
{
/// <summary>
/// Provides a type visualizer that can be used to arrange other visualizers
/// using a related set of tab pages.
/// </summary>
public class TabControlVisualizer : ContainerControlVisualizerBase<TabControl, TabControlBuilder>
{
/// <inheritdoc/>
protected override TabControl CreateControl(IServiceProvider provider, TabControlBuilder builder)
{
var tabControl = new TabControl();
tabControl.Dock = DockStyle.Fill;
tabControl.Size = new Size(320, 240);
return tabControl;
}

/// <inheritdoc/>
protected override void AddControl(int index, Control control)
{
var tabPage = new TabPage(control.Name);
tabPage.Controls.Add(control);
Control.Controls.Add(tabPage);
}
}
}
25 changes: 25 additions & 0 deletions src/Bonsai.Gui/TextControlBuilderBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel;
using System.Reactive.Subjects;

namespace Bonsai.Gui
{
/// <summary>
/// Provides an abstract base class for common UI text control functionality.
/// </summary>
[DefaultProperty(nameof(Text))]
public abstract class TextControlBuilderBase : ControlBuilderBase
{
internal readonly BehaviorSubject<string> _Text = new(string.Empty);

/// <summary>
/// Gets or sets the text associated with this control.
/// </summary>
[Category(nameof(CategoryAttribute.Appearance))]
[Description("The text associated with this control.")]
public string Text
{
get => _Text.Value;
set => _Text.OnNext(value);
}
}
}

0 comments on commit 10da3b3

Please sign in to comment.