public FloatSlider() { var slider = new Slider { MinValue = Minimum, MaxValue = Maximum }; var nb = new FloatNumberBox(); slider.Bind( s => s.Value, nb.ValueBinding ); nb.ValueBinding.Bind(this.ValueBinding); this.Content = new StackView { Orientation = Orientation.Horizontal, VerticalContentAlignment = VerticalAlignment.Center, Items = { new StackLayoutItem(slider, true), new StackLayoutItem(nb, false) } }; }
void SetArtistTool() { VisualElement root = rootVisualElement; root.Clear(); VisualTreeAsset ArtistToolVisualTree = Resources.Load <VisualTreeAsset>("ArtistTool"); ArtistToolVisualTree.CloneTree(root); root.styleSheets.Add(Resources.Load <StyleSheet>("ArtistTool")); SerializedObject Tso = new SerializedObject(TimeController); Slider timeSlider = root.Q <Slider>(name: "Time"); timeSlider.Bind(Tso); #region SkyColor VisualElement gradientVisualElement = root.Q <VisualElement>(name: "SkyGradient"); if (gradientVisualElement != null) { GradientField gradientField = gradientVisualElement.Q <GradientField>(); if (gradientField != null) { skyColorSetter = GameObject.Find("Light - Sky").GetComponent <MaterialColorSetter>(); SerializedObject serialized_MaterialSetter = new SerializedObject(skyColorSetter); gradientField.bindingPath = "gradient"; gradientField.Bind(serialized_MaterialSetter); gradientVisualElement.Q <Label>().text = "Sky Gradient"; } } #endregion #region Ruins GradientEditorSetter("RuinsGradient", "Ruins Gradient", RuinsColorSetter); #endregion #region Trees GradientEditorSetter("TreesGradient", "Trees Gradient", TreesColorSetter); #endregion #region Rim GradientEditorSetter("RimColor", "Rim Gradient", RimColorSetter); #endregion #region Lights #region SunLights SerializedObject serialized_SunSpot = new SerializedObject(SunSpot_Group); VisualElement sunLightVisualElement = root.Q <VisualElement>(name: "Sunlight"); if (sunLightVisualElement.Q <VisualElement>(name: "LightGradient") != null) { GradientField sunLightGradient = sunLightVisualElement.Q <VisualElement>(name: "LightGradient").Q <GradientField>(); FloatField sunLightIntensity = root.Q <FloatField>(name: "Intensity"); if (sunLightGradient != null) { sunLightGradient.bindingPath = "gradient"; sunLightGradient.Bind(serialized_SunSpot); sunLightGradient.label = "Gradient"; } sunLightIntensity.value = GetSpotLightIntensity(); sunLightIntensity.RegisterCallback <ChangeEvent <float> >(ChangeIntensitySpotLightsEvent); } #endregion #region GrassLight SerializedObject serialized_GrassLight_Group = new SerializedObject(GrassLight_Group); VisualElement grassLightVisualElement = root.Q <VisualElement>(name: "GrassLight"); if (grassLightVisualElement.Q <VisualElement>(name: "LightGradient") != null) { GradientField grassLightGradient = grassLightVisualElement.Q <VisualElement>(name: "LightGradient").Q <GradientField>(); FloatField grassLightIntensity = grassLightVisualElement.Q <FloatField>(name: "Intensity"); if (grassLightGradient != null) { grassLightGradient.bindingPath = "gradient"; grassLightGradient.Bind(serialized_GrassLight_Group); grassLightGradient.label = "Gradient"; } grassLightIntensity.value = GrassLight.intensity; SerializedObject serialized_GrassLight = new SerializedObject(GrassLight); grassLightIntensity.Bind(serialized_GrassLight); } #endregion #region cave Light SerializedObject serialized_CaveHoleLight = new SerializedObject(CaveHoleLight); VisualElement caveLightVisualElement = root.Q <VisualElement>(name: "CaveHoleLight"); caveLightVisualElement.Q <FloatField>(name: "Falloff").Bind(serialized_CaveHoleLight); Slider fallOffSlider = caveLightVisualElement.Q <Slider>(name: "FalloffIntencity"); FloatField fallOffField = fallOffSlider.Q <FloatField>(name: "CurrentValue"); fallOffSlider.Bind(serialized_CaveHoleLight); fallOffField.SetValueWithoutNotify(CaveHoleLight.falloffIntensity); fallOffField.RegisterCallback <ChangeEvent <float> >((evt) => fallOffSlider.value = evt.newValue); fallOffSlider.RegisterCallback <ChangeEvent <float> >((evt) => fallOffField.SetValueWithoutNotify(evt.newValue)); #endregion #region Visualisers var AllGradientElements = root.Query <GradientField>(); AllGradientElements.ForEach((element) => { //registerCallback for Gradient to apply changes on scene element.RegisterCallback <ChangeEvent <Gradient> >(ChangeGradientEvent); VisualElement visualiser = element.Q <VisualElement>(name: "VisualisationColor"); //Init color of visualisation cube float currentTime = TimeController.timeValue; visualiser.style.backgroundColor = element.value.Evaluate(currentTime); //register Callback for each visualisation cube when gradient Changes element.RegisterCallback <ChangeEvent <Gradient> >((evt) => { float timeOfChange = TimeController.timeValue; visualiser.style.backgroundColor = evt.newValue.Evaluate(currentTime); }); //register Callback for each visualisation cube when Time Changes timeSlider.RegisterCallback <ChangeEvent <float> >((evt) => { visualiser.style.backgroundColor = element.value.Evaluate(evt.newValue); }); }); #endregion #endregion #region Wind Shader // Set Initial Values VisualElement windComponent = root.Q <VisualElement>(name: "Wind"); if (windComponent != null) { Vector4Field windDirectionQuaternion = windComponent.Q <Vector4Field>(name: "WindDirection"); windDirectionQuaternion.value = GetWindDirection(); FloatField windScaleFloat = windComponent.Q <FloatField>(name: "WindScale"); windScaleFloat.value = GetWindScale(); MinMaxValue minMaxStrength = GetWindStrength(); VisualElement windStrengthHolder = windComponent.Q <VisualElement>(name: "WinStrengthHolder"); MinMaxSlider windStrengthSlider = windStrengthHolder.Q <MinMaxSlider>(name: "WindStrength"); windStrengthSlider.highLimit = minMaxStrength.HighLimit; windStrengthSlider.lowLimit = minMaxStrength.LowLimit; windStrengthSlider.value = new Vector2(minMaxStrength.minValue, minMaxStrength.maxValue); windStrengthHolder.Q <Label>(name: "MinValue").text = "Min Value :" + minMaxStrength.minValue; windStrengthHolder.Q <Label>(name: "MaxValue").text = "Max Value :" + minMaxStrength.maxValue; FloatField windSpeedFloat = windComponent.Q <FloatField>(name: "WindSpeed"); windSpeedFloat.value = GetWindSpeed(); //Set Callbacks values windDirectionQuaternion.RegisterCallback <ChangeEvent <Vector4> >(ChangeWindDirection); windScaleFloat.RegisterCallback <ChangeEvent <float> >(ChangeWindScale); windStrengthSlider.RegisterCallback <ChangeEvent <Vector2> >(ChangeWindStrength); windSpeedFloat.RegisterCallback <ChangeEvent <float> >(ChangeWindSpeed); } #endregion #region Postprocessing #region WhiteBalance //serialize White balance property SerializedObject serialized_whiteBalanceProperty = new SerializedObject(whiteBalanceProperty); //Get White balance Visual Element VisualElement whiteBalanceVisualElement = root.Q <VisualElement>(name: "WhiteBalance"); #region Temperature //Get White Balance temperature Visual Element VisualElement whiteBalanceTemperatureVE = whiteBalanceVisualElement.Q <VisualElement>(name: "Temperature"); //Get White Balance temperature Slider Slider whiteBalanceTemperatureSlider = whiteBalanceTemperatureVE.Q <Slider>(name: "SliderValue"); //Bind Slider to value whiteBalanceTemperatureSlider.bindingPath = "temperature.m_Value"; whiteBalanceTemperatureSlider.Bind(serialized_whiteBalanceProperty); //Get White Balance temperature Float Field FloatField whiteBalanceTemperatureFloat = whiteBalanceTemperatureVE.Q <FloatField>(name: "CurrentValue"); //Set default Temperature whiteBalanceTemperatureFloat.SetValueWithoutNotify(whiteBalanceProperty.temperature.value); //Register change callback for the float field to change the slider value. Changing slider value will change the values bound with it. whiteBalanceTemperatureFloat.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTemperatureSlider.value = evt.newValue); //Register change Callback for the slider, to change the float fiel Without notification (to avoid triggering Float field callback) whiteBalanceTemperatureSlider.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTemperatureFloat.SetValueWithoutNotify(evt.newValue)); #endregion #region Tint //Get White Balance Tint Visual Element VisualElement whiteBalanceTintVE = whiteBalanceVisualElement.Q <VisualElement>(name: "Tint"); //Get White Balance Tint Slider Slider whiteBalanceTintSlider = whiteBalanceTintVE.Q <Slider>(name: "SliderValue"); //Bind Slider to value whiteBalanceTintSlider.bindingPath = "tint.m_Value"; whiteBalanceTintSlider.Bind(serialized_whiteBalanceProperty); //Get White Balance Tint Float Field FloatField whiteBalanceTintFloat = whiteBalanceTintVE.Q <FloatField>(name: "CurrentValue"); //Set default Tint whiteBalanceTintFloat.SetValueWithoutNotify(whiteBalanceProperty.tint.value); //Register change callback for the float field to change the slider value. Changing slider value will change the values bound with it. whiteBalanceTintFloat.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTintSlider.value = evt.newValue); //Register change Callback for the slider, to change the float fiel Without notification (to avoid triggering Float field callback) whiteBalanceTintSlider.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTintFloat.SetValueWithoutNotify(evt.newValue)); #endregion #endregion #region Bloom //serialize bloom property SerializedObject serialized_BloomProperty = new SerializedObject(BloomProperty); //Get Bloom Visual Element VisualElement bloomVisualElement = root.Q <VisualElement>(name: "Bloom"); //Get Bloom Tint Color ColorField bloomTint = bloomVisualElement.Q <ColorField>(name: "Tint"); //Bind color to value bloomTint.bindingPath = "tint.m_Value"; bloomTint.Bind(serialized_BloomProperty); //Get Bloom Intensity FloatField bloomIntensity = bloomVisualElement.Q <FloatField>(name: "Intensity"); //Bind Intensity to value bloomIntensity.Bind(serialized_BloomProperty); #endregion #endregion #region VFX SerializedObject serialized_GlowParticleSystem = new SerializedObject(GlowParticleSystem); VisualElement VFXVisualElement = root.Q <VisualElement>(name: "VFX"); VFXVisualElement.Q <FloatField>(name: "Emission").bindingPath = "EmissionModule.rateOverTime.scalar"; VFXVisualElement.Q <FloatField>(name: "Emission").Bind(serialized_GlowParticleSystem); VFXVisualElement.Q <EnumField>(name: "RenderMode").Init(GlowParticleSystem.GetComponent <ParticleSystemRenderer>().renderMode); VFXVisualElement.Q <EnumField>(name: "RenderMode").RegisterCallback <ChangeEvent <string> >(ChangeRenderMode); VFXVisualElement.Q <ObjectField>(name: "Material").objectType = typeof(Material); VFXVisualElement.Q <ObjectField>(name: "Material").RegisterCallback <ChangeEvent <string> >(ChangeRenderMaterial); #endregion root.Q <Button>(name: "SaveButton").clicked += SaveButton; root.Q <Button>(name: "ResetButton").clicked += ResetToInitialSceneValues; }
public MyForm() { // Set ClientSize instead of Size, as each platform has different window border sizes ClientSize = new Size(600, 400); // Title to show in the title bar Title = "Menus and Toolbars"; // Create menu Menu = new MenuBar { Items = { new ButtonMenuItem { Text = "&File", Items = { // You can add commands or menu items new MyCommand(), // Another menu item, not based off a Command new ButtonMenuItem { Text = "Click Me, MenuItem" } } } }, // Quit item (goes in Application menu on OS X, File menu for others) QuitItem = new Command((sender, e) => Application.Instance.Quit()) { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }, // About command (goes in Application menu on OS X, Help menu for others) AboutItem = new Command((sender, e) => new Dialog { Content = new Label { Text = "About my app..." }, ClientSize = new Size(200, 200) }.ShowModal(this)) { MenuText = "About my app" } }; // Create toolbar ToolBar = new ToolBar { Items = { new MyCommand(), new SeparatorToolItem(), new ButtonToolItem { Text = "Click Me, ToolItem" } } }; // ViewModel var model = new ViewModel { String = "Hello!", Check = false, BackgroundColor = this.BackgroundColor }; // TextBox var textBox = new TextBox(); textBox.TextBinding.Bind(model, m => m.String); textBox.Bind(c => c.BackgroundColor, model, (ViewModel m) => m.BackgroundColor); // CheckBox var check = new CheckBox(); check.CheckedBinding.Bind(model, m => m.Check); // Slider var slider = new Slider { TickFrequency = 10 }; slider.Bind(c => c.Value, model, (ViewModel m) => m.Value); // ProgressBar var progressBar = new ProgressBar(); progressBar.Bind(c => c.Value, model, (ViewModel m) => m.Value); // Binding model and form background this.Bind(c => c.BackgroundColor, model, (ViewModel m) => m.BackgroundColor); // Button with event var button = new ColorButton(); button.Click += model.OnClicked; // The main layout mechanism for Eto.Forms is a TableLayout. // This is recommended to allow controls to keep their natural platform-specific size. // You can layout your controls declaratively using rows and columns as below, or add to the TableLayout.Rows and TableRow.Cell directly. Content = new TableLayout { Spacing = new Size(5, 5), // Space between each cell Padding = new Padding(10, 10, 10, 10), // Space around the table's sides Rows = { new TableRow( new TableCell(new Label { Text = "First Column" }, true), new TableCell(new Label { Text = "Second Column" }, true), new Label { Text = "Third Column" } ), new TableRow( new TextBox { Text = "Some Text", BackgroundColor = Color.Parse("Green"), TextColor = Color.Parse("Red") }, // Changed color of text and bg new DropDown { Items = { "Item 1","Item 2", "Item 3" } }, //new CheckBox { Text = "A checkbox" } new CheckBox { Text = "A checkbox", Checked = true } ), new TableRow( textBox, check ), new TableRow( slider, progressBar, button ), // By default, the last row & column will get scaled. This adds a row at the end to take the extra space of the form. // Otherwise, the above row will get scaled and stretch the TextBox/ComboBox/CheckBox to fill the remaining height. null //new TableRow { ScaleHeight = true } } }; // Set data context so it propegates to all child controls /* * var model = new ViewModel { String = "Hello!", Check = false, BackgroundColor = this.BackgroundColor }; * DataContext = model; */ // This creates the following layout: // -------------------------------- // |First |Second |Third | // -------------------------------- // |<TextBox> |<ComboBox>|<CheckBox>| // -------------------------------- // | | | | // | | | | // -------------------------------- // // Some notes: // 1. When scaling the width of a cell, it applies to all cells in the same column. // 2. When scaling the height of a row, it applies to the entire row. // 3. Scaling a row/column makes it share all remaining space with other scaled rows/columns. // 4. If a row/column is not scaled, it will be the size of the largest control in that row/column. // 5. A Control can be implicitly converted to a TableCell or TableRow to make the layout more concise. }
private TabPage BuildControlsTab() { SldSensitivity.Bind(s => s.Value, Settings.Local, l => l.MouseSensitivity); TxtSensitivity.Bind <int>("Text", SldSensitivity, "Value"); SldMovementSpeed.Bind(s => s.Value, Settings.Roaming, r => r.MovementSpeed); TxtMovementSpeed.Bind <int>("Text", SldMovementSpeed, "Value"); var tblAxes = new TableLayout(1, 2) { Spacing = MasterSpacing / 2 }; tblAxes.Add(CbxInvertX, 0, 0); tblAxes.Add(CbxInvertY, 0, 1); var stkAxes = new StackLayout { Orientation = Orientation.Horizontal, VerticalContentAlignment = VerticalAlignment.Center, Spacing = MasterPadding, Items = { new Label { Text = "Axes" }, tblAxes } }; var tblSensitivity = new TableLayout(3, 1) { Spacing = MasterSpacing }; tblSensitivity.Add(new Label { Text = "Sensitivity" }, 0, 0); tblSensitivity.Add(SldSensitivity, 1, 0); tblSensitivity.Add(TxtSensitivity, 2, 0); tblSensitivity.SetColumnScale(0, false); tblSensitivity.SetColumnScale(1, true); tblSensitivity.SetColumnScale(2, false); var tblMouse = new TableLayout(1, 2) { Spacing = MasterSpacing }; tblMouse.Add(stkAxes, 0, 0); tblMouse.Add(tblSensitivity, 0, 1); tblMouse.SetRowScale(0, true); tblMouse.SetRowScale(1, true); tblMouse.SetColumnScale(0, true); var gbxMouse = new GroupBox { Text = "Mouse", Content = tblMouse, Padding = MasterPadding }; var tblMovementSpeed = new TableLayout(3, 3) { Spacing = MasterSpacing }; tblMovementSpeed.Add(new Label { Text = "Movement speed" }, 0, 1); tblMovementSpeed.Add(SldMovementSpeed, 1, 1); tblMovementSpeed.Add(TxtMovementSpeed, 2, 1); tblMovementSpeed.SetColumnScale(0, false); tblMovementSpeed.SetColumnScale(1, true); tblMovementSpeed.SetColumnScale(2, false); tblMovementSpeed.SetRowScale(0, true); tblMovementSpeed.SetRowScale(1, false); tblMovementSpeed.SetRowScale(2, true); var gbxKeyboard = new GroupBox { Text = "Keyboard", Content = tblMovementSpeed, Padding = MasterPadding }; var tblGroups = new TableLayout(1, 2); tblGroups.Add(gbxMouse, 0, 0); tblGroups.Add(gbxKeyboard, 0, 1); tblGroups.SetRowScale(0, true); tblGroups.SetRowScale(1, true); return(new TabPage { Padding = MasterPadding, Text = "Controls", Content = tblGroups }); }