A version of the default Fabulous app template running on Linux and macOS
This is a version of a Fabulous app created from the Fabulous template. The difference here is this runs on Linux using GTK#.
If you want to create this yourself, follow these steps.
Install the template, and create a new project using:
dotnet new -i Fabulous.Templates
dotnet new fabulous-app -lang F# -n SqueakyApp
Launch the solution file using MonoDevelop - I used the nightly builds as these have better support for the underlying technology used by Fabulous. Then delete the Android
and iOS
apps.
Right-click on the solution and select Add -> Add New Project.... Choose Other -> .NET -> Gtk# 2.0 project. Select F# from the drop down, then click Next. Give your project a name, such as SqueakyApp.Gtk
, then click Create.
Add the Xamarin.Forms and Xamarin.Forms.Platform.GTK NuGet packages to this project, and update the Xamarin.Forms package used by the SqueakyApp .NET Standard project to the same version as you have just installed.
Add a reference to the SqueakyApp .NET Standard project to your new GTK project.
Open up Main.fs
, and change the code to match the following:
namespace SqueakyApp.Gtk
module Main =
open System
open Xamarin.Forms
open Xamarin.Forms.Platform.GTK
[<EntryPoint>]
let Main(args) =
Gtk.Application.Init()
Forms.Init()
let app = new SqueakyApp.App()
let window = new FormsWindow()
window.LoadApplication(app)
window.SetApplicationTitle("Hello Fabulous Linux")
window.Show();
Gtk.Application.Run()
0
This code will initialize GTK, initialize Xamarin.Forms, then launch the Forms app inside a GTK window.
Run your app!
You can read more on adding Xamarin.Forms GTK support for Linux on docs.microsoft.com.
Right-click on the solution and select Add -> Add New Project.... Choose Mac -> App -> Cocoa App. Select F# from the drop down, then click Next. Give your project a name, such as SqueakyApp.Mac
, then click Create.
Add the Xamarin.Forms, Fabulous.Core, Fabulous.LiveUpdate and Newtonsoft.Json NuGet packages to this project, and update the Xamarin.Forms package used by the SqueakyApp .NET Standard project to the same version as you have just installed.
Add a reference to the SqueakyApp .NET Standard project to your new GTK project.
Open up Main.fs
, and change the code to match the following:
namespace SqueakyApp.Gtk
open System
open AppKit
module main =
[<EntryPoint>]
let main args =
NSApplication.Init ()
NSApplication.SharedApplication.Delegate <- new AppDelegate();
NSApplication.Main (args)
0
This code will initialize app delegate that will run the macOS app. Here is app delegate code.
open System
open Foundation
open AppKit
open Xamarin.Forms
open Xamarin.Forms.Platform.MacOS
[<Register ("AppDelegate")>]
type AppDelegate () =
inherit FormsApplicationDelegate ()
let mutable _window : NSWindow = null
do
let style = NSWindowStyle.Closable ||| NSWindowStyle.Resizable ||| NSWindowStyle.Titled
let rect = CoreGraphics.CGRect(200., 1000., 1024., 768.)
_window <- new NSWindow(rect, style, NSBackingStore.Buffered, false)
_window.Title <- "Hello Fabulous Mac!"
_window.TitleVisibility <- NSWindowTitleVisibility.Hidden
override this.MainWindow =
_window
override this.DidFinishLaunching(notification) =
Forms.Init()
this.LoadApplication(new SqueakyApp.App())
base.DidFinishLaunching(notification)
This code will initialize cocoa app, initialize Xamarin.Forms, then launch the Forms app inside a cocoa app window.
Run your app!
You can read more on adding Xamarin.Forms Cocoa support for macOS on docs.microsoft.com.