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

Switch Sliders and ProgressBars to floating point values #1

Open
wants to merge 1 commit into
base: master
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
14 changes: 7 additions & 7 deletions src/Eto.Gtk/Forms/Controls/ProgressBarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Eto.GtkSharp.Forms.Controls
{
public class ProgressBarHandler : GtkControl<Gtk.ProgressBar, ProgressBar, ProgressBar.ICallback>, ProgressBar.IHandler
{
int minValue;
int maxValue = 100;
double minValue;
double maxValue = 100;
bool indeterminate;
UITimer timer;
public static double UpdateInterval = 0.2;
Expand Down Expand Up @@ -64,7 +64,7 @@ public bool Indeterminate
}
}

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

public int MinValue
public double MinValue
{
get { return minValue; }
set
Expand All @@ -86,12 +86,12 @@ public int MinValue
}
}

public int Value
public double Value
{
get { return (int)((Control.Fraction * MaxValue) + MinValue); }
get { return Control.Fraction * MaxValue + MinValue; }
set
{
Control.Fraction = Math.Max(0, Math.Min(1, ((double)value - MinValue) / (double)MaxValue));
Control.Fraction = Math.Max(0, Math.Min(1, (value - MinValue) / MaxValue));
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/Eto.Gtk/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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;
Gtk.Scale scale;

public SliderHandler()
Expand All @@ -33,15 +33,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 +64,7 @@ public void HandleScaleValueChanged(object sender, EventArgs e)
}
}

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

public int MinValue
public double MinValue
{
get { return min; }
set
Expand All @@ -84,15 +84,15 @@ 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 int TickFrequency
public double TickFrequency
{
get
{
Expand Down
26 changes: 13 additions & 13 deletions src/Eto.Mac/Forms/Controls/ProgressBarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected override SizeF GetNaturalSize (SizeF availableSize)
return new Size (80, 30);
}

public bool Indeterminate {
public bool Indeterminate
{
get { return Control.Indeterminate; }
set {
Control.Indeterminate = value;
Expand All @@ -87,22 +88,21 @@ public bool Indeterminate {
}
}

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

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

public int Value {
get { return (int)Control.DoubleValue; }
public double Value
{
get { return Control.DoubleValue; }
set { Control.DoubleValue = value; }
}
}
Expand Down
24 changes: 10 additions & 14 deletions src/Eto.Mac/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ static void HandleActivated(object sender, EventArgs e)
{
handler.TriggerMouseCallback();

var newval = (int)Math.Round(handler.Control.DoubleValue);
if (newval != handler.Control.IntValue)
handler.Control.IntValue = newval;

handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty);
}
}
Expand All @@ -89,9 +85,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 @@ -100,9 +96,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 @@ -111,10 +107,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 @@ -123,17 +119,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 = value > 0 ? (MaxValue - MinValue) / value + 1 : 0;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Eto.WinForms/Forms/Controls/ProgressBarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public bool Indeterminate {
}
}

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

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

public int Value {
public double Value {
get { return Control.Value; }
set { Control.Value = value; }
set { Control.Value = (int)value; }
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/Eto.WinForms/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Eto.WinForms.Forms.Controls
{
public class SliderHandler : WindowsControl<swf.TrackBar, Slider, Slider.ICallback>, Slider.IHandler
{
int? lastValue;
double? lastValue;

class EtoTrackBar : swf.TrackBar
{
Expand Down 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; }
set { Control.Maximum = (int)value; }
}

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

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

public bool SnapToTick { get; set; }

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

Expand Down
6 changes: 3 additions & 3 deletions src/Eto.Wpf/Forms/Controls/ProgressBarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public ProgressBarHandler()
};
}

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

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

public int Value
public double Value
{
get { return (int)Control.Value; }
set { Control.Value = 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
Loading