mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Fix scenario duplication
This commit is contained in:
@@ -2,34 +2,11 @@
|
||||
using System;
|
||||
|
||||
namespace UICatalog.Scenarios {
|
||||
[ScenarioMetadata (Name: "Color Picker2", Description: "Color Picker.")]
|
||||
[ScenarioCategory ("Colors")]
|
||||
[ScenarioMetadata (Name: "Split Container", Description: "Demonstrates the SplitContainer functionality")]
|
||||
[ScenarioCategory ("Controls")]
|
||||
public class ColorPickers : Scenario {
|
||||
/// <summary>
|
||||
/// Foreground ColorPicker.
|
||||
/// </summary>
|
||||
private ColorPicker foregroundColorPicker;
|
||||
public class SplitContainerExample : Scenario {
|
||||
|
||||
/// <summary>
|
||||
/// Background ColorPicker.
|
||||
/// </summary>
|
||||
private ColorPicker backgroundColorPicker;
|
||||
|
||||
/// <summary>
|
||||
/// Foreground color label.
|
||||
/// </summary>
|
||||
private Label foregroundColorLabel;
|
||||
|
||||
/// <summary>
|
||||
/// Background color Label.
|
||||
/// </summary>
|
||||
private Label backgroundColorLabel;
|
||||
|
||||
/// <summary>
|
||||
/// Demo label.
|
||||
/// </summary>
|
||||
private Label demoLabel;
|
||||
private SplitContainer splitContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Setup the scenario.
|
||||
@@ -39,74 +16,17 @@ namespace UICatalog.Scenarios {
|
||||
// Scenario Window's.
|
||||
Win.Title = this.GetName ();
|
||||
|
||||
// Forground ColorPicker.
|
||||
foregroundColorPicker = new ColorPicker ("Foreground Color");
|
||||
foregroundColorPicker.X = 0;
|
||||
foregroundColorPicker.Y = 0;
|
||||
foregroundColorPicker.ColorChanged += ForegroundColor_ColorChanged;
|
||||
Win.Add (foregroundColorPicker);
|
||||
splitContainer = new SplitContainer {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
SplitterDistance = Pos.Percent(50),
|
||||
};
|
||||
|
||||
foregroundColorLabel = new Label ();
|
||||
foregroundColorLabel.X = Pos.Left (foregroundColorPicker);
|
||||
foregroundColorLabel.Y = Pos.Bottom (foregroundColorPicker) + 1;
|
||||
Win.Add (foregroundColorLabel);
|
||||
|
||||
// Background ColorPicker.
|
||||
backgroundColorPicker = new ColorPicker ();
|
||||
backgroundColorPicker.Text = "Background Color";
|
||||
backgroundColorPicker.X = Pos.AnchorEnd () - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker));
|
||||
backgroundColorPicker.Y = 0;
|
||||
backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged;
|
||||
Win.Add (backgroundColorPicker);
|
||||
splitContainer.Panel1.Add (new Label ("Hello"));
|
||||
splitContainer.Panel2.Add (new Label ("World"));
|
||||
|
||||
backgroundColorLabel = new Label ();
|
||||
backgroundColorLabel.X = Pos.AnchorEnd () - (Pos.Right (backgroundColorLabel) - Pos.Left (backgroundColorLabel));
|
||||
backgroundColorLabel.Y = Pos.Bottom (backgroundColorPicker) + 1;
|
||||
Win.Add (backgroundColorLabel);
|
||||
|
||||
// Demo Label.
|
||||
demoLabel = new Label ("Lorem Ipsum");
|
||||
demoLabel.X = Pos.Center ();
|
||||
demoLabel.Y = 1;
|
||||
Win.Add (demoLabel);
|
||||
|
||||
// Set default colors.
|
||||
backgroundColorPicker.SelectedColor = demoLabel.SuperView.ColorScheme.Normal.Background;
|
||||
foregroundColorPicker.SelectedColor = demoLabel.SuperView.ColorScheme.Normal.Foreground;
|
||||
Win.Add (splitContainer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fired when foreground color is changed.
|
||||
/// </summary>
|
||||
private void ForegroundColor_ColorChanged ()
|
||||
{
|
||||
UpdateColorLabel (foregroundColorLabel, foregroundColorPicker);
|
||||
UpdateDemoLabel ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fired when background color is changed.
|
||||
/// </summary>
|
||||
private void BackgroundColor_ColorChanged ()
|
||||
{
|
||||
UpdateColorLabel (backgroundColorLabel, backgroundColorPicker);
|
||||
UpdateDemoLabel ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a color label from his ColorPicker.
|
||||
/// </summary>
|
||||
private void UpdateColorLabel (Label label, ColorPicker colorPicker)
|
||||
{
|
||||
label.Clear ();
|
||||
label.Text = $"{colorPicker.SelectedColor} - {(int)colorPicker.SelectedColor}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Demo Label.
|
||||
/// </summary>
|
||||
private void UpdateDemoLabel () => demoLabel.ColorScheme = new ColorScheme () {
|
||||
Normal = new Terminal.Gui.Attribute (foregroundColorPicker.SelectedColor, backgroundColorPicker.SelectedColor)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user