Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RatioEditorControl.cs « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a5c8fdc66d3968aeb35d86e9fdb57d599b26b5d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections;
using System.ComponentModel;
using AppKit;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Mac
{
	internal class RatioEditorControl<T> : PropertyEditorControl<RatioViewModel>
	{
		private RatioEditor<T> ratioEditor;

		public RatioEditorControl (IHostResourceProvider hostResources)
			: base (hostResources)
		{
			base.TranslatesAutoresizingMaskIntoConstraints = false;

			this.ratioEditor = new RatioEditor<T> (hostResources);
			this.ratioEditor.ProxyResponder = new ProxyResponder (this, ProxyRowType.SingleView);
			this.ratioEditor.SetFormatter (null);

			// update the value on keypress
			this.ratioEditor.ValueChanged += (sender, e) => {
				if (e is RatioEditor<T>.RatioEventArgs ratioEventArgs) {
					ViewModel.ValueChanged (this.ratioEditor.StringValue, ratioEventArgs.CaretPosition, ratioEventArgs.SelectionLength, ratioEventArgs.IncrementValue);
				}
			};
			AddSubview (this.ratioEditor);

			this.AddConstraints (new[] {
				NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this,  NSLayoutAttribute.CenterY, 1f, 0),
				NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this,  NSLayoutAttribute.Width, 1f, 0),
				NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6),
			});
		}

		public override NSView FirstKeyView => ratioEditor.NumericEditor;
		public override NSView LastKeyView => ratioEditor.DecrementButton;

		protected override void SetEnabled ()
		{
			this.ratioEditor.Enabled = ViewModel.Property.CanWrite;
		}

		protected override void UpdateAccessibilityValues ()
		{
			this.ratioEditor.AccessibilityEnabled = this.ratioEditor.Enabled;
			this.ratioEditor.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityNumeric, ViewModel.Property.Name);
		}

		protected override void UpdateValue ()
		{
			this.ratioEditor.StringValue = ViewModel.ValueString;
		}
	}
}