Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Jan 28, 2023
1 parent 6eb1a5e commit 6420755
Show file tree
Hide file tree
Showing 56 changed files with 434 additions and 429 deletions.
56 changes: 25 additions & 31 deletions samples/CounterApp/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,76 @@ open type Fabulous.Maui.View

module App =
type Model =
{ Count: int
Step: int
TimerOn: bool }

{ Count: int; Step: int; TimerOn: bool }

type Msg =
| Increment
| Decrement
| Reset
| SetStep of float
| TimerToggled of bool
| TimedTick

let initModel = { Count = 0; Step = 1; TimerOn = false }

let timerCmd () =
async {
do! Async.Sleep 200
return TimedTick
}
|> Cmd.ofAsyncMsg

let init() =
initModel, Cmd.none


let init () = initModel, Cmd.none

let update msg model =
match msg with
| Increment ->
{ model with
Count = model.Count + model.Step }, Cmd.none
Count = model.Count + model.Step },
Cmd.none
| Decrement ->
{ model with
Count = model.Count - model.Step }, Cmd.none
Count = model.Count - model.Step },
Cmd.none
| Reset -> initModel, Cmd.none
| SetStep n -> { model with Step = int(n + 0.5) }, Cmd.none
| TimerToggled on ->
{ model with TimerOn = on },
if on then timerCmd() else Cmd.none
| TimerToggled on -> { model with TimerOn = on }, (if on then timerCmd() else Cmd.none)
| TimedTick ->
if model.TimerOn then
{ model with Count = model.Count + model.Step },
{ model with
Count = model.Count + model.Step },
timerCmd()
else
model, Cmd.none

let view model =
Application() {
Window(
ContentView(
(VStack() {
Label($"%d{model.Count}")
.centerHorizontal()

Label($"%d{model.Count}").centerHorizontal()

TextButton("Increment", Increment)

TextButton("Decrement", Decrement)

(HStack() {
Label("Timer")
Switch(model.TimerOn, TimerToggled)
})
.padding(20.)
.centerHorizontal()

Slider(0., 10., double model.Step, SetStep)

Label($"Step size: %d{model.Step}")
.centerTextHorizontal()


Label($"Step size: %d{model.Step}").centerTextHorizontal()

TextButton("Reset", Reset)
})
.padding(30.)
.centerVertical()
)
)
}

let program =
Program.statefulWithCmd init update view
|> Program.withThemeAwareness

let program = Program.statefulWithCmd init update view |> Program.withThemeAwareness
5 changes: 2 additions & 3 deletions samples/CounterApp/MauiProgram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ type MauiProgram =
fonts
.AddFont("OpenSans_Regular.ttf", "OpenSansRegular")
.AddFont("OpenSans_Semibold.ttf", "OpenSansSemibold")
|> ignore
)
.Build()
|> ignore)
.Build()
16 changes: 10 additions & 6 deletions samples/CounterApp/Platforms/Android/MainActivity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ open Android.App
open Android.Content.PM
open Microsoft.Maui

[<Activity(
Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
ConfigurationChanges = (ConfigChanges.ScreenSize ||| ConfigChanges.Orientation ||| ConfigChanges.UiMode ||| ConfigChanges.ScreenLayout ||| ConfigChanges.SmallestScreenSize ||| ConfigChanges.Density)
)>]
[<Activity(Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
ConfigurationChanges =
(ConfigChanges.ScreenSize
||| ConfigChanges.Orientation
||| ConfigChanges.UiMode
||| ConfigChanges.ScreenLayout
||| ConfigChanges.SmallestScreenSize
||| ConfigChanges.Density))>]
type MainActivity() =
inherit MauiAppCompatActivity()
inherit MauiAppCompatActivity()
5 changes: 2 additions & 3 deletions samples/CounterApp/Platforms/Android/MainApplication.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ type MainApplication(handle, ownership) =
inherit MauiApplication(handle, ownership)

do CounterApp.Resource.UpdateIdValues()

override this.CreateMauiApp() =
MauiProgram.CreateMauiApp()

override this.CreateMauiApp() = MauiProgram.CreateMauiApp()
39 changes: 19 additions & 20 deletions samples/HelloWorld/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@ module App =
let semanticAnnounce text =
fun () -> SemanticScreenReader.Announce(text)
|> Cmd.ignore

type Model =
{ Count: int
ButtonText: string }

type Msg =
| Increment

let init() =

type Model = { Count: int; ButtonText: string }

type Msg = | Increment

let init () =
{ Count = 0; ButtonText = "Click me!" }, Cmd.none

let update msg model =
match msg with
| Increment ->
let newCount = model.Count + 1

let text =
match newCount with
| 1 -> "Clicked: 1 time"
| count -> $"Clicked: {count} times"

{ model with Count = newCount; ButtonText = text }, semanticAnnounce text


{ model with
Count = newCount
ButtonText = text },
semanticAnnounce text

let view model =
Application() {
Window(
Expand All @@ -44,19 +45,19 @@ module App =
.semantics(Semantics(Description = "Cute dotnet bot waving hi to you!"))
.height(200.)
.centerHorizontal()

Label("Hello, World!")
.style(Styles.label)
.semantics(Semantics(HeadingLevel = SemanticHeadingLevel.Level1))
.font(Font.SystemFontOfSize(32.))
.centerHorizontal()

Label("Welcome to .NET Multi-platform App UI")
.style(Styles.label)
.semantics(Semantics(HeadingLevel = SemanticHeadingLevel.Level2, Description = "Welcome to dot net Multi platform App U I"))
.font(Font.SystemFontOfSize(18.))
.centerHorizontal()

// Compatibility button
Button(model.ButtonText, Increment)
//.style(Styles.textButton)
Expand All @@ -70,7 +71,5 @@ module App =
.style(Styles.contentView)
)
}

let program =
Program.statefulWithCmd init update view
|> Program.withThemeAwareness

let program = Program.statefulWithCmd init update view |> Program.withThemeAwareness
5 changes: 2 additions & 3 deletions samples/HelloWorld/MauiProgram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ type MauiProgram =
fonts
.AddFont("OpenSans_Regular.ttf", "OpenSansRegular")
.AddFont("OpenSans_Semibold.ttf", "OpenSansSemibold")
|> ignore
)
.Build()
|> ignore)
.Build()
16 changes: 10 additions & 6 deletions samples/HelloWorld/Platforms/Android/MainActivity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ open Android.App
open Android.Content.PM
open Microsoft.Maui

[<Activity(
Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
ConfigurationChanges = (ConfigChanges.ScreenSize ||| ConfigChanges.Orientation ||| ConfigChanges.UiMode ||| ConfigChanges.ScreenLayout ||| ConfigChanges.SmallestScreenSize ||| ConfigChanges.Density)
)>]
[<Activity(Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
ConfigurationChanges =
(ConfigChanges.ScreenSize
||| ConfigChanges.Orientation
||| ConfigChanges.UiMode
||| ConfigChanges.ScreenLayout
||| ConfigChanges.SmallestScreenSize
||| ConfigChanges.Density))>]
type MainActivity() =
inherit MauiAppCompatActivity()
inherit MauiAppCompatActivity()
5 changes: 2 additions & 3 deletions samples/HelloWorld/Platforms/Android/MainApplication.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ type MainApplication(handle, ownership) =
inherit MauiApplication(handle, ownership)

do HelloWorld.Resource.UpdateIdValues()

override this.CreateMauiApp() =
MauiProgram.CreateMauiApp()

override this.CreateMauiApp() = MauiProgram.CreateMauiApp()
14 changes: 6 additions & 8 deletions samples/HelloWorld/Styles.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ module Colors =
let gray900 = Color.FromArgb("#212121")
let gray = Color.FromArgb("#1B1B1B")
let primary = Color.FromArgb("#512BD4")

module Fonts =
let OpenSansRegular = "OpenSansRegular"

module Styles =
let inline textButton (widget: WidgetBuilder<'msg, #ITextButton>) =
widget
Expand All @@ -27,11 +27,9 @@ module Styles =
.padding(14., 10.)
.minimumHeight(44.)
.minimumWidth(44.)

let inline label (widget: WidgetBuilder<'msg, #ILabel>) =
widget
.textColor(ThemeAware.Of(Colors.gray900, Colors.white))

widget.textColor(ThemeAware.Of(Colors.gray900, Colors.white))

let inline contentView (widget: WidgetBuilder<'msg, #IContentView>) =
widget
.background(SolidPaint(ThemeAware.Of(Colors.white, Colors.gray)))
widget.background(SolidPaint(ThemeAware.Of(Colors.white, Colors.gray)))
18 changes: 11 additions & 7 deletions src/Fabulous.Maui/AppHostBuilderExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ module FabulousHandlers =
type AppHostBuilderExtensions =
/// Start a Fabulous app taking args
[<Extension>]
static member UseFabulousApp<'args, 'model, 'msg, 'marker when 'marker :> IApplication>(this: MauiAppBuilder, program: Program<'args, 'model, 'msg, 'marker>, args: 'args) =
static member UseFabulousApp<'args, 'model, 'msg, 'marker when 'marker :> IApplication>
(
this: MauiAppBuilder,
program: Program<'args, 'model, 'msg, 'marker>,
args: 'args
) =
this.Services.TryAddSingleton<IApplication>(fun _ ->
let app = Program.startApplicationWithArgs args program
app
)
this
.ConfigureMauiHandlers(FabulousHandlers.register)

app)

this.ConfigureMauiHandlers(FabulousHandlers.register)

/// Start a Fabulous app taking no args
[<Extension>]
static member UseFabulousApp<'model, 'msg, 'marker when 'marker :> IApplication>(this: MauiAppBuilder, program: Program<unit, 'model, 'msg, 'marker>) =
this.UseFabulousApp(program, ())
this.UseFabulousApp(program, ())
1 change: 0 additions & 1 deletion src/Fabulous.Maui/Compatibility/Views/Any.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ module AnyBuilders =
/// Downcast to ICell to allow to return different types of cells in a single expression (e.g. if/else, match with pattern, etc.)
static member AnyCell(widget: WidgetBuilder<'msg, #IFabCompatCell>) =
WidgetBuilder<'msg, IFabCompatCell>(widget.Key, widget.Attributes)

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module LinearGradientBrushBuilders =
LinearGradientBrush.StartPoint.WithValue(Point(0., 0.)),
LinearGradientBrush.EndPoint.WithValue(Point(1., 1.))
)

/// <summary>LinearGradientBrush paints an area with a linear gradient, which blends two or more colors along a line known as the gradient axis. </summary>
/// <param name="endPoint">EndPoint, of type Point, which represents the ending two-dimensional coordinates of the linear gradient. The default value of this property is (1,1).</param>
/// <param name="startPoint">StartPoint, of type Point, which represents the starting two-dimensional coordinates of the linear gradient. The default value of this property is (0,0).</param>
Expand All @@ -39,4 +39,4 @@ module LinearGradientBrushBuilders =
GradientBrush.Children,
LinearGradientBrush.StartPoint.WithValue(startPoint),
LinearGradientBrush.EndPoint.WithValue(endPoint)
)
)
6 changes: 5 additions & 1 deletion src/Fabulous.Maui/Compatibility/Views/Cells/ImageCell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ module ImageCellBuilders =
type Fabulous.Maui.View with

static member inline ImageCell<'msg>(text: string, light: ImageSource, ?dark: ImageSource) =
WidgetBuilder<'msg, IFabCompatImageCell>(ImageCell.WidgetKey, TextCell.Text.WithValue(text), ImageCell.ImageSource.WithValue(AppTheme.create light dark))
WidgetBuilder<'msg, IFabCompatImageCell>(
ImageCell.WidgetKey,
TextCell.Text.WithValue(text),
ImageCell.ImageSource.WithValue(AppTheme.create light dark)
)

static member inline ImageCell<'msg>(text: string, light: string, ?dark: string) =
let light = ImageSource.FromFile(light)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,11 @@ type CollectionViewModifiers =
this.AddScalar(CollectionView.SelectionChanged.WithValue(fun args -> onSelectionChanged args |> box))

[<Extension>]
static member inline header
(
this: WidgetBuilder<'msg, #IFabCompatCollectionView>,
content: WidgetBuilder<'msg, #IView>
) =
static member inline header(this: WidgetBuilder<'msg, #IFabCompatCollectionView>, content: WidgetBuilder<'msg, #IView>) =
this.AddWidget(CollectionView.Header.WithValue(content.Compile()))

[<Extension>]
static member inline footer
(
this: WidgetBuilder<'msg, #IFabCompatCollectionView>,
content: WidgetBuilder<'msg, #IView>
) =
static member inline footer(this: WidgetBuilder<'msg, #IFabCompatCollectionView>, content: WidgetBuilder<'msg, #IView>) =
this.AddWidget(CollectionView.Footer.WithValue(content.Compile()))

[<Extension>]
Expand Down
Loading

0 comments on commit 6420755

Please sign in to comment.