using Terminal.Gui; using System; namespace UICatalog.Scenarios { [ScenarioMetadata (Name: "Color Picker", Description: "Color Picker.")] [ScenarioCategory ("Colors")] [ScenarioCategory ("Controls")] public class ColorPickers : Scenario { /// /// Foreground ColorPicker. /// private ColorPicker foregroundColorPicker; /// /// Background ColorPicker. /// private ColorPicker backgroundColorPicker; /// /// Foreground color label. /// private Label foregroundColorLabel; /// /// Background color Label. /// private Label backgroundColorLabel; /// /// Demo label. /// private Label demoLabel; /// /// Setup the scenario. /// public override void Setup () { // Scenario Window's. Win.Title = this.GetName (); // Foreground ColorPicker. foregroundColorPicker = new ColorPicker ("Foreground Color"); foregroundColorPicker.ColorChanged += ForegroundColor_ColorChanged; Win.Add (foregroundColorPicker); foregroundColorLabel = new Label { X = Pos.Left (foregroundColorPicker), Y = Pos.Bottom (foregroundColorPicker) + 1 }; Win.Add (foregroundColorLabel); // Background ColorPicker. backgroundColorPicker = new ColorPicker ("Background Color"); backgroundColorPicker.X = Pos.AnchorEnd () - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker)); backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged; Win.Add (backgroundColorPicker); 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; } /// /// Fired when foreground color is changed. /// private void ForegroundColor_ColorChanged (object sender, EventArgs e) { UpdateColorLabel (foregroundColorLabel, foregroundColorPicker); UpdateDemoLabel (); } /// /// Fired when background color is changed. /// private void BackgroundColor_ColorChanged (object sender, EventArgs e) { UpdateColorLabel (backgroundColorLabel, backgroundColorPicker); UpdateDemoLabel (); } /// /// Update a color label from his ColorPicker. /// private void UpdateColorLabel (Label label, ColorPicker colorPicker) { label.Clear (); label.Text = $"{colorPicker.SelectedColor} - {(int)colorPicker.SelectedColor}"; } /// /// Update Demo Label. /// private void UpdateDemoLabel () => demoLabel.ColorScheme = new ColorScheme () { Normal = new Terminal.Gui.Attribute (foregroundColorPicker.SelectedColor, backgroundColorPicker.SelectedColor) }; } }