Skip to content

Commit

Permalink
Upgrade to version 1.0.0-rc1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-brandewinder committed Jun 21, 2023
1 parent bec2141 commit f3ba539
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
13 changes: 7 additions & 6 deletions GameOfLifeMvu.fsproj
Expand Up @@ -3,16 +3,17 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
</PropertyGroup> </PropertyGroup>

<ItemGroup> <ItemGroup>
<Compile Include="Shell.fs" /> <Compile Include="Shell.fs" />
<Compile Include="Program.fs" /> <Compile Include="Program.fs" />
<AvaloniaResource Include="**\*.xaml" />
</ItemGroup> </ItemGroup>

<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="0.10.12" /> <PackageReference Include="Avalonia.Desktop" Version="11.0.0-rc1.1" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.12" /> <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-rc1.1" />
<PackageReference Include="JaggerJo.Avalonia.FuncUI" Version="0.5.0" /> <PackageReference Include="Avalonia.FuncUI" Version="1.0.0-rc1.1.0" />
<PackageReference Include="JaggerJo.Avalonia.FuncUI.DSL" Version="0.5.0" /> <PackageReference Include="Avalonia.FuncUI.Elmish" Version="1.0.0-rc1.1.0" />
<PackageReference Include="JaggerJo.Avalonia.FuncUI.Elmish" Version="0.5.0" />
</ItemGroup> </ItemGroup>

</Project> </Project>
35 changes: 25 additions & 10 deletions Program.fs
@@ -1,31 +1,46 @@
namespace GameOfLifeMvu namespace GameOfLifeMvu


open Avalonia open Avalonia
open Avalonia.Controls.ApplicationLifetimes
open Avalonia.FuncUI
open Avalonia.Themes.Fluent open Avalonia.Themes.Fluent
open Elmish
open Avalonia.FuncUI.Hosts
open Avalonia.FuncUI
open Avalonia.FuncUI.Elmish
open Avalonia.Controls.ApplicationLifetimes

type MainWindow() as this =
inherit HostWindow()
do
base.Title <- "Game of Life"
base.Width <- 800.0
base.Height <- 1000.0
base.MinWidth <- 800.0
base.MinHeight <- 1000.0


Elmish.Program.mkProgram Shell.init Shell.update Shell.view
|> Program.withHost this
|> Program.run


/// This is your application you can ose the initialize method to load styles
/// or handle Life Cycle events of your application
type App() = type App() =
inherit Application() inherit Application()


override this.Initialize() = override this.Initialize() =
this.Styles.Add (FluentTheme(baseUri = null, Mode = FluentThemeMode.Dark)) this.Styles.Add (FluentTheme())
this.Styles.Load "avares://GameOfLifeMvu/Styles.xaml" this.RequestedThemeVariant <- Styling.ThemeVariant.Dark


override this.OnFrameworkInitializationCompleted() = override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with match this.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktopLifetime -> | :? IClassicDesktopStyleApplicationLifetime as desktopLifetime ->
desktopLifetime.MainWindow <- Shell.MainWindow() let mainWindow = MainWindow()
desktopLifetime.MainWindow <- mainWindow
| _ -> () | _ -> ()


module Program = module Program =


[<EntryPoint>] [<EntryPoint>]
let main (args: string []) = let main(args: string[]) =
AppBuilder.Configure<App>() AppBuilder
.Configure<App>()
.UsePlatformDetect() .UsePlatformDetect()
.UseSkia() .UseSkia()
.StartWithClassicDesktopLifetime(args) .StartWithClassicDesktopLifetime(args)
58 changes: 21 additions & 37 deletions Shell.fs
Expand Up @@ -3,12 +3,10 @@ namespace GameOfLifeMvu
module Shell = module Shell =


open System open System
open System.Threading
open Elmish open Elmish
open Avalonia.Controls open Avalonia.Controls
open Avalonia.FuncUI.DSL open Avalonia.FuncUI.DSL
open Avalonia.FuncUI
open Avalonia.FuncUI.Hosts
open Avalonia.FuncUI.Elmish
open Avalonia.Controls.Primitives open Avalonia.Controls.Primitives
open Avalonia.Controls.Shapes open Avalonia.Controls.Shapes
open Avalonia.Layout open Avalonia.Layout
Expand Down Expand Up @@ -68,15 +66,16 @@ module Shell =
type Configuration = { type Configuration = {
Rows: int Rows: int
Columns: int Columns: int
CellSize: int
RefreshIntervalMilliseconds: int RefreshIntervalMilliseconds: int
} }
with
member this.CellSize =
(800.0 - 10.0) / float (max this.Rows this.Columns)


let config = { let config = {
Rows = 50 Rows = 250
Columns = 50 Columns = 250
CellSize = 5 RefreshIntervalMilliseconds = 100
RefreshIntervalMilliseconds = 500
} }


let init () = let init () =
Expand All @@ -90,12 +89,6 @@ module Shell =
) )
{ Cells = cells; Running = false; Generation = 0 }, Cmd.none { Cells = cells; Running = false; Generation = 0 }, Cmd.none


let waitAndUpdate =
Cmd.OfAsync.perform
(fun () -> async { do! Async.Sleep config.RefreshIntervalMilliseconds })
()
(fun () -> NextGeneration)

let update (msg: Msg) (state: State): State * Cmd<Msg> = let update (msg: Msg) (state: State): State * Cmd<Msg> =
match msg with match msg with
| Restart -> init () | Restart -> init ()
Expand All @@ -113,11 +106,22 @@ module Shell =
|> Array2D.mapi (fun row col _ -> |> Array2D.mapi (fun row col _ ->
nextGeneration state.Cells (row, col) nextGeneration state.Cells (row, col)
) )
let ctx = SynchronizationContext.Current
let cmd =
Cmd.OfAsync.perform
(fun () -> async {
do! Async.Sleep config.RefreshIntervalMilliseconds
do! Async.SwitchToContext ctx
return Msg.NextGeneration
}
)
()
id
{ state with { state with
Cells = updated; Cells = updated;
Generation = state.Generation + 1 Generation = state.Generation + 1
}, },
waitAndUpdate cmd //Cmd.none
else state, Cmd.none else state, Cmd.none


let deadCell = let deadCell =
Expand Down Expand Up @@ -156,8 +160,8 @@ module Shell =
UniformGrid.columns state.Columns UniformGrid.columns state.Columns
UniformGrid.rows state.Rows UniformGrid.rows state.Rows


UniformGrid.width (state.Columns * config.CellSize |> float) UniformGrid.width (float state.Columns * config.CellSize |> float)
UniformGrid.height (state.Rows * config.CellSize |> float) UniformGrid.height (float state.Rows * config.CellSize |> float)


UniformGrid.children [ UniformGrid.children [
for row in 0 .. state.Rows - 1 do for row in 0 .. state.Rows - 1 do
Expand Down Expand Up @@ -196,23 +200,3 @@ module Shell =
] ]
] ]
] ]

/// This is the main window of your application
/// you can do all sort of useful things here like setting heights and widths
/// as well as attaching your dev tools that can be super useful when developing with
/// Avalonia
type MainWindow() as this =
inherit HostWindow()
do
base.Title <- "Game of Life"
base.Width <- 500.0
base.Height <- 600.0
base.MinWidth <- 500.0
base.MinHeight <- 600.0

//this.VisualRoot.VisualRoot.Renderer.DrawFps <- true
//this.VisualRoot.VisualRoot.Renderer.DrawDirtyRects <- true

Elmish.Program.mkProgram init update view
|> Program.withHost this
|> Program.run

0 comments on commit f3ba539

Please sign in to comment.