Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sliders use floating point values #1773

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 42 additions & 25 deletions src/Eto.Gtk/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ namespace Eto.GtkSharp.Forms.Controls
{
public class SliderHandler : GtkControl<Gtk.EventBox, Slider, Slider.ICallback>, Slider.IHandler
{
int min;
int max = 100;
int tick = 1;
double min;
double max = 100;
double tick = 1;
bool snapToTick;
Gtk.Scale scale;

public SliderHandler()
{
this.Control = new Gtk.EventBox();
//Control.VisibleWindow = false;
scale = new Gtk.HScale(min, max, 1);
scale = new Gtk.HScale(min, max, SnapToTick ? tick : 0.000000001D);
this.Control.Child = scale;
}

Expand All @@ -33,15 +34,15 @@ protected override WeakConnector CreateConnector()

protected class SliderConnector : GtkControlConnector
{
int? lastValue;
double? lastValue;

public new SliderHandler Handler { get { return (SliderHandler)base.Handler; } }

public void HandleScaleValueChanged(object sender, EventArgs e)
{
var scale = Handler.scale;
var tick = Handler.tick;
var value = (int)scale.Value;
var value = scale.Value;
if (tick > 0)
{
var offset = value % tick;
Expand All @@ -64,7 +65,7 @@ public void HandleScaleValueChanged(object sender, EventArgs e)
}
}

public int MaxValue
public double MaxValue
{
get { return max; }
set
Expand All @@ -74,7 +75,7 @@ public int MaxValue
}
}

public int MinValue
public double MinValue
{
get { return min; }
set
Expand All @@ -84,15 +85,26 @@ public int MinValue
}
}

public int Value
public double Value
{
get { return (int)scale.Value; }
get { return scale.Value; }
set { scale.Value = value; }
}

public bool SnapToTick { get; set; }
public bool SnapToTick
{
get
{
return snapToTick;
}
set
{
snapToTick = value;
UpdateScale(Orientation);
}
}

public int TickFrequency
public double TickFrequency
{
get
{
Expand All @@ -115,22 +127,27 @@ public Orientation Orientation
{
if (Orientation != value)
{
scale.ValueChanged -= Connector.HandleScaleValueChanged;
Control.Remove(scale);
#if !GTKCORE
scale.Destroy();
#endif
scale.Dispose();
if (value == Orientation.Horizontal)
scale = new Gtk.HScale(min, max, 1);
else
scale = new Gtk.VScale(min, max, 1);
scale.ValueChanged += Connector.HandleScaleValueChanged;
Control.Child = scale;
scale.ShowAll();
UpdateScale(value);
}
}
}

protected void UpdateScale(Orientation value)
{
scale.ValueChanged -= Connector.HandleScaleValueChanged;
Control.Remove(scale);
#if !GTKCORE
scale.Destroy();
#endif
scale.Dispose();
if (value == Orientation.Horizontal)
scale = new Gtk.HScale(min, max, SnapToTick ? tick : 0.000000001D);
else
scale = new Gtk.VScale(min, max, SnapToTick ? tick : 0.000000001D);
scale.ValueChanged += Connector.HandleScaleValueChanged;
Control.Child = scale;
scale.ShowAll();
}
}
}

20 changes: 10 additions & 10 deletions src/Eto.Mac/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ protected override SizeF GetNaturalSize(SizeF availableSize)
return Orientation == Orientation.Horizontal ? new Size(80, 30) : new Size(30, 80);
}

public int MaxValue
public double MaxValue
{
get { return (int)Control.MaxValue; }
get { return Control.MaxValue; }
set
{
var old = TickFrequency;
Expand All @@ -92,9 +92,9 @@ public int MaxValue
}
}

public int MinValue
public double MinValue
{
get { return (int)Control.MinValue; }
get { return Control.MinValue; }
set
{
var old = TickFrequency;
Expand All @@ -103,10 +103,10 @@ public int MinValue
}
}

public int Value
public double Value
{
get { return Control.IntValue; }
set { Control.IntValue = value; }
get { return Control.DoubleValue; }
set { Control.DoubleValue = value; }
}

public bool SnapToTick
Expand All @@ -115,17 +115,17 @@ public bool SnapToTick
set { Control.AllowsTickMarkValuesOnly = value; }
}

public int TickFrequency
public double TickFrequency
{
get
{
if (Control.TickMarksCount > 1)
return (int)((MaxValue - MinValue) / (Control.TickMarksCount - 1));
return (MaxValue - MinValue) / (Control.TickMarksCount - 1);
return 0;
}
set
{
Control.TickMarksCount = value > 0 ? ((MaxValue - MinValue) / value) + 1 : 0;
Control.TickMarksCount = (nint)(value > 0 ? ((MaxValue - MinValue) / value) + 1 : 0);
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/Eto.WinForms/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,32 @@ void HandleScaleValueChanged(object sender, EventArgs e)
}
}

public int MaxValue
public double MaxValue
{
get { return Control.Maximum; }
set { Control.Maximum = value; }
get { return (double)Control.Maximum; }
set { Control.Maximum = (int)value; }
}

public int MinValue
public double MinValue
{
get { return Control.Minimum; }
set { Control.Minimum = value; }
get { return (double)Control.Minimum; }
set { Control.Minimum = (int)value; }
}

public int Value
public double Value
{
get { return Control.Value; }
set { Control.Value = value; }
get { return (double)Control.Value; }
set { Control.Value = (int)value; }
}

public bool SnapToTick { get; set; }

public int TickFrequency
public double TickFrequency
{
get { return Control.TickFrequency; }
get { return (double)Control.TickFrequency; }
set
{
Control.TickFrequency = value;
Control.TickFrequency = (int)value;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Eto.WinRT/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public SliderHandler ()

public override bool UseKeyPreview { get { return true; } }

public int MaxValue
public double MaxValue
{
get { return (int)Control.Maximum; }
get { return Control.Maximum; }
set { Control.Maximum = value; }
}

public int MinValue
public double MinValue
{
get { return (int)Control.Minimum; }
get { return Control.Minimum; }
set { Control.Minimum = value; }
}

public int Value
public double Value
{
get { return (int)Control.Value; }
get { return Control.Value; }
set { Control.Value = value; }
}

Expand All @@ -53,9 +53,9 @@ public bool SnapToTick
set { Control.SnapsTo = SliderSnapsTo.Ticks; }
}

public int TickFrequency
public double TickFrequency
{
get { return (int)Control.TickFrequency; }
get { return Control.TickFrequency; }
set { Control.TickFrequency = value; }
}

Expand Down
16 changes: 8 additions & 8 deletions src/Eto.Wpf/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ protected override sw.Size DefaultSize

public override bool UseKeyPreview { get { return true; } }

public int MaxValue
public double MaxValue
{
get { return (int)Control.Maximum; }
get { return Control.Maximum; }
set { Control.Maximum = value; }
}

public int MinValue
public double MinValue
{
get { return (int)Control.Minimum; }
get { return Control.Minimum; }
set { Control.Minimum = value; }
}

public int Value
public double Value
{
get { return (int)Control.Value; }
get { return Control.Value; }
set { Control.Value = value; }
}

Expand All @@ -67,9 +67,9 @@ public bool SnapToTick
set { Control.IsSnapToTickEnabled = value; }
}

public int TickFrequency
public double TickFrequency
{
get { return (int)Control.TickFrequency; }
get { return Control.TickFrequency; }
set { Control.TickFrequency = value; }
}

Expand Down
14 changes: 7 additions & 7 deletions src/Eto.iOS/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ protected override void Initialize()
TickFrequency = 1;
}

public int MaxValue
public double MaxValue
{
get { return (int)Control.MaxValue; }
get { return Control.MaxValue; }
set { Control.MaxValue = value; }
}

public int MinValue
public double MinValue
{
get { return (int)Control.MinValue; }
get { return Control.MinValue; }
set { Control.MinValue = value; }
}

public int Value
public double Value
{
get { return (int)Control.Value; }
get { return Control.Value; }
set { Control.Value = value; }
}

public int TickFrequency { get; set; }
public double TickFrequency { get; set; }

public bool SnapToTick
{
Expand Down
Loading