private Control ConstructBindingLayout() { var layout = new StackLayout() { Orientation = Orientation.Horizontal, Padding = new Padding(5), Spacing = 5 }; this.SettingsChanged += (settings) => { // Clear layout layout.Items.Clear(); // Tip Binding var tipBindingLayout = new StackLayout { Spacing = 5 }; var tipBindingControl = new BindingDisplay(Settings.TipButton); tipBindingControl.BindingUpdated += (s, binding) => Settings.TipButton = binding.ToString(); var tipBindingGroup = new GroupBox { Text = "Tip Binding", Padding = App.GroupBoxPadding, Content = tipBindingControl }; tipBindingLayout.Items.Add(new StackLayoutItem(tipBindingGroup, HorizontalAlignment.Stretch, true)); var tipPressureSlider = new Slider { MinValue = 0, MaxValue = 100 }; var tipPressureBox = new TextBox(); tipPressureSlider.ValueChanged += (sender, e) => { settings.TipActivationPressure = tipPressureSlider.Value; tipPressureBox.Text = Settings.TipActivationPressure.ToString(); tipPressureBox.CaretIndex = tipPressureBox.Text.Length; }; tipPressureBox.TextChanged += (sender, e) => { Settings.TipActivationPressure = float.TryParse(tipPressureBox.Text, out var val) ? val : 0f; tipPressureSlider.Value = (int)Settings.TipActivationPressure; }; tipPressureBox.Text = Settings.TipActivationPressure.ToString(); var tipPressureLayout = new StackLayout { Orientation = Orientation.Horizontal, Items = { new StackLayoutItem(tipPressureSlider, VerticalAlignment.Center, true), new StackLayoutItem(tipPressureBox, VerticalAlignment.Center, false) } }; var tipPressureGroup = new GroupBox { Text = "Tip Activation Pressure", Padding = App.GroupBoxPadding, Content = tipPressureLayout }; tipBindingLayout.Items.Add(new StackLayoutItem(tipPressureGroup, HorizontalAlignment.Stretch, true)); layout.Items.Add(new StackLayoutItem(tipBindingLayout, true)); // Pen Bindings var penBindingLayout = new StackLayout { Spacing = 5 }; for (int i = 0; i < Settings.PenButtons.Count; i++) { var penBindingControl = new BindingDisplay(Settings.PenButtons[i]) { Tag = i }; penBindingControl.BindingUpdated += (sender, binding) => { var index = (int)(sender as BindingDisplay).Tag; Settings.PenButtons[index] = binding.ToString(); }; var penBindingGroup = new GroupBox { Text = $"Pen Button {i + 1}", Padding = App.GroupBoxPadding, Content = penBindingControl }; penBindingLayout.Items.Add(new StackLayoutItem(penBindingGroup, HorizontalAlignment.Stretch, true)); } layout.Items.Add(new StackLayoutItem(penBindingLayout, true)); // Aux Bindings var auxBindingLayout = new StackLayout { Spacing = 5 }; for (int i = 0; i < Settings.AuxButtons.Count; i++) { var auxBindingControl = new BindingDisplay(Settings.AuxButtons[i]) { Tag = i }; auxBindingControl.BindingUpdated += (sender, binding) => { int index = (int)(sender as BindingDisplay).Tag; Settings.AuxButtons[index] = binding.ToString(); }; var auxBindingGroup = new GroupBox { Text = $"Express Key {i + 1}", Padding = App.GroupBoxPadding, Content = auxBindingControl }; auxBindingLayout.Items.Add(new StackLayoutItem(auxBindingGroup, HorizontalAlignment.Stretch, true)); } layout.Items.Add(new StackLayoutItem(auxBindingLayout, true)); }; return(layout); }
public PenBindingEditor() { this.Content = new Scrollable { Border = BorderType.None, Content = new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Stretch, Items = { new TableLayout { Rows = { new TableRow { Cells = { new Group { Text = "Tip Settings", Content = new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Stretch, Spacing = 5, Items = { new Group { Text = "Tip Binding", Orientation = Orientation.Horizontal, ExpandContent = false, Content = tipButton = new BindingDisplay() }, new Group { Text = "Tip Pressure", ToolTip = "The minimum threshold in order for the assigned binding to activate.", Orientation = Orientation.Horizontal, Content = tipPressure = new FloatSlider() } } } }, new Group { Text = "Eraser Settings", Content = new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Stretch, Spacing = 5, Items = { new Group { Text = "Eraser Binding", ExpandContent = false, Orientation = Orientation.Horizontal, Content = eraserButton = new BindingDisplay() }, new Group { Text = "Eraser Pressure", ToolTip = "The minimum threshold in order for the assigned binding to activate.", Orientation = Orientation.Horizontal, Content = eraserPressure = new FloatSlider() } } } } } } } }, new Group { Text = "Pen Buttons", Content = penButtons = new BindingDisplayList { Prefix = "Pen Binding" } } } } }; tipButton.StoreBinding.Bind(SettingsBinding.Child(c => c.TipButton)); eraserButton.StoreBinding.Bind(SettingsBinding.Child(c => c.EraserButton)); tipPressure.ValueBinding.Bind(SettingsBinding.Child(c => c.TipActivationPressure)); eraserPressure.ValueBinding.Bind(SettingsBinding.Child(c => c.EraserActivationPressure)); penButtons.ItemSourceBinding.Bind(SettingsBinding.Child(c => (IList <PluginSettingStore>)c.PenButtons)); }