Skip to content

Commit

Permalink
Merge pull request #195 from fsprojects/sleepyfran/chores/0.5-upgrade
Browse files Browse the repository at this point in the history
Avalonia.FuncUI 0.5 release
  • Loading branch information
JordanMarr authored Mar 18, 2022
2 parents 0f800b5 + 4479637 commit c2ec8e6
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
dotnet-version: 6.0.x
- name: Build & Test
run: dotnet test src/Avalonia.FuncUI.sln --verbosity normal
- name: Install WASM workload
run: dotnet workload install wasm-tools
- name: Build for release
run: dotnet build src/Avalonia.FuncUI.sln -c Release
- name: Publish base project, DSL and Elmish NuGets (if this version was not published before)
run: dotnet nuget push src/**/bin/Release/*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
run: dotnet nuget push src/**/bin/Release/*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,54 @@
*(Application was created using Avalonia.FuncUI!)*

## About
This library allows you to write cross-platform GUI Applications entirely in F# - No XAML, but a declarative Elm-like DSL. MVU (Model-View-Update) architecture support is built in, and bindings to use it with Elmish are also ready to use.
This library allows you to write cross-platform GUI Applications entirely in F# - No XAML, but either using React/Sutil inspired components or a declarative Elm-like DSL with MVU (Model-View-Update) architecture support and Elmish bindings built-in.

## Getting started

- 🧱[Templates](https://github.com/AvaloniaCommunity/Avalonia.FuncUI.ProjectTemplates)

- 📓[Examples](https://github.com/AvaloniaCommunity/Avalonia.FuncUI/tree/master/src/Examples)
- 📓[Examples](https://github.com/fsprojects/Avalonia.FuncUI/tree/master/src/Examples)

- 📚[Documentation](https://avaloniacommunity.github.io/Avalonia.FuncUI.Docs/)

## Contributing
Please contribute to this library through issue reports, pull requests, code reviews, documentation, and discussion.

## Example
Below is the code of a simple counter app (using the Avalonia.FuncUI.Elmish package).
## Examples
### Example using components
A simple counter made with the component library:

``` f#
module Counter =
let view =
Component
(fun ctx ->
let state = ctx.useState 0
DockPanel.create [
DockPanel.children [
Button.create [
Button.onClick (fun _ -> state.Current - 1 |> state.Set)
Button.content "click to decrement"
]
Button.create [
Button.onClick (fun _ -> state.Current + 1 |> state.Set)
Button.content "click to increment"
]
]
TextBlock.create [
TextBlock.dock Dock.Top
TextBlock.text (string state.Current)
]
]
])
```

This and more examples using the component library in the [Components Examples folder](https://github.com/fsprojects/Avalonia.FuncUI/tree/master/src/Examples/Component%20Examples).

### Example using Elmish
The same counter as above but using the `Avalonia.FuncUI.Elmish` package:

```f#
module Counter =
Expand Down Expand Up @@ -69,6 +102,8 @@ module Counter =
]
```

This and more examples using Elmish in the [Elmish Examples folder](https://github.com/fsprojects/Avalonia.FuncUI/tree/master/src/Examples/Elmish%20Examples)

# Maintainer(s)

The current co-maintainers of Avalonia.FuncUI are
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.FuncUI.DSL/Avalonia.FuncUI.DSL.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>https://github.com/FuncUI/Avalonia.FuncUI/blob/master/github/img/nuget_icon.png?raw=true</PackageIconUrl>
<Title>Avalonia FuncUI DSL</Title>
<PackageVersion>0.5.0-beta</PackageVersion>
<PackageVersion>0.5.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.FuncUI.Elmish/Avalonia.FuncUI.Elmish.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>https://github.com/FuncUI/Avalonia.FuncUI/blob/master/github/img/nuget_icon.png?raw=true</PackageIconUrl>
<Title>Avalonia FuncUI Elmish</Title>
<PackageVersion>0.5.0-beta</PackageVersion>
<PackageVersion>0.5.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.FuncUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Examples.ChordParser", "Exa
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Examples.WebAssemblyPlayground", "Examples\Component Examples\Examples.WebAssemblyPlayground\Examples.WebAssemblyPlayground.fsproj", "{57D0AF41-5482-47FC-B75A-51FADD2FFEBD}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Examples.CounterApp", "Examples\Component Examples\Examples.CounterApp\Examples.CounterApp.fsproj", "{5CC37986-D6E0-438B-B895-BC82DFD22307}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -121,6 +123,10 @@ Global
{57D0AF41-5482-47FC-B75A-51FADD2FFEBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57D0AF41-5482-47FC-B75A-51FADD2FFEBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57D0AF41-5482-47FC-B75A-51FADD2FFEBD}.Release|Any CPU.Build.0 = Release|Any CPU
{5CC37986-D6E0-438B-B895-BC82DFD22307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CC37986-D6E0-438B-B895-BC82DFD22307}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CC37986-D6E0-438B-B895-BC82DFD22307}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CC37986-D6E0-438B-B895-BC82DFD22307}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -141,6 +147,7 @@ Global
{EB476DAF-C691-46B4-84FC-CA64E4C64A1A} = {F50826CE-D9BC-45CF-A110-C42225B75AD3}
{BF5DC7CC-7ABF-40AB-97DD-6774C17FE005} = {F50826CE-D9BC-45CF-A110-C42225B75AD3}
{57D0AF41-5482-47FC-B75A-51FADD2FFEBD} = {F50826CE-D9BC-45CF-A110-C42225B75AD3}
{5CC37986-D6E0-438B-B895-BC82DFD22307} = {F50826CE-D9BC-45CF-A110-C42225B75AD3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4630E817-6780-4C98-9379-EA3B45224339}
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.FuncUI/Avalonia.FuncUI.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>https://github.com/FuncUI/Avalonia.FuncUI/blob/master/github/img/nuget_icon.png?raw=true</PackageIconUrl>
<Title>Avalonia FuncUI</Title>
<PackageVersion>0.5.0-beta</PackageVersion>
<PackageVersion>0.5.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<WarnOn>3390;$(WarnOn)</WarnOn>
<RootNamespace>Examples.ChordParser</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Examples.Components.CounterApp</RootNamespace>
<PackageId>Examples.CounterApp</PackageId>
</PropertyGroup>

<ItemGroup>
<Compile Include="Main.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Avalonia.FuncUI.DSL\Avalonia.FuncUI.DSL.fsproj" />
<ProjectReference Include="..\..\..\Avalonia.FuncUI\Avalonia.FuncUI.fsproj" />
</ItemGroup>

</Project>
61 changes: 61 additions & 0 deletions src/Examples/Component Examples/Examples.CounterApp/Main.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace Examples.CounterApp

module Main =
open Avalonia.Controls
open Avalonia.FuncUI
open Avalonia.FuncUI.DSL
open Avalonia.Layout

let view =
Component
(fun ctx ->
let state = ctx.useState 0

DockPanel.create [
DockPanel.children [
Button.create [
Button.dock Dock.Bottom
Button.onClick (fun _ -> state.Set 0)
Button.content "reset"
Button.horizontalAlignment HorizontalAlignment.Stretch
]
Button.create [
Button.dock Dock.Bottom
Button.onClick (fun _ -> state.Current - 1 |> state.Set)
Button.content "-"
Button.horizontalAlignment HorizontalAlignment.Stretch
]
Button.create [
Button.dock Dock.Bottom
Button.onClick (fun _ -> state.Current + 1 |> state.Set)
Button.content "+"
Button.horizontalAlignment HorizontalAlignment.Stretch
]
Button.create [
Button.dock Dock.Bottom
Button.onClick (
(fun _ -> state.Current * 2 |> state.Set),
SubPatchOptions.OnChangeOf state.Current
)
Button.content "x2"
Button.horizontalAlignment HorizontalAlignment.Stretch
]
TextBox.create [
TextBox.dock Dock.Bottom
TextBox.onTextChanged (
(fun text ->
let isNumber, number = System.Int32.TryParse text
if isNumber then number |> state.Set)
)
TextBox.text (string state.Current)
TextBox.horizontalAlignment HorizontalAlignment.Stretch
]
TextBlock.create [
TextBlock.dock Dock.Top
TextBlock.fontSize 48.0
TextBlock.verticalAlignment VerticalAlignment.Center
TextBlock.horizontalAlignment HorizontalAlignment.Center
TextBlock.text (string state.Current)
]
]
])
37 changes: 37 additions & 0 deletions src/Examples/Component Examples/Examples.CounterApp/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Examples.CounterApp

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

type MainWindow() =
inherit HostWindow()
do
base.Title <- "Counter Example"
base.Height <- 400.0
base.Width <- 400.0
base.Content <- Main.view

type App() =
inherit Application()

override this.Initialize() =
this.Styles.Add (FluentTheme(baseUri = null, Mode = FluentThemeMode.Dark))

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

module Program =

[<EntryPoint>]
let main(args: string[]) =
AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseSkia()
.StartWithClassicDesktopLifetime(args)

0 comments on commit c2ec8e6

Please sign in to comment.