Created
January 18, 2017 18:40
-
-
Save cwensley/9bed58a4f6f440e0a878e0b3542d322c to your computer and use it in GitHub Desktop.
Example showing how to create a collapsible panel in Eto using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Eto.Forms; | |
using Eto.Drawing; | |
namespace MyCollapserForm | |
{ | |
public class MainForm : Dialog<bool> | |
{ | |
class L : Label | |
{ | |
public L(string text) | |
{ | |
VerticalAlignment = VerticalAlignment.Center; | |
TextAlignment = TextAlignment.Right; | |
Text = text; | |
} | |
} | |
public MainForm() | |
{ | |
Title = "My Collapsible Eto Form"; | |
Resizable = false; | |
Padding = new Padding(5); | |
var collapsePanel = new DynamicLayout { Visible = false, Padding = new Padding(40, 10), DefaultSpacing = new Size(5,5) }; | |
// set content of the collapsed section | |
collapsePanel.BeginVertical(); | |
collapsePanel.AddRow(null, new L("Density:"), new NumericUpDown()); | |
collapsePanel.AddRow(null, new L("Maximum angle:"), new NumericUpDown()); | |
collapsePanel.AddRow(null, new L("Maximum aspect ratio:"), new NumericUpDown()); | |
collapsePanel.AddRow(null, new L("Minimum edge length:"), new NumericUpDown()); | |
collapsePanel.AddRow(null, new L("Maximum edge length:"), new NumericUpDown()); | |
collapsePanel.AddRow(null, new L("Maximum distance, edge to surface:"), new NumericUpDown()); | |
collapsePanel.AddRow(null, new L("Minimum initial grid quads:"), new NumericUpDown()); | |
collapsePanel.EndVertical(); | |
collapsePanel.BeginVertical(); | |
collapsePanel.AddRow(null, new CheckBox { Text = "Refine mesh" }); | |
collapsePanel.AddRow(null, new CheckBox { Text = "Jagged seams" }, new CheckBox { Text = "Pack textures" }, null); | |
collapsePanel.AddRow(null, new CheckBox { Text = "Simple planes" }); | |
collapsePanel.EndVertical(); | |
// button to toggle collapsing | |
var collapseButton = new Button { Text = "v", MinimumSize = Size.Empty }; | |
collapseButton.Click += (sender, e) => | |
{ | |
collapsePanel.Visible = !collapsePanel.Visible; | |
collapseButton.Text = collapsePanel.Visible ? "^" : "v"; | |
// adjust form size | |
if (collapsePanel.Visible) | |
ClientSize = new Size(Math.Max(ClientSize.Width, collapsePanel.Width), ClientSize.Height + collapsePanel.Height); | |
else | |
ClientSize = new Size(ClientSize.Width, ClientSize.Height - collapsePanel.Height); | |
}; | |
// a few buttons always shown at the bottom | |
var previewButton = new Button { Text = "Preview" }; | |
var cancelButton = new Button { Text = "Cancel" }; | |
cancelButton.Click += (sender, e) => Close(false); | |
var okButton = new Button { Text = "OK" }; | |
okButton.Click += (sender, e) => Close(true); | |
DefaultButton = okButton; | |
AbortButton = cancelButton; | |
var toleranceUpDown = new NumericUpDown(); | |
// our main layout | |
var layout = new DynamicLayout(); | |
layout.AddSeparateRow(null, new L("Tolerance"), toleranceUpDown, new L("millimeters"), collapseButton); | |
layout.AddCentered(collapsePanel); // we need this auto-sized so we can get its width to adjust form height | |
layout.Add(null); // expanding space, in case you want the form re-sizable | |
layout.AddSeparateRow(null, previewButton, cancelButton, okButton); | |
Content = layout; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment