-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from bonsai-rx/feature-dev
Add label and text box controls
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |