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

Replace Minimum/Maximum by a single MinimumMaximum property #246

Merged
merged 3 commits into from
Dec 11, 2018
Merged
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
10 changes: 5 additions & 5 deletions .paket/Paket.Restore.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
<PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketToolsPath)paket')">$(PaketToolsPath)paket</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket.exe')">$(PaketRootPath)paket.exe</PaketExePath>

<PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' ">$(PaketToolsPath)paket.exe</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND '$(PaketExeImage)' == 'assembly' ">$(PaketToolsPath)paket.exe</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND '$(PaketExeImage)' == 'native' ">$(PaketToolsPath)paket</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' AND Exists('$(PaketToolsPath)paket.exe')">$(PaketToolsPath)paket.exe</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND '$(PaketExeImage)' == 'assembly' AND Exists('$(PaketToolsPath)paket.exe') ">$(PaketToolsPath)paket.exe</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND '$(PaketExeImage)' == 'native' AND Exists('$(PaketToolsPath)paket') ">$(PaketToolsPath)paket</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' ">paket</PaketExePath>

<!-- Paket command -->
<_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)"))</_PaketExeExtension>
<PaketCommand Condition=" '$(PaketCommand)' == '' AND '$(_PaketExeExtension)' == '.dll' ">dotnet "$(PaketExePath)"</PaketCommand>
<PaketCommand Condition=" '$(PaketCommand)' == '' AND '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
<PaketCommand Condition=" '$(PaketCommand)' == '' AND '$(OS)' != 'Windows_NT' AND '$(_PaketExeExtension)' == '.exe' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</PaketCommand>
<PaketCommand Condition=" '$(PaketCommand)' == '' AND '$(OS)' != 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
<PaketCommand Condition=" '$(PaketCommand)' == '' ">"$(PaketExePath)"</PaketCommand>

<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' AND Exists('$(PaketRootPath)paket.bootstrapper.exe')">$(PaketRootPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' ">$(PaketToolsPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
Expand Down
10 changes: 1 addition & 9 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

## Ideas

* Consider allowing explicit static Xaml through a type provider, e.g `xaml<"""<StackLayout Padding="20">...</StackLayout>""">`, evaluating to a `ViewElement`

* Performance:
* Do better list comparison/diffing
* Perf-test on large lists and do resulting perf work
* Consider allowing a `ChunkList` tree as input to ListView etc., e.g. `chunks { yield! stablePart; yield newElement; yield! stablePart2 }`
* Consider memoize function closure creation
* Consider moving 'view' and 'model' computations off the UI thread

* Make some small F# langauge improvements to improve code:
* Make some small F# language improvements to improve code:
* Remove `yield` in more cases
* Automatically save function values that do not capture any arguments
* Allow a default unnamed argument for `children` so the argument name doesn't have to be given explicitly
Expand All @@ -35,9 +33,3 @@
## Discarded Ideas

* Possibly switch to a type provider (see [this comment](https://github.com/fsprojects/Fabulous/issues/50#issuecomment-390396365))


## Bugs:
* Fix issue for slider where minimum = 1.0, maximum=10.0 (i.e. when value=0 and minimum gets set before maximum?)


23 changes: 17 additions & 6 deletions samples/AllControls/AllControls/AllControls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Model =
CountForSlider : int
CountForActivityIndicator : int
StepForSlider : int
MinimumForSlider : int
MaximumForSlider : int
StartDate : System.DateTime
EndDate : System.DateTime
EditorText : string
Expand Down Expand Up @@ -53,6 +55,8 @@ type Msg =
| Reset
| IncrementForSlider
| DecrementForSlider
| ChangeMinimumMaximumForSlider1
| ChangeMinimumMaximumForSlider2
| IncrementForActivityIndicator
| DecrementForActivityIndicator
| SliderValueChanged of int
Expand Down Expand Up @@ -138,8 +142,10 @@ module App =
{ RootPageKind = Choice false
Count = 0
CountForSlider = 0
CountForActivityIndicator = 0
StepForSlider = 3
MinimumForSlider = 0
MaximumForSlider = 10
CountForActivityIndicator = 0
PickedColorIndex = 0
EditorText = "hic hac hoc"
Placeholder = "cogito ergo sum"
Expand Down Expand Up @@ -167,6 +173,8 @@ module App =
| Decrement -> { model with Count = model.Count - 1}
| IncrementForSlider -> { model with CountForSlider = model.CountForSlider + model.StepForSlider }
| DecrementForSlider -> { model with CountForSlider = model.CountForSlider - model.StepForSlider }
| ChangeMinimumMaximumForSlider1 -> { model with MinimumForSlider = 0; MaximumForSlider = 10 }
| ChangeMinimumMaximumForSlider2 -> { model with MinimumForSlider = 15; MaximumForSlider = 20 }
| IncrementForActivityIndicator -> { model with CountForActivityIndicator = model.CountForActivityIndicator + 1 }
| DecrementForActivityIndicator -> { model with CountForActivityIndicator = model.CountForActivityIndicator - 1 }
| Reset -> init ()
Expand Down Expand Up @@ -422,7 +430,7 @@ module App =
currentPage=model.Tabbed1CurrentPageIndex,
children=
[
dependsOn (model.CountForSlider, model.StepForSlider) (fun model (count, step) ->
dependsOn (model.MinimumForSlider, model.MaximumForSlider, model.CountForSlider, model.StepForSlider) (fun model (minimum, maximum, count, step) ->
View.ScrollingContentPage("Slider",
[ View.Label(text="Label:")
View.Label(text= sprintf "%d" count, horizontalOptions=LayoutOptions.CenterAndExpand)
Expand All @@ -432,10 +440,13 @@ module App =

View.Label(text="Button:")
View.Button(text="Decrement", command=(fun () -> dispatch DecrementForSlider), horizontalOptions=LayoutOptions.CenterAndExpand)

View.Label(text="Slider:")
View.Slider(minimum=0.0,
maximum=10.0,

View.Label(text="Button:")
View.Button(text="Set Minimum = 0 / Maximum = 10", command=(fun () -> dispatch ChangeMinimumMaximumForSlider1), horizontalOptions=LayoutOptions.CenterAndExpand)
View.Button(text="Set Minimum = 15 / Maximum = 20", command=(fun () -> dispatch ChangeMinimumMaximumForSlider2), horizontalOptions=LayoutOptions.CenterAndExpand)

View.Label(text=sprintf "Slider: (Minimum %d, Maximum %d, Value %d)" minimum maximum step)
View.Slider(minimumMaximum=(float minimum, float maximum),
value=double step,
valueChanged=(fun args -> dispatch (SliderValueChanged (int (args.NewValue + 0.5)))),
horizontalOptions=LayoutOptions.Fill)
Expand Down
2 changes: 1 addition & 1 deletion samples/CounterApp/CounterApp/CounterApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module App =
yield View.StackLayout(padding=20.0, orientation=StackOrientation.Horizontal, horizontalOptions=LayoutOptions.Center,
children = [ View.Label(text="Timer")
View.Switch(isToggled=model.TimerOn, toggled=(fun on -> dispatch (TimerToggled on.Value))) ])
yield View.Slider(minimum=0.0, maximum=10.0, value= double model.Step, valueChanged=(fun args -> dispatch (SetStep (int (args.NewValue + 0.5)))))
yield View.Slider(minimumMaximum=(0.0, 10.0), value= double model.Step, valueChanged=(fun args -> dispatch (SetStep (int (args.NewValue + 0.5)))))
yield View.Label(text=sprintf "Step size: %d" model.Step, horizontalOptions=LayoutOptions.Center)
//if model <> initModel () then
yield View.Button(text="Reset", horizontalOptions=LayoutOptions.Center, command=(fun () -> dispatch Reset), canExecute = (model <> initModel () ))
Expand Down
36 changes: 36 additions & 0 deletions src/Fabulous.Core/ViewConverters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,42 @@ module Converters =
| ValueSome _, ValueNone -> control.CurrentPage <- null
| _, ValueSome curr -> control.CurrentPage <- control.Children.[curr]

let updateSliderMinimumMaximum prevValueOpt valueOpt (target: obj) =
let control = target :?> Xamarin.Forms.Slider
let defaultValue = (0.0, 1.0)
let updateFunc (prevMinimum, prevMaximum) (newMinimum, newMaximum) =
if newMinimum > prevMaximum then
control.Maximum <- newMaximum
control.Minimum <- newMinimum
else
control.Minimum <- newMinimum
control.Maximum <- newMaximum

match prevValueOpt, valueOpt with
| ValueNone, ValueNone -> ()
| ValueSome prev, ValueSome curr when prev = curr -> ()
| ValueSome prev, ValueSome curr -> updateFunc prev curr
| ValueSome prev, ValueNone -> updateFunc prev defaultValue
| ValueNone, ValueSome curr -> updateFunc defaultValue curr

let updateStepperMinimumMaximum prevValueOpt valueOpt (target: obj) =
let control = target :?> Xamarin.Forms.Stepper
let defaultValue = (0.0, 1.0)
let updateFunc (prevMinimum, prevMaximum) (newMinimum, newMaximum) =
if newMinimum > prevMaximum then
control.Maximum <- newMaximum
control.Minimum <- newMinimum
else
control.Minimum <- newMinimum
control.Maximum <- newMaximum

match prevValueOpt, valueOpt with
| ValueNone, ValueNone -> ()
| ValueSome prev, ValueSome curr when prev = curr -> ()
| ValueSome prev, ValueSome curr -> updateFunc prev curr
| ValueSome prev, ValueNone -> updateFunc prev defaultValue
| ValueNone, ValueSome curr -> updateFunc defaultValue curr

let equalLayoutOptions (x:Xamarin.Forms.LayoutOptions) (y:Xamarin.Forms.LayoutOptions) =
x.Alignment = y.Alignment && x.Expands = y.Expands

Expand Down
Loading