private void InitializeGrid(Rect rect) { Console.WriteLine($"Size {rect.Size}"); if (rect.Size.Width <= 0) { Console.WriteLine($"ColumnDefinitions {ColumnDefinitions}"); Console.WriteLine($"RowDefinitions {RowDefinitions}"); return; } double twoColumnsTriggerWidth = 500; double aspectRatio = 0.5; if (rect.Size.Width < twoColumnsTriggerWidth) { var columnDefinitionsStr = "1*,1*"; var columnWidth = rect.Size.Width / 2; var itemHeight = columnWidth * aspectRatio; var rowDefinitionsStr = $"{ToString(itemHeight)},{ToString(itemHeight)}"; ColumnDefinitions = ColumnDefinitions.Parse(columnDefinitionsStr); RowDefinitions = RowDefinitions.Parse(rowDefinitionsStr); //var columnDefinitions = ColumnDefinitions.Parse(columnDefinitionsStr); //var rowDefinitions = RowDefinitions.Parse(rowDefinitionsStr); //SetColumnDefinitions(columnDefinitions); //SetRowDefinitions(rowDefinitions); //InvalidateMeasure(); Console.WriteLine($"ColumnDefinitions {columnDefinitionsStr}"); Console.WriteLine($"RowDefinitions {rowDefinitionsStr}"); } else { var columnDefinitionsStr = "1*,1*,1*"; var columnWidth = rect.Size.Width / 3; var itemHeight = columnWidth * aspectRatio; var rowDefinitionsStr = $"{ToString(itemHeight)},{ToString(itemHeight)}"; ColumnDefinitions = ColumnDefinitions.Parse(columnDefinitionsStr); RowDefinitions = RowDefinitions.Parse(rowDefinitionsStr); //var columnDefinitions = ColumnDefinitions.Parse(columnDefinitionsStr); //var rowDefinitions = RowDefinitions.Parse(rowDefinitionsStr); //SetColumnDefinitions(columnDefinitions); //SetRowDefinitions(rowDefinitions); //InvalidateMeasure(); Console.WriteLine($"ColumnDefinitions {columnDefinitionsStr}"); Console.WriteLine($"RowDefinitions {rowDefinitionsStr}"); } }
protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is PacketDocumentViewModel dc) { dc.ToObservable(o => o.ReasonPanelVisibility) .SubscribeAction(show => { var grid = this.FindControl <Grid>("RightPanel"); grid.RowDefinitions = RowDefinitions.Parse(show ? "*,5,100" : "*,0,0"); }); } }
void Update_LaunchpadModel() { Grid?.Children.Clear(); int buttons = Preferences.LaunchpadModel.GridSize(); IEnumerable <string> ones = Enumerable.Range(0, buttons).Select(i => "*"); IEnumerable <string> zeros = Enumerable.Range(0, 10 - buttons).Select(i => "0"); View.Child = Grid = new Grid() { RowDefinitions = RowDefinitions.Parse( String.Join( ",", ones.Concat(zeros).ToArray() ) ), ColumnDefinitions = ColumnDefinitions.Parse( String.Join( ",", zeros.Concat(ones).ToArray() ) ) }; for (int i = 0; i < 100; i++) { int mouse = Buttons[i].UpdateModel(); if (mouse < 0) { Buttons[i].PointerPressed -= MouseDown; } else if (mouse > 0) { Buttons[i].PointerPressed += MouseDown; } Grid.Children.Add(Buttons[i]); } ModeLight.IsVisible = Preferences.LaunchpadModel.HasModeLight(); Update_LaunchpadStyle(); }
public void ReloadGUI() { if (!Operation.CanExecute) { return; } _scriptConfigurationPanel.Children.Clear(); _scriptVariablesGrid.Children.Clear(); _scriptVariablesGrid.RowDefinitions.Clear(); TextBox tbScriptName = new() { IsReadOnly = true, Text = $"{Operation.ScriptGlobals.Script.Name} v{Operation.ScriptGlobals.Script.Version} by {Operation.ScriptGlobals.Script.Author}", UseFloatingWatermark = true, Watermark = "Script name, Version and Author" }; TextBox tbScriptDescription = new() { IsReadOnly = true, Text = Operation.ScriptGlobals.Script.Description, AcceptsReturn = true, UseFloatingWatermark = true, Watermark = "Script description" }; _scriptConfigurationPanel.Children.Add(tbScriptName); _scriptConfigurationPanel.Children.Add(tbScriptDescription); //Operation.ScriptGlobals.Script.UserInputs.Add(new ScriptBoolInput() { Label = "Hellow" }); //Operation.ScriptGlobals.Script.UserInputs.Add(new ScriptTextBoxInput() { Label = "Hellow", Value = "m,e", MultiLine = true}); if (Operation.ScriptGlobals.Script.UserInputs.Count == 0) { return; } string rowDefinitions = string.Empty; for (var i = 0; i < Operation.ScriptGlobals.Script.UserInputs.Count; i++) { if (i < Operation.ScriptGlobals.Script.UserInputs.Count - 1) { rowDefinitions += "Auto,10,"; } else { rowDefinitions += "Auto"; } } _scriptVariablesGrid.RowDefinitions = RowDefinitions.Parse(rowDefinitions); for (var i = 0; i < Operation.ScriptGlobals.Script.UserInputs.Count; i++) { var variable = Operation.ScriptGlobals.Script.UserInputs[i]; if (!string.IsNullOrWhiteSpace(variable.Label) && variable is not ScriptCheckBoxInput) { TextBlock tbLabel = new() { VerticalAlignment = VerticalAlignment.Center, Text = $"{variable.Label}:" }; if (!string.IsNullOrWhiteSpace(variable.ToolTip)) { ToolTip.SetTip(tbLabel, variable.ToolTip); } _scriptVariablesGrid.Children.Add(tbLabel); Grid.SetRow(tbLabel, i * 2); Grid.SetColumn(tbLabel, 0); } if (!string.IsNullOrWhiteSpace(variable.Unit)) { TextBlock control = new() { VerticalAlignment = VerticalAlignment.Center, Text = variable.Unit }; _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 4); } switch (variable) { case ScriptNumericalInput <sbyte> numSBYTE: { NumericUpDown control = new() { Minimum = numSBYTE.Minimum, Maximum = numSBYTE.Maximum, Value = numSBYTE.Value, Increment = numSBYTE.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numSBYTE.Value = (sbyte)value; control.Value = numSBYTE.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <byte> numBYTE: { NumericUpDown control = new() { Minimum = numBYTE.Minimum, Maximum = numBYTE.Maximum, Value = numBYTE.Value, Increment = numBYTE.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numBYTE.Value = (byte)value; control.Value = numBYTE.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <short> numSHORT: { NumericUpDown control = new() { Minimum = numSHORT.Minimum, Maximum = numSHORT.Maximum, Value = numSHORT.Value, Increment = numSHORT.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numSHORT.Value = (short)value; control.Value = numSHORT.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <ushort> numUSHORT: { NumericUpDown control = new() { Minimum = numUSHORT.Minimum, Maximum = numUSHORT.Maximum, Value = numUSHORT.Value, Increment = numUSHORT.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numUSHORT.Value = (ushort)value; control.Value = numUSHORT.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <int> numINT: { NumericUpDown control = new() { Minimum = numINT.Minimum, Maximum = numINT.Maximum, Value = numINT.Value, Increment = numINT.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numINT.Value = (int)value; control.Value = numINT.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <uint> numUINT: { NumericUpDown control = new() { Minimum = numUINT.Minimum, Maximum = numUINT.Maximum, Value = numUINT.Value, Increment = numUINT.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numUINT.Value = (uint)value; control.Value = numUINT.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <long> numLONG: { NumericUpDown control = new() { Minimum = numLONG.Minimum, Maximum = numLONG.Maximum, Value = numLONG.Value, Increment = numLONG.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numLONG.Value = (long)value; control.Value = numLONG.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <ulong> numULONG: { NumericUpDown control = new() { Minimum = numULONG.Minimum, Maximum = numULONG.Maximum, Value = numULONG.Value, Increment = numULONG.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numULONG.Value = (ulong)value; control.Value = numULONG.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <float> numFLOAT: { NumericUpDown control = new() { Minimum = numFLOAT.Minimum, Maximum = numFLOAT.Maximum, Value = numFLOAT.Value, Increment = numFLOAT.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numFLOAT.Value = (float)Math.Round(value, numFLOAT.DecimalPlates); control.Value = numFLOAT.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <double> numDOUBLE: { NumericUpDown control = new() { Minimum = numDOUBLE.Minimum, Maximum = numDOUBLE.Maximum, Value = numDOUBLE.Value, Increment = numDOUBLE.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numDOUBLE.Value = Math.Round(value, numDOUBLE.DecimalPlates); control.Value = numDOUBLE.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptNumericalInput <decimal> numDECIMAL: { NumericUpDown control = new() { Minimum = (double)numDECIMAL.Minimum, Maximum = (double)numDECIMAL.Maximum, Value = (double)numDECIMAL.Value, Increment = (double)numDECIMAL.Increment, MinWidth = 150 }; var valueProperty = control.GetObservable(NumericUpDown.ValueProperty); valueProperty.Subscribe(value => { numDECIMAL.Value = (decimal)Math.Round(value, numDECIMAL.DecimalPlates); control.Value = (double)numDECIMAL.Value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } case ScriptCheckBoxInput inputCheckBox: { CheckBox control = new() { Content = variable.Label, IsChecked = inputCheckBox.Value }; var valueProperty = control.GetObservable(CheckBox.IsCheckedProperty); valueProperty.Subscribe(value => { if (value != null) { inputCheckBox.Value = value.Value; } }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); if (!string.IsNullOrWhiteSpace(variable.ToolTip)) { ToolTip.SetTip(control, variable.ToolTip); } continue; } case ScriptTextBoxInput inputTextBox: { TextBox control = new() { AcceptsReturn = inputTextBox.MultiLine, Text = inputTextBox.Value, }; var valueProperty = control.GetObservable(TextBox.TextProperty); valueProperty.Subscribe(value => { inputTextBox.Value = value; }); _scriptVariablesGrid.Children.Add(control); Grid.SetRow(control, i * 2); Grid.SetColumn(control, 2); continue; } } } ParentWindow.FitToSize(); } } }