Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Spinner control for desktop platforms. Issue #131
- Loading branch information
Showing
17 changed files
with
840 additions
and
345 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Eto.Forms; | ||
|
||
namespace Eto.Platform.GtkSharp.Forms.Controls | ||
{ | ||
public class SpinnerHandler : GtkControl<Gtk.Spinner, Spinner>, ISpinner | ||
{ | ||
bool enabled; | ||
public SpinnerHandler() | ||
{ | ||
Control = new Gtk.Spinner(); | ||
} | ||
|
||
public override void OnLoadComplete(EventArgs e) | ||
{ | ||
base.OnLoadComplete(e); | ||
if (enabled) | ||
Control.Start(); | ||
} | ||
|
||
public override void OnUnLoad(EventArgs e) | ||
{ | ||
base.OnUnLoad(e); | ||
if (enabled) | ||
Control.Stop(); | ||
} | ||
|
||
public override bool Enabled | ||
{ | ||
get { return enabled; } | ||
set | ||
{ | ||
if (enabled != value) | ||
{ | ||
enabled = value; | ||
if (Widget.Loaded) | ||
{ | ||
if (enabled) | ||
Control.Start(); | ||
else | ||
Control.Stop(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using MonoMac.AppKit; | ||
using Eto.Forms; | ||
using Eto.Drawing; | ||
|
||
namespace Eto.Platform.Mac.Forms.Controls | ||
{ | ||
public class SpinnerHandler : MacView<NSProgressIndicator, Spinner>, ISpinner | ||
{ | ||
bool enabled; | ||
readonly NSView view; | ||
|
||
public override NSView ContainerControl { get { return view; } } | ||
|
||
protected override SizeF GetNaturalSize(SizeF availableSize) | ||
{ | ||
return new SizeF(16, 16); | ||
} | ||
|
||
public SpinnerHandler() | ||
{ | ||
Control = new NSProgressIndicator | ||
{ | ||
Style = NSProgressIndicatorStyle.Spinning, | ||
ControlSize = NSControlSize.Regular | ||
}; | ||
view = new MacEventView { Handler = this }; | ||
view.AddSubview(Control); | ||
} | ||
protected override void Initialize() | ||
{ | ||
base.Initialize(); | ||
HandleEvent(Eto.Forms.Control.SizeChangedEvent); | ||
} | ||
|
||
public override void OnSizeChanged(EventArgs e) | ||
{ | ||
base.OnSizeChanged(e); | ||
var size = Math.Max(Size.Width, Size.Height); | ||
if (size <= 8) | ||
Control.ControlSize = NSControlSize.Mini; | ||
else if (size <= 20) | ||
Control.ControlSize = NSControlSize.Small; | ||
else if (size <= 30) | ||
Control.ControlSize = NSControlSize.Regular; | ||
Control.SizeToFit(); | ||
Control.CenterInParent(); | ||
} | ||
|
||
public override void OnLoadComplete(EventArgs e) | ||
{ | ||
base.OnLoadComplete(e); | ||
if (enabled) | ||
Control.StartAnimation(Control); | ||
} | ||
|
||
public override void OnUnLoad(EventArgs e) | ||
{ | ||
base.OnUnLoad(e); | ||
if (enabled) | ||
Control.StopAnimation(Control); | ||
} | ||
|
||
public override bool Enabled | ||
{ | ||
get { return enabled; } | ||
set | ||
{ | ||
if (enabled != value) | ||
{ | ||
enabled = value; | ||
if (Widget.Loaded) | ||
{ | ||
if (enabled) | ||
Control.StartAnimation(Control); | ||
else | ||
Control.StopAnimation(Control); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.