-
Notifications
You must be signed in to change notification settings - Fork 3
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 #6 from bonsai-rx/feature-dev
Add common button controls
- Loading branch information
Showing
9 changed files
with
240 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,23 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reactive.Subjects; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Represents an operator that interfaces with a button control and generates | ||
/// a sequence of notifications whenever the button is clicked. | ||
/// </summary> | ||
[TypeVisualizer(typeof(ButtonVisualizer))] | ||
[Description("Interfaces with a button control and generates a sequence of notifications whenever the button is clicked.")] | ||
public class ButtonBuilder : ButtonBuilderBase<string> | ||
{ | ||
internal readonly Subject<string> _Click = new(); | ||
|
||
/// <inheritdoc/> | ||
protected override IObservable<string> Generate() | ||
{ | ||
return _Click; | ||
} | ||
} | ||
} |
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,26 @@ | ||
using System.ComponentModel; | ||
using System.Reactive.Subjects; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Provides an abstract base class with common button control functionality. | ||
/// </summary> | ||
/// <inheritdoc/> | ||
[DefaultProperty(nameof(Text))] | ||
public abstract class ButtonBuilderBase<TEvent> : ControlBuilderBase<TEvent> | ||
{ | ||
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); | ||
} | ||
} | ||
} |
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,26 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Provides a type visualizer representing a button control. | ||
/// </summary> | ||
public class ButtonVisualizer : ControlVisualizerBase<Button, ButtonBuilder> | ||
{ | ||
/// <inheritdoc/> | ||
protected override Button CreateControl(IServiceProvider provider, ButtonBuilder builder) | ||
{ | ||
var button = new Button(); | ||
button.Dock = DockStyle.Fill; | ||
button.Size = new Size(300, 150); | ||
button.SubscribeTo(builder._Text, value => button.Text = value); | ||
button.Click += (sender, e) => | ||
{ | ||
builder._Click.OnNext(button.Name); | ||
}; | ||
return button; | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reactive.Subjects; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Represents an operator that interfaces with a check box control and generates | ||
/// a sequence of notifications whenever the checked status changes. | ||
/// </summary> | ||
[TypeVisualizer(typeof(CheckBoxVisualizer))] | ||
[Description("Interfaces with a check box control and generates a sequence of notifications whenever the checked status changes.")] | ||
public class CheckBoxBuilder : ButtonBuilderBase<bool> | ||
{ | ||
internal readonly Subject<bool> _CheckedChanged = new(); | ||
|
||
/// <summary> | ||
/// Gets or sets a value specifying the initial state of the check box. | ||
/// </summary> | ||
[Category(nameof(CategoryAttribute.Appearance))] | ||
[Description("Specifies the initial state of the check box.")] | ||
public bool Checked { get; set; } | ||
|
||
/// <inheritdoc/> | ||
protected override IObservable<bool> Generate() | ||
{ | ||
return _CheckedChanged; | ||
} | ||
} | ||
} |
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,27 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Provides a type visualizer representing a check box control. | ||
/// </summary> | ||
public class CheckBoxVisualizer : ControlVisualizerBase<CheckBox, CheckBoxBuilder> | ||
{ | ||
/// <inheritdoc/> | ||
protected override CheckBox CreateControl(IServiceProvider provider, CheckBoxBuilder builder) | ||
{ | ||
var checkBox = new CheckBox(); | ||
checkBox.Dock = DockStyle.Fill; | ||
checkBox.Size = new Size(300, 75); | ||
checkBox.Checked = builder.Checked; | ||
checkBox.SubscribeTo(builder._Text, value => checkBox.Text = value); | ||
checkBox.CheckedChanged += (sender, e) => | ||
{ | ||
builder._CheckedChanged.OnNext(checkBox.Checked); | ||
}; | ||
return checkBox; | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reactive.Subjects; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Represents an operator that interfaces with a radio button control and generates | ||
/// a sequence of notifications whenever the checked status changes. | ||
/// </summary> | ||
[TypeVisualizer(typeof(RadioButtonVisualizer))] | ||
[Description("Interfaces with a radio button control and generates a sequence of notifications whenever the checked status changes.")] | ||
public class RadioButtonBuilder : ButtonBuilderBase<bool> | ||
{ | ||
internal readonly Subject<bool> _CheckedChanged = new(); | ||
|
||
/// <summary> | ||
/// Gets or sets a value specifying the initial state of the radio button. | ||
/// </summary> | ||
[Category(nameof(CategoryAttribute.Appearance))] | ||
[Description("Specifies the initial state of the radio button.")] | ||
public bool Checked { get; set; } | ||
|
||
/// <inheritdoc/> | ||
protected override IObservable<bool> Generate() | ||
{ | ||
return _CheckedChanged; | ||
} | ||
} | ||
} |
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,27 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Provides a type visualizer representing a radio button control. | ||
/// </summary> | ||
public class RadioButtonVisualizer : ControlVisualizerBase<RadioButton, RadioButtonBuilder> | ||
{ | ||
/// <inheritdoc/> | ||
protected override RadioButton CreateControl(IServiceProvider provider, RadioButtonBuilder builder) | ||
{ | ||
var radioButton = new RadioButton(); | ||
radioButton.Dock = DockStyle.Fill; | ||
radioButton.Size = new Size(300, 75); | ||
radioButton.Checked = builder.Checked; | ||
radioButton.SubscribeTo(builder._Text, value => radioButton.Text = value); | ||
radioButton.CheckedChanged += (sender, e) => | ||
{ | ||
builder._CheckedChanged.OnNext(radioButton.Checked); | ||
}; | ||
return radioButton; | ||
} | ||
} | ||
} |
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,23 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reactive.Subjects; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Represents an operator that interfaces with a toggle button control and generates | ||
/// a sequence of notifications whenever the toggle status changes. | ||
/// </summary> | ||
[TypeVisualizer(typeof(ToggleButtonVisualizer))] | ||
[Description("Interfaces with a toggle button control and generates a sequence of notifications whenever the toggle status changes.")] | ||
public class ToggleButtonBuilder : ButtonBuilderBase<bool> | ||
{ | ||
internal readonly Subject<bool> _CheckedChanged = new(); | ||
|
||
/// <inheritdoc/> | ||
protected override IObservable<bool> Generate() | ||
{ | ||
return _CheckedChanged; | ||
} | ||
} | ||
} |
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,28 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace Bonsai.Gui | ||
{ | ||
/// <summary> | ||
/// Provides a type visualizer representing a toggle button control. | ||
/// </summary> | ||
public class ToggleButtonVisualizer : ControlVisualizerBase<CheckBox, ToggleButtonBuilder> | ||
{ | ||
/// <inheritdoc/> | ||
protected override CheckBox CreateControl(IServiceProvider provider, ToggleButtonBuilder builder) | ||
{ | ||
var checkBox = new CheckBox(); | ||
checkBox.Dock = DockStyle.Fill; | ||
checkBox.Size = new Size(300, 150); | ||
checkBox.Appearance = Appearance.Button; | ||
checkBox.TextAlign = ContentAlignment.MiddleCenter; | ||
checkBox.SubscribeTo(builder._Text, value => checkBox.Text = value); | ||
checkBox.CheckedChanged += (sender, e) => | ||
{ | ||
builder._CheckedChanged.OnNext(checkBox.Checked); | ||
}; | ||
return checkBox; | ||
} | ||
} | ||
} |