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 ColorPicker pop-up example #1720

Closed
tig opened this issue May 14, 2022 · 1 comment
Closed

Add ColorPicker pop-up example #1720

tig opened this issue May 14, 2022 · 1 comment

Comments

@tig
Copy link
Collaborator

tig commented May 14, 2022

Very related to

I already coded this up as part of my code review of ColorPicker (#1668). But I didn't add it because I built it on ProgressBar Styles and it really should be part of the Color Picker Scenario.

This code shows how to wrap Color Picker in a Dialog such that when you click on a color, the dialog closes and the ProgressBar colors change.

My suggestion is to add a ProgressBar to the Color Picker scenario and use this code (or an adaptation) to make it sing:

		#region ColorPicker
		ColorName ChooseColor (string text, ColorName colorName)
		{

			var colorPicker = new ColorPicker {
				Title = text,
				SelectedColor = colorName
			};

			var dialog = new Dialog {
				Title = text
			};

			dialog.LayoutComplete += (sender, args) => {
				// TODO: Replace with Dim.Auto
				dialog.X = pbList.Frame.X;
				dialog.Y = pbList.Frame.Height;

				// Once #3127 is merged:
				dialog.LayoutStyle = LayoutStyle.Absolute;
				dialog.Bounds = new Rect (0, 0, colorPicker.Frame.Width, colorPicker.Frame.Height);

				Application.Top.LayoutSubviews ();
			};

			dialog.Add (colorPicker);
			colorPicker.ColorChanged += (s, e) => {
				dialog.RequestStop ();
			};
			Application.Run (dialog);

			var retColor = colorPicker.SelectedColor;
			colorPicker.Dispose ();

			return retColor;
		}

		var fgColorPickerBtn = new Button {
			Text = "Foreground HotNormal Color",
			X = Pos.Center (),
			Y = Pos.Bottom (pbList),
		};
		editor.Add (fgColorPickerBtn);
		fgColorPickerBtn.Clicked += (s, e) => {
			var newColor = ChooseColor (fgColorPickerBtn.Text, editor.ViewToEdit.ColorScheme.HotNormal.Foreground.ColorName);
			var cs = new ColorScheme (editor.ViewToEdit.ColorScheme) {
				HotNormal = new Attribute (newColor, editor.ViewToEdit.ColorScheme.HotNormal.Background)
			};
			editor.ViewToEdit.ColorScheme = cs;
		};

		var bgColorPickerBtn = new Button {
			X = Pos.Center (),
			Y = Pos.Bottom (fgColorPickerBtn),
			Text = "Background HotNormal Color"
		};
		editor.Add (bgColorPickerBtn);
		bgColorPickerBtn.Clicked += (s, e) => {
			var newColor = ChooseColor (fgColorPickerBtn.Text, editor.ViewToEdit.ColorScheme.HotNormal.Background.ColorName);
			var cs = new ColorScheme (editor.ViewToEdit.ColorScheme) {
				HotNormal = new Attribute (editor.ViewToEdit.ColorScheme.HotNormal.Foreground, newColor)
			};
			editor.ViewToEdit.ColorScheme = cs;
		};

image

Tag @jocelynnatali

@jocelynnatali
Copy link
Contributor

Yes, it's a good idea :-). I'll update the scenario in the next days.

tig added a commit that referenced this issue Jan 13, 2024
…enario) (#3154)

* Removed resharper settings from editorconfig

* initial commit

* Lots of tweaks
@tig tig closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants