Exemplo n.º 1
0
        private void LogForm_Load(object sender, EventArgs e)
        {
            guiPanel.FlowDirection = FlowDirection.TopDown;
            guiPanel.Controls.Clear();
            Func <ProgressObject, Control> progressTemplate = (ProgressObject po) => {
                var topLabel = new Label()
                {
                    Margin   = new Padding(0, 5, 0, 5),
                    Font     = new Font(Font.FontFamily, 12f, FontStyle.Bold),
                    Width    = guiPanel.Width - 30,
                    AutoSize = true
                };
                var botLabel = new Label()
                {
                    Width    = guiPanel.Width - 30,
                    AutoSize = true
                };
                var progBar = new ProgressBar()
                {
                    Margin   = new Padding(0, 5, 0, 0),
                    Width    = guiPanel.Width - 30,
                    AutoSize = true
                };

                po.TaskTitle.Binding = topLabel.Bind(x => x.Text).ToBinding(BindingMode.FromTarget);
                po.TaskText.Binding  = botLabel.Bind(x => x.Text).ToBinding(BindingMode.FromTarget);
                po.Total.Binding     = progBar.Bind(x => x.Maximum).ToBinding(BindingMode.FromTarget);
                po.Current.Binding   = progBar.Bind(x => x.Value).ToBinding(BindingMode.FromTarget);

                progBar.Maximum = po.Total.Value;
                progBar.Value   = po.Current.Value;
                var flowThing = new FlowLayoutPanel()
                {
                    FlowDirection = FlowDirection.TopDown,
                    Margin        = new Padding(10, 5, 10, 5),
                    Width         = guiPanel.Width - 30
                };
                flowThing.Controls.AddRange(new[] {
                    (Control)topLabel,
                    botLabel,
                    progBar
                });
                return(flowThing);
            };

            List.Binding =
                guiPanel.Controls
                .CastList().ProjectList(progressTemplate)
                .ToBindable()
                .WithDispatcher(act => Invoke(act))
                .ToBinding(BindingMode.FromTarget);
        }
        Control GetPatching()
        {
            var progressBar = new ProgressBar {
                MinValue = 0,
                MaxValue = 100,
            };

            progressBar.Bind(
                p => p.Value,
                Binding.Property(viewModel, vm => vm.PatchProgress)
                .Convert(v => (int)(v * 100)));

            return(new TableLayout {
                Padding = 10,
                Spacing = new Size(10, 10),
                Rows =
                {
                    new TableRow(L10n.Get("Patching...")),
                    new TableRow(progressBar),
                    new TableRow(new ImageView {
                        Image = Bitmap.FromResource(ResourcesName.PatchingBackground),
                    }),
                },
            });
        }
Exemplo n.º 3
0
        public void Should_Return_FallbackValue_When_Invalid_Source_Type()
        {
            var target = new ProgressBar();
            var source = new Source { Foo = "foo" };
            var binding = new Binding
            {
                Source = source,
                Path = "Foo",
                FallbackValue = 42,
            };

            target.Bind(ProgressBar.ValueProperty, binding);

            Assert.Equal(42, target.Value);
        }
Exemplo n.º 4
0
        public ProgressView()
        {
            AddToClassList(UssClassName);
            AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_LayoutPath).CloneTree(this);
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(k_StylePath));

            m_Label      = this.Q <Label>(className: LabelUssClassName);
            m_Label.text = string.Empty;

            m_ProgressScriptableObject = ScriptableObject.CreateInstance <ProgressScriptableObject>();
            var progressSerializedObject = new SerializedObject(m_ProgressScriptableObject);

            m_ProgressBar             = this.Q <ProgressBar>(className: ProgressBarUssClassName);
            m_ProgressBar.bindingPath = nameof(ProgressScriptableObject.percent);
            m_ProgressBar.Bind(progressSerializedObject);

            m_Button      = this.Q <Button>(className: ButtonUssClassName);
            m_Button.text = StringAssets.cancel;
        }
Exemplo n.º 5
0
        void CreateUIElements()
        {
            var titleRow = new VisualElement()
            {
                style =
                {
                    flexDirection  = FlexDirection.Row,
                    flexShrink     =                0f,
                    justifyContent = Justify.SpaceBetween
                }
            };

            m_VisualElementContainer.Add(new Label("VisualElements Container"));


            var curveX           = AnimationCurve.Linear(0, 0, 1, 0);
            var popupFieldValues = new List <SomeClass>
            {
                new SomeClass("First Class Value"),
                new SomeClass("Second Value"),
                new SomeClass("Another Value"),
                new SomeClass("Another Value with a very lonnnnnnnnnnnnnnnnnnnnnnnnng text to make sure this is really overflowing the popup field.")
            };
            var maskFieldOptions = new List <string>(m_MaskFieldOptions);


            m_VisualElementContainer.Add(m_IntegerField  = new IntegerField());
            m_VisualElementContainer.Add(m_LongField     = new LongField());
            m_VisualElementContainer.Add(m_FloatField    = new FloatField());
            m_VisualElementContainer.Add(m_DoubleField   = new DoubleField());
            m_VisualElementContainer.Add(m_EnumField     = new EnumField(EnumValues.Two));
            m_VisualElementContainer.Add(m_TextField     = new TextField());
            m_VisualElementContainer.Add(m_PasswordField = new TextField()
            {
                isPasswordField = true, maskChar = '*'
            });
            m_VisualElementContainer.Add(m_Vector3Field      = new Vector3Field());
            m_VisualElementContainer.Add(m_Vector3IntField   = new Vector3IntField());
            m_VisualElementContainer.Add(m_Vector2Field      = new Vector2Field());
            m_VisualElementContainer.Add(m_ColorField        = new ColorField());
            m_VisualElementContainer.Add(m_ObjectFieldCamera = new ObjectField()
            {
                objectType = typeof(Camera)
            });
            m_VisualElementContainer.Add(m_ObjectFieldGameObject = new ObjectField()
            {
                objectType = typeof(GameObject)
            });
            m_VisualElementContainer.Add(m_CurveField = new CurveField()
            {
                value = curveX
            });
            m_VisualElementContainer.Add(m_CurveFieldMesh = new CurveField()
            {
                value = curveX, renderMode = CurveField.RenderMode.Mesh
            });
            m_VisualElementContainer.Add(m_PopupField        = new PopupField <SomeClass>(popupFieldValues, popupFieldValues[1]));
            m_VisualElementContainer.Add(m_RectField         = new RectField());
            m_VisualElementContainer.Add(m_BoundsField       = new BoundsField());
            m_VisualElementContainer.Add(m_ToggleField       = new Toggle());
            m_VisualElementContainer.Add(m_MaskField         = new MaskField(maskFieldOptions, 6));
            m_VisualElementContainer.Add(m_LayerField        = new LayerField());
            m_VisualElementContainer.Add(m_TagField          = new TagField());
            m_VisualElementContainer.Add(m_MinMaxSliderField = new MinMaxSlider(5, 10, 0, 125));
            m_VisualElementContainer.Add(m_Slider            = new Slider(2, 8));
            m_VisualElementContainer.Add(m_SliderInt         = new SliderInt(11, 23));

            var buttonRow = new VisualElement()
            {
                style =
                {
                    flexDirection = FlexDirection.Row,
                    flexShrink    =                0f,
                }
            };

            buttonRow.Add(new Button()
            {
                text = k_ButtonLeftTitle, style = { flexGrow = 1 }
            });
            buttonRow.Add(new Button()
            {
                text = k_ButtonRightTitle, style = { flexGrow = 1 }
            });
            m_VisualElementContainer.Add(buttonRow);

            m_VisualElementContainer.Add(new Button()
            {
                text = k_ButtonTopTitle
            });
            m_VisualElementContainer.Add(new Button()
            {
                text = k_ButtonBottomTitle
            });

            m_VisualElementContainer.Add(m_ColorField1        = new ColorField());
            m_VisualElementContainer.Add(m_LayerMaskField     = new LayerMaskField(0));
            m_VisualElementContainer.Add(m_MultiLineTextField = new TextField()
            {
                multiline = true
            });

            m_VisualElementContainer.Add(m_SliderProgressBar = new SliderInt());
            m_VisualElementContainer.Add(m_ProgressBar       = new ProgressBar());

            m_ProgressBar.title           = nameof(ProgressBar);
            m_SliderProgressBar.lowValue  = 0;
            m_SliderProgressBar.highValue = 100;

            m_SliderProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue);
            m_ProgressBar.bindingPath       = nameof(SliderProgressTestObject.exampleValue);

            m_SliderProgressBar.Bind(SliderProgressTestSO);
            m_ProgressBar.Bind(SliderProgressTestSO);
            // The progress bar by itself does not contain any margin in IMGUI...
            // In this example, we are artifically adding the textfield margin to it. (see below, in the IMGUI section, ProgressBar())
            m_ProgressBar.style.marginBottom = 2f;

            m_VisualElementContainer.Add(m_GradientField = new GradientField());
            RefreshUIElements();
        }
Exemplo n.º 6
0
        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.
        }