Skip to content

Commit

Permalink
Fix Window
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Feb 2, 2023
1 parent 570d15c commit 15c781e
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/Fabulous.Maui.Controls/FabWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ namespace Fabulous.Maui
{
public interface IFabWindow : IWindow, IFabTitledElement
{
void SetOnCreated(Action? value);
void SetOnResumed(Action? value);
void SetContent(IView value);
void SetFlowDirection(FlowDirection value);
void SetHeight(double value);
void SetMaximumHeight(double value);
void SetMaximumWidth(double value);
void SetMinimumWidth(double value);
void SetMinimumHeight(double value);
void SetOnActivated(Action? value);
void SetOnBackButtonClicked(Func<bool>? value);
void SetOnBackgrounding(Action<IPersistedState>? value);
void SetOnCreated(Action? value);
void SetOnDeactivated(Action? value);
void SetOnStopped(Action? value);
void SetOnDestroying(Action? value);
void SetOnBackgrounding(Action<IPersistedState>? value);
void SetOnBackButtonClicked(Func<bool>? value);
void SetOnDisplayDensityChanged(Action<float>? value);
void SetOnFrameChanged(Action<Microsoft.Maui.Graphics.Rect>? value);
void SetContent(IView value);
void SetOnResumed(Action? value);
void SetOnStopped(Action? value);
void SetVisualDiagnosticsOverlay(IVisualDiagnosticsOverlay value);
void SetWidth(double value);
void SetX(double value);
void SetY(double value);
void SetWidth(double value);
void SetMinimumWidth(double value);
void SetMaximumWidth(double value);
void SetHeight(double value);
void SetMinimumHeight(double value);
void SetMaximumHeight(double value);
void SetFlowDirection(FlowDirection value);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/Fabulous.Maui/Compatibility/Views/Pages/NavigationPage.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open System.IO
open System.Runtime.CompilerServices
open Fabulous
open Fabulous.Maui
open Fabulous.StackAllocatedCollections
open Microsoft.Maui
open Microsoft.Maui.Controls
open Microsoft.Maui.Controls.PlatformConfiguration
Expand Down Expand Up @@ -443,3 +444,13 @@ type NavigationPagePlatformModifiers =
[<Extension>]
static member inline prefersLargeTitles(this: WidgetBuilder<'msg, #IFabCompatNavigationPage>, value: bool) =
this.AddScalar(NavigationPage.PrefersLargeTitles.WithValue(value))

[<Extension>]
type NavigationPageYieldExtensions =
[<Extension>]
static member inline Yield
(
_: CollectionBuilder<'msg, 'marker, #IFabCompatPage>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }
1 change: 0 additions & 1 deletion src/Fabulous.Maui/Compatibility/Views/_CompatView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ open Microsoft.Maui.Controls

type IFabCompatView =
inherit IFabCompatVisualElement
inherit IView

module CompatView =
let HorizontalOptions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Microsoft.Maui.Controls

type IFabCompatVisualElement =
inherit IFabCompatNavigableElement
inherit IView

[<Struct>]
type TranslateToData =
Expand Down
26 changes: 26 additions & 0 deletions src/Fabulous.Maui/Core/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ module Attributes =
if element.Handler <> null then
element.Handler.UpdateValue(propertyName))

let inline defineMauiFuncBool<'target, 'args>
(propertyName: string)
(defaultValue: Func<bool>)
([<InlineIfLambda>] set: 'target -> Func<bool> -> unit)
=
Attributes.defineSimpleScalar
$"{typeof<'target>.Name}_{propertyName}"
ScalarAttributeComparers.noCompare
(fun _ (currOpt: (unit -> obj) voption) node ->
let target = node.Target :?> 'target

match currOpt with
| ValueNone -> set target defaultValue
| ValueSome curr ->
let fn () =
let r = curr ()
Dispatcher.dispatch node r
true

set target fn

let element = node.Target :?> FabElement

if element.Handler <> null then
element.Handler.UpdateValue(propertyName))

let defineMauiProperty'<'target, 'value when 'value: equality> (propertyName: string) (defaultValueFn: unit -> 'value) (set: 'target -> 'value -> unit) =
Attributes.defineSimpleScalarWithEquality $"{typeof<'target>.Name}_{propertyName}" (fun _ currOpt node ->
let target = node.Target :?> 'target
Expand Down
149 changes: 147 additions & 2 deletions src/Fabulous.Maui/Core/Views/Window.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,79 @@
namespace Fabulous.Maui

open System.Runtime.CompilerServices
open Fabulous
open Fabulous.Maui.Controls
open Fabulous.StackAllocatedCollections.StackList
open Microsoft.Maui
open Microsoft.Maui.Graphics
open Microsoft.Maui.Handlers.Defaults

module Window =
let WidgetKey = Widgets.register<FabWindow>()

let Content =
Attributes.defineMauiPropertyWidget<IFabWindow, IView> "Content" (fun target -> target.Content) (fun target -> target.SetContent)

let FlowDirection =
Attributes.defineMauiProperty' "FlowDirection" WindowDefaults.CreateFlowDirection (fun (target: IFabWindow) -> target.SetFlowDirection)

let Height =
Attributes.defineMauiProperty "Height" WindowDefaults.Height (fun (target: IFabWindow) -> target.SetHeight)

let MaximumHeight =
Attributes.defineMauiProperty "MaximumHeight" WindowDefaults.MaximumHeight (fun (target: IFabWindow) -> target.SetMaximumHeight)

let MaximumWidth =
Attributes.defineMauiProperty "MaximumWidth" WindowDefaults.MaximumWidth (fun (target: IFabWindow) -> target.SetMaximumWidth)

let MinimumHeight =
Attributes.defineMauiProperty "MinimumHeight" WindowDefaults.MinimumHeight (fun (target: IFabWindow) -> target.SetMinimumHeight)

let MinimumWidth =
Attributes.defineMauiProperty "MinimumWidth" WindowDefaults.MinimumWidth (fun (target: IFabWindow) -> target.SetMinimumWidth)

let OnActivated =
Attributes.defineMauiAction "OnActivated" WindowDefaults.OnActivated (fun (target: IFabWindow) -> target.SetOnActivated)


let OnBackButtonClicked =
Attributes.defineMauiFuncBool "OnBackButtonClicked" WindowDefaults.OnBackButtonClicked (fun (target: IFabWindow) -> target.SetOnBackButtonClicked)

let OnBackgrounding =
Attributes.defineMauiAction' "OnBackgrounding" WindowDefaults.OnBackgrounding (fun (target: IFabWindow) -> target.SetOnBackgrounding)

let OnCreated =
Attributes.defineMauiAction "OnCreated" WindowDefaults.OnCreated (fun (target: IFabWindow) -> target.SetOnCreated)

let OnDeactivated =
Attributes.defineMauiAction "OnDeactivated" WindowDefaults.OnDeactivated (fun (target: IFabWindow) -> target.SetOnDeactivated)

let OnDestroying =
Attributes.defineMauiAction "OnDestroying" WindowDefaults.OnDestroying (fun (target: IFabWindow) -> target.SetOnDestroying)

let OnDisplayDensityChanged =
Attributes.defineMauiAction' "OnDisplayDensityChanged" WindowDefaults.OnDisplayDensityChanged (fun (target: IFabWindow) -> target.SetOnDisplayDensityChanged)

let OnFrameChanged =
Attributes.defineMauiAction' "OnFrameChanged" WindowDefaults.OnFrameChanged (fun (target: IFabWindow) -> target.SetOnFrameChanged)

let OnResumed =
Attributes.defineMauiAction "OnResumed" WindowDefaults.OnResumed (fun (target: IFabWindow) -> target.SetOnResumed)

let OnStopped =
Attributes.defineMauiAction "OnStopped" WindowDefaults.OnStopped (fun (target: IFabWindow) -> target.SetOnStopped)

let VisualDiagnosticsOverlay =
Attributes.defineMauiProperty "VisualDiagnosticsOverlay" WindowDefaults.VisualDiagnosticsOverlay (fun (target: IFabWindow) -> target.SetVisualDiagnosticsOverlay)

let Width =
Attributes.defineMauiProperty "Width" WindowDefaults.Width (fun (target: IFabWindow) -> target.SetWidth)

let X =
Attributes.defineMauiProperty "X" WindowDefaults.X (fun (target: IFabWindow) -> target.SetX)

let Y =
Attributes.defineMauiProperty "Y" WindowDefaults.Y (fun (target: IFabWindow) -> target.SetY)

[<AutoOpen>]
module WindowBuilders =
type Fabulous.Maui.View with
Expand All @@ -21,3 +83,86 @@ module WindowBuilders =
Window.WidgetKey,
AttributesBundle(StackList.empty(), ValueSome [| Window.Content.WithValue(content.Compile()) |], ValueNone)
)

[<Extension>]
type WindowModifiers =
[<Extension>]
static member inline flowDirection(this: WidgetBuilder<'msg, #IFabWindow>, value: FlowDirection) =
this.AddScalar(Window.FlowDirection.WithValue(value))

[<Extension>]
static member inline height(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.Height.WithValue(value))

[<Extension>]
static member inline maximumHeight(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.MaximumHeight.WithValue(value))

[<Extension>]
static member inline maximumWidth(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.MaximumWidth.WithValue(value))

[<Extension>]
static member inline minimumHeight(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.MinimumHeight.WithValue(value))

[<Extension>]
static member inline minimumWidth(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.MinimumWidth.WithValue(value))

[<Extension>]
static member inline onActivated(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnActivated.WithValue(fun () -> box msg))

[<Extension>]
static member inline onBackButtonClicked(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnBackButtonClicked.WithValue(fun () -> box msg))

[<Extension>]
static member inline onBackgrounding(this: WidgetBuilder<'msg, #IFabWindow>, fn: IPersistedState -> 'msg) =
this.AddScalar(Window.OnBackgrounding.WithValue(fun args -> box (fn args)))

[<Extension>]
static member inline onCreated(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnCreated.WithValue(fun () -> box msg))

[<Extension>]
static member inline onDeactivated(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnDeactivated.WithValue(fun () -> box msg))

[<Extension>]
static member inline onDestroying(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnDestroying.WithValue(fun () -> box msg))

[<Extension>]
static member inline onDisplayDensityChanged(this: WidgetBuilder<'msg, #IFabWindow>, fn: float32 -> 'msg) =
this.AddScalar(Window.OnDisplayDensityChanged.WithValue(fun args -> box (fn args)))

[<Extension>]
static member inline onFrameChanged(this: WidgetBuilder<'msg, #IFabWindow>, fn: Rect -> 'msg) =
this.AddScalar(Window.OnFrameChanged.WithValue(fun args -> box (fn args)))

[<Extension>]
static member inline onResumed(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnResumed.WithValue(fun () -> box msg))

[<Extension>]
static member inline onStopped(this: WidgetBuilder<'msg, #IFabWindow>, msg: 'msg) =
this.AddScalar(Window.OnStopped.WithValue(fun () -> box msg))

[<Extension>]
static member inline visualDiagnosticsOverlay(this: WidgetBuilder<'msg, #IFabWindow>, value: VisualDiagnosticsOverlay) =
this.AddScalar(Window.VisualDiagnosticsOverlay.WithValue(value))

[<Extension>]
static member inline width(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.Width.WithValue(value))

[<Extension>]
static member inline x(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.X.WithValue(value))

[<Extension>]
static member inline y(this: WidgetBuilder<'msg, #IFabWindow>, value: double) =
this.AddScalar(Window.Y.WithValue(value))

0 comments on commit 15c781e

Please sign in to comment.