Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label and text box controls #9

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Bonsai.Gui/LabelBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel;

namespace Bonsai.Gui
{
/// <summary>
/// Represents an operator that interfaces with a label control.
/// </summary>
[TypeVisualizer(typeof(LabelVisualizer))]
[Description("Interfaces with a label control.")]
public class LabelBuilder : TextControlBuilderBase
{
}
}
21 changes: 21 additions & 0 deletions src/Bonsai.Gui/LabelVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Bonsai.Gui
{
/// <summary>
/// Provides a type visualizer representing a label control.
/// </summary>
public class LabelVisualizer : ControlVisualizerBase<Label, LabelBuilder>
{
/// <inheritdoc/>
protected override Label CreateControl(IServiceProvider provider, LabelBuilder builder)
{
var label = new Label();
label.Dock = DockStyle.Fill;
label.Size = new Size(300, label.Height);
return label;
}
}
}
39 changes: 39 additions & 0 deletions src/Bonsai.Gui/TextBoxBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.ComponentModel;
using System.Reactive.Subjects;

namespace Bonsai.Gui
{
/// <summary>
/// Represents an operator that interfaces with a text box control and generates
/// a sequence of notifications whenever the text changes.
/// </summary>
[TypeVisualizer(typeof(TextBoxVisualizer))]
public class TextBoxBuilder : TextControlBuilderBase<string>
{
internal readonly BehaviorSubject<bool> _Multiline = new(true);

/// <summary>
/// Gets or sets a value specifying whether the text box is multiline.
/// </summary>
[Description("Specifies whether the text box is multiline.")]
public bool Multiline
{
get => _Multiline.Value;
set => _Multiline.OnNext(value);
}

/// <summary>
/// Generates an observable sequence of values containing the contents
/// of the text box whenever the text changes.
/// </summary>
/// <returns>
/// A sequence of <see cref="string"/> values representing the contents
/// of the text box.
/// </returns>
protected override IObservable<string> Generate()
{
return _Text;
}
}
}
32 changes: 32 additions & 0 deletions src/Bonsai.Gui/TextBoxVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Bonsai.Gui
{
/// <summary>
/// Provides a type visualizer representing a text box control.
/// </summary>
public class TextBoxVisualizer : ControlVisualizerBase<TextBox, TextBoxBuilder>
{
/// <inheritdoc/>
protected override TextBox CreateControl(IServiceProvider provider, TextBoxBuilder builder)
{
var textBox = new TextBox();
textBox.Dock = DockStyle.Fill;
textBox.Multiline = builder._Multiline.Value;
if (textBox.Multiline)
{
textBox.Size = new Size(320, 240);
}

textBox.Text = builder._Text.Value;
textBox.SubscribeTo(builder._Multiline, value => textBox.Multiline = value);
textBox.TextChanged += (sender, e) =>
{
builder._Text.OnNext(textBox.Text);
};
return textBox;
}
}
}
Loading