From 10da3b3f3445ff3287459cc2221460f512d826f1 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Mon, 12 Feb 2024 22:57:16 +0000 Subject: [PATCH] Add group box and tab control containers --- src/Bonsai.Gui/ControlBuilderBase.cs | 2 +- src/Bonsai.Gui/GroupBoxBuilder.cs | 14 ++++++++++ src/Bonsai.Gui/GroupBoxVisualizer.cs | 34 +++++++++++++++++++++++ src/Bonsai.Gui/TabControlBuilder.cs | 14 ++++++++++ src/Bonsai.Gui/TabControlVisualizer.cs | 35 ++++++++++++++++++++++++ src/Bonsai.Gui/TextControlBuilderBase.cs | 25 +++++++++++++++++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/Bonsai.Gui/GroupBoxBuilder.cs create mode 100644 src/Bonsai.Gui/GroupBoxVisualizer.cs create mode 100644 src/Bonsai.Gui/TabControlBuilder.cs create mode 100644 src/Bonsai.Gui/TabControlVisualizer.cs create mode 100644 src/Bonsai.Gui/TextControlBuilderBase.cs diff --git a/src/Bonsai.Gui/ControlBuilderBase.cs b/src/Bonsai.Gui/ControlBuilderBase.cs index 0054f41..2a028ac 100644 --- a/src/Bonsai.Gui/ControlBuilderBase.cs +++ b/src/Bonsai.Gui/ControlBuilderBase.cs @@ -13,7 +13,7 @@ namespace Bonsai.Gui { /// - /// Provides an abstract base class with common UI control functionality. + /// Provides an abstract base class for common UI control functionality. /// public abstract class ControlBuilderBase : ZeroArgumentExpressionBuilder, INamedElement { diff --git a/src/Bonsai.Gui/GroupBoxBuilder.cs b/src/Bonsai.Gui/GroupBoxBuilder.cs new file mode 100644 index 0000000..54b4695 --- /dev/null +++ b/src/Bonsai.Gui/GroupBoxBuilder.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; + +namespace Bonsai.Gui +{ + /// + /// Represents an operator that specifies a mashup visualizer that displays a frame + /// around a group of other visualizers with an optional caption. + /// + [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 + { + } +} diff --git a/src/Bonsai.Gui/GroupBoxVisualizer.cs b/src/Bonsai.Gui/GroupBoxVisualizer.cs new file mode 100644 index 0000000..77c5c55 --- /dev/null +++ b/src/Bonsai.Gui/GroupBoxVisualizer.cs @@ -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))] + +namespace Bonsai.Gui +{ + /// + /// Provides a type visualizer that displays a frame around a group of other + /// visualizers with an optional caption. + /// + public class GroupBoxVisualizer : ContainerControlVisualizerBase + { + /// + protected override void AddControl(int index, Control control) + { + Control.Controls.Add(control); + } + + /// + 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; + } + } +} diff --git a/src/Bonsai.Gui/TabControlBuilder.cs b/src/Bonsai.Gui/TabControlBuilder.cs new file mode 100644 index 0000000..57d4600 --- /dev/null +++ b/src/Bonsai.Gui/TabControlBuilder.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; + +namespace Bonsai.Gui +{ + /// + /// Represents an operator that specifies a mashup visualizer that can be used + /// to arrange other visualizers using a related set of tab pages. + /// + [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 + { + } +} diff --git a/src/Bonsai.Gui/TabControlVisualizer.cs b/src/Bonsai.Gui/TabControlVisualizer.cs new file mode 100644 index 0000000..245659c --- /dev/null +++ b/src/Bonsai.Gui/TabControlVisualizer.cs @@ -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))] + +namespace Bonsai.Gui +{ + /// + /// Provides a type visualizer that can be used to arrange other visualizers + /// using a related set of tab pages. + /// + public class TabControlVisualizer : ContainerControlVisualizerBase + { + /// + protected override TabControl CreateControl(IServiceProvider provider, TabControlBuilder builder) + { + var tabControl = new TabControl(); + tabControl.Dock = DockStyle.Fill; + tabControl.Size = new Size(320, 240); + return tabControl; + } + + /// + protected override void AddControl(int index, Control control) + { + var tabPage = new TabPage(control.Name); + tabPage.Controls.Add(control); + Control.Controls.Add(tabPage); + } + } +} diff --git a/src/Bonsai.Gui/TextControlBuilderBase.cs b/src/Bonsai.Gui/TextControlBuilderBase.cs new file mode 100644 index 0000000..d589f3d --- /dev/null +++ b/src/Bonsai.Gui/TextControlBuilderBase.cs @@ -0,0 +1,25 @@ +using System.ComponentModel; +using System.Reactive.Subjects; + +namespace Bonsai.Gui +{ + /// + /// Provides an abstract base class for common UI text control functionality. + /// + [DefaultProperty(nameof(Text))] + public abstract class TextControlBuilderBase : ControlBuilderBase + { + internal readonly BehaviorSubject _Text = new(string.Empty); + + /// + /// Gets or sets the text associated with this control. + /// + [Category(nameof(CategoryAttribute.Appearance))] + [Description("The text associated with this control.")] + public string Text + { + get => _Text.Value; + set => _Text.OnNext(value); + } + } +}