Skip to content

Commit

Permalink
Added ctor params and also tried to fix the demos.
Browse files Browse the repository at this point in the history
  • Loading branch information
simplexidev committed Aug 21, 2018
1 parent f7fc798 commit 4712a3c
Show file tree
Hide file tree
Showing 34 changed files with 308 additions and 169 deletions.
2 changes: 1 addition & 1 deletion demos/ControlGallery/ControlGallery.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions demos/ControlGallery/MainWindow.cs
Expand Up @@ -6,9 +6,9 @@ namespace ControlGallery
public class MainWindow : Window
{
private TabContainer tabControl = new TabContainer();
private readonly BasicControlsTab basicControlsTab = new BasicControlsTab();
private readonly NumbersTab numbersTab = new NumbersTab();
private readonly DataChoosersTab dataChoosersTab = new DataChoosersTab();
private BasicControlsTab controlsTab = new BasicControlsTab();
private NumbersTab numbersTab = new NumbersTab();
private DataChoosersTab dataTab = new DataChoosersTab();

public MainWindow() : base("LibUISharp Control Gallery", new Size(640, 480), true) => InitializeComponent();

Expand All @@ -17,9 +17,9 @@ protected override void InitializeComponent()
IsMargined = true;
Child = tabControl;

tabControl.Children.Add(basicControlsTab);
tabControl.Children.Add(controlsTab);
tabControl.Children.Add(numbersTab);
tabControl.Children.Add(dataChoosersTab);
tabControl.Children.Add(dataTab);
}
}
}
7 changes: 4 additions & 3 deletions demos/ControlGallery/Program.cs
@@ -1,20 +1,21 @@
using System;
using LibUISharp;

namespace ControlGallery
{
internal class Program
{
// This MUST be static, or dotnet itself will crash.
private static Menu menu;
private static Menu menu = new Menu("Demo");

[STAThread]
private static void Main()
{
// Initialize application.
Application app = new Application();

// Create the menu and add it's items.
menu = new Menu("Demo");
menu.Children.Add("MenuItem 1", action => Window.ShowMessageBox(null, "TestMessage", null, false));
menu.Children.Add("MenuItem 1"/*, action => Window.ShowMessageBox(null, "TestMessage", null, false)*/);
menu.Children.AddCheckable("CheckableMenuItem 1");
menu.Children.AddSeparator();
menu.Children.AddPreferences();
Expand Down
43 changes: 18 additions & 25 deletions demos/ControlGallery/TabPages.cs
Expand Up @@ -4,25 +4,24 @@ namespace ControlGallery
{
public sealed class BasicControlsTab : TabPage
{
private StackContainer vPanel = new StackContainer(Orientation.Vertical) { IsPadded = true };
private StackContainer hPanel = new StackContainer(Orientation.Horizontal) { IsPadded = true };
private StackContainer vPanel = new StackContainer(Orientation.Vertical, true);
private StackContainer hPanel = new StackContainer(Orientation.Horizontal, true);
private Button button = new Button("Button");
private CheckBox checkBox = new CheckBox("CheckBox");
private CheckBox checkBox = new CheckBox("CheckBox", true);
private Label label = new Label("This is a Label. Right now, labels can only span one line.");
private Separator hSeparator = new Separator(Orientation.Horizontal);
private GroupContainer groupContainer = new GroupContainer("Entries") { IsMargined = true };
private FormContainer form = new FormContainer { IsPadded = true };
private GroupContainer groupContainer = new GroupContainer("Entries", true);
private FormContainer form = new FormContainer(true);
private TextBox textBox = new TextBox();
private PasswordBox passwordBox = new PasswordBox();
private SearchBox searchBox = new SearchBox();
private TextBlock textBlock = new TextBlock();
private TextBlock noWordWrapTextBlock = new TextBlock(false);
private TextBlock noWordWrapTextBlock = new TextBlock(null, false);

public BasicControlsTab() : base("Basic Controls") => InitializeComponent();
public BasicControlsTab() : base("Basic Controls", true) => InitializeComponent();

protected override void InitializeComponent()
{
IsMargined = true;
Child = vPanel;

vPanel.Children.Add(hPanel);
Expand All @@ -42,24 +41,23 @@ protected override void InitializeComponent()

public sealed class NumbersTab : TabPage
{
private StackContainer hPanel = new StackContainer(Orientation.Horizontal) { IsPadded = true };
private GroupContainer groupContainer = new GroupContainer("Numbers") { IsMargined = true };
private StackContainer vPanel = new StackContainer(Orientation.Vertical) { IsPadded = true };
private StackContainer hPanel = new StackContainer(Orientation.Horizontal, true);
private GroupContainer groupContainer = new GroupContainer("Numbers", true);
private StackContainer vPanel = new StackContainer(Orientation.Vertical, true);
private SpinBox spinBox = new SpinBox(0, 100);
private Slider slider = new Slider(0, 100);
private ProgressBar progressBar = new ProgressBar();
private ProgressBar iProgressBar = new ProgressBar() { Value = -1 };
private GroupContainer groupBox2 = new GroupContainer("Lists") { IsMargined = true };
private StackContainer vPanel2 = new StackContainer(Orientation.Vertical) { IsPadded = true };
private ComboBox comboBox = new ComboBox();
private EditableComboBox editableComboBox = new EditableComboBox();
private RadioButtonList radioButtonList = new RadioButtonList();
private ProgressBar iProgressBar = new ProgressBar(-1);
private GroupContainer groupBox2 = new GroupContainer("Lists", true);
private StackContainer vPanel2 = new StackContainer(Orientation.Vertical, true);
private ComboBox comboBox = new ComboBox(new[] { "ComboBoxItem1", "ComboBoxItem2", "ComboBoxItem3" });
private EditableComboBox editableComboBox = new EditableComboBox(new[] { "EditableItem1", "EditableItem2", "EditableItem3" });
private RadioButtonList radioButtonList = new RadioButtonList(new[] {"RadioButton1", "RadioButton2", "RadioButton3"});

public NumbersTab() : base("Numbers and Lists") => InitializeComponent();
public NumbersTab() : base("Numbers and Lists", true) => InitializeComponent();

protected override void InitializeComponent()
{
IsMargined = true;
Child = hPanel;

hPanel.Children.Add(groupContainer, true);
Expand Down Expand Up @@ -88,10 +86,6 @@ protected override void InitializeComponent()

groupBox2.Child = vPanel2;

comboBox.Add("Combobox Item 1", "Combobox Item 2", "Combobox Item 3");
editableComboBox.Add("Editable Item 1", "Editable Item 2", "Editable Item 3");
radioButtonList.Add("Radio Button 1", "Radio Button 2", "Radio Button 3");

vPanel2.Children.Add(comboBox);
vPanel2.Children.Add(editableComboBox);
vPanel2.Children.Add(radioButtonList);
Expand Down Expand Up @@ -120,11 +114,10 @@ public sealed class DataChoosersTab : TabPage
private Button buttonMessage = new Button("Message Box");
private Button buttonMessageErr = new Button("Message Box (Error)");

public DataChoosersTab() : base("Data Choosers") => InitializeComponent();
public DataChoosersTab() : base("Data Choosers", true) => InitializeComponent();

protected override void InitializeComponent()
{
IsMargined = true;
Child = hPanel;

hPanel.Children.Add(vPanel);
Expand Down
2 changes: 1 addition & 1 deletion demos/Histogram/Histogram.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions demos/Histogram/HistogramWindow.cs
Expand Up @@ -30,14 +30,14 @@ protected override void InitializeComponent()
spinBoxList.Add(spinBox);
}

colorPicker.ColorChanged += (sender, args) => { histogramSurface.QueueRedrawAll(); };
colorPicker.ColorChanged += () => { histogramSurface.QueueRedrawAll(); };

vPanel.Children.Add(colorPicker);

histogramSurface = new Surface(new SurfaceHandler(colorPicker, spinBoxList));
histogramSurface = new Surface(new HistogramSurfaceHandler(colorPicker, spinBoxList));
hPanel.Children.Add(histogramSurface, true);
}

private void SpinBoxOnValueChanged(object sender, EventArgs eventArgs) => histogramSurface.QueueRedrawAll();
private void SpinBoxOnValueChanged() => histogramSurface.QueueRedrawAll();
}
}
4 changes: 2 additions & 2 deletions demos/Histogram/SurfaceHandler.cs
Expand Up @@ -4,7 +4,7 @@

namespace Histogram
{
public class SurfaceHandler : SurfaceEventHandler
public class HistogramSurfaceHandler : SurfaceHandler
{
private const int pointRadius = 5;
private const int xoffLeft = 20;
Expand All @@ -26,7 +26,7 @@ public class SurfaceHandler : SurfaceEventHandler

private int _currentPoint = -1;

public SurfaceHandler(ColorPicker colorPicker, List<SpinBox> spinBoxes)
public HistogramSurfaceHandler(ColorPicker colorPicker, List<SpinBox> spinBoxes)
{
this.colorPicker = colorPicker;
spinBoxList = spinBoxes;
Expand Down
2 changes: 2 additions & 0 deletions source/LibUISharp/src/LibUISharp/Application.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using LibUISharp.Internal;
using LibUISharp.SafeHandles;

namespace LibUISharp
{
Expand Down Expand Up @@ -51,6 +52,7 @@ public Application()
/// <returns>0 if successful, else returns -1.</returns>
public int Run(Window window)
{
if (window.IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(window);
MainWindow = window;
return Run(() => { window.Show(); });
}
Expand Down
17 changes: 11 additions & 6 deletions source/LibUISharp/src/LibUISharp/Button.cs
@@ -1,5 +1,6 @@
using System;
using LibUISharp.Internal;
using LibUISharp.SafeHandles;

namespace LibUISharp
{
Expand Down Expand Up @@ -34,16 +35,16 @@ public string Text
{
get
{
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
text = NativeCalls.ButtonText(Handle);
return text;
}
set
{
if (text != value)
{
NativeCalls.ButtonSetText(Handle, value);
text = value;
}
if (text == value) return;
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
NativeCalls.ButtonSetText(Handle, value);
text = value;
}
}

Expand All @@ -55,6 +56,10 @@ public string Text
/// <summary>
/// Initializes this UI component's events.
/// </summary>
protected sealed override void InitializeEvents() => NativeCalls.ButtonOnClicked(Handle, (button, data) => { OnClick(); }, IntPtr.Zero);
protected sealed override void InitializeEvents()
{
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
NativeCalls.ButtonOnClicked(Handle, (button, data) => { OnClick(); }, IntPtr.Zero);
}
}
}
35 changes: 21 additions & 14 deletions source/LibUISharp/src/LibUISharp/CheckBox.cs
@@ -1,5 +1,6 @@
using System;
using LibUISharp.Internal;
using LibUISharp.SafeHandles;

namespace LibUISharp
{
Expand All @@ -10,16 +11,18 @@ namespace LibUISharp
public class CheckBox : Control
{
private string text;
private bool @checked;
private bool @checked = false;

/// <summary>
/// Initializes a new instance of the <see cref="CheckBox"/> class with the specified text.
/// </summary>
/// <param name="text">The text specified by the <see cref="CheckBox"/>.</param>
public CheckBox(string text)
/// <param name="checked">The state of the <see cref="CheckBox"/>.</param>
public CheckBox(string text, bool @checked = false)
{
Handle = NativeCalls.NewCheckbox(text);
this.text = text;
Text = text;
Checked = @checked;
InitializeEvents();
}

Expand All @@ -36,16 +39,16 @@ public string Text
{
get
{
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
text = NativeCalls.CheckboxText(Handle);
return text;
}
set
{
if (text != value)
{
NativeCalls.CheckboxSetText(Handle, value);
text = value;
}
if (text == value) return;
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
NativeCalls.CheckboxSetText(Handle, value);
text = value;
}
}

Expand All @@ -56,16 +59,16 @@ public bool Checked
{
get
{
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
@checked = NativeCalls.CheckboxChecked(Handle);
return @checked;
}
set
{
if (@checked != value)
{
NativeCalls.CheckboxSetChecked(Handle, value);
@checked = value;
}
if (@checked == value) return;
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
NativeCalls.CheckboxSetChecked(Handle, value);
@checked = value;
}
}

Expand All @@ -77,6 +80,10 @@ public bool Checked
/// <summary>
/// Initializes this UI component's events.
/// </summary>
protected sealed override void InitializeEvents() => NativeCalls.CheckboxOnToggled(Handle, (checkbox, data) => { OnToggled(); }, IntPtr.Zero);
protected sealed override void InitializeEvents()
{
if (IsInvalid) throw new UIComponentInvalidHandleException<SafeControlHandle>(this);
NativeCalls.CheckboxOnToggled(Handle, (checkbox, data) => { OnToggled(); }, IntPtr.Zero);
}
}
}

0 comments on commit 4712a3c

Please sign in to comment.