-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
193 additions
and
741 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 18 additions & 162 deletions
180
src/Fabulous.Avalonia/ComponentViews/Controls/Primitives/Popup.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,202 +1,58 @@ | ||
namespace Fabulous.Avalonia.Components | ||
|
||
open System | ||
open System.Runtime.CompilerServices | ||
open Avalonia | ||
open Avalonia.Controls | ||
open Avalonia.Controls.Primitives | ||
open Avalonia.Controls.Primitives.PopupPositioning | ||
open Avalonia.Input | ||
open Fabulous | ||
open Fabulous.Avalonia | ||
open Fabulous.StackAllocatedCollections.StackList | ||
|
||
type IFabPopup = | ||
inherit IFabControl | ||
|
||
module Popup = | ||
let WidgetKey = Widgets.register<Popup>() | ||
|
||
let WindowManagerAddShadowHint = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.WindowManagerAddShadowHintProperty | ||
|
||
let Child = Attributes.defineAvaloniaPropertyWidget Popup.ChildProperty | ||
|
||
let InheritsTransform = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.InheritsTransformProperty | ||
|
||
let IsOpen = Attributes.defineAvaloniaPropertyWithEquality Popup.IsOpenProperty | ||
|
||
let PlacementAnchor = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.PlacementAnchorProperty | ||
|
||
let PlacementConstraintAdjustment = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.PlacementConstraintAdjustmentProperty | ||
|
||
let PlacementGravity = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.PlacementGravityProperty | ||
|
||
let Placement = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.PlacementProperty | ||
|
||
let PlacementTarget = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.PlacementTargetProperty | ||
|
||
let PlacementRect = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.PlacementRectProperty | ||
|
||
let OverlayDismissEventPassThrough = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.OverlayDismissEventPassThroughProperty | ||
|
||
let HorizontalOffset = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.HorizontalOffsetProperty | ||
|
||
let IsLightDismissEnabled = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.IsLightDismissEnabledProperty | ||
|
||
let VerticalOffset = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.VerticalOffsetProperty | ||
|
||
let Topmost = Attributes.defineAvaloniaPropertyWithEquality Popup.TopmostProperty | ||
|
||
let OverlayInputPassThroughElement = | ||
Attributes.defineAvaloniaPropertyWithEquality Popup.OverlayInputPassThroughElementProperty | ||
type IFabComponentPopup = | ||
inherit IFabComponentControl | ||
inherit IFabPopup | ||
|
||
module ComponentPopup = | ||
let Closed = | ||
Attributes.defineEvent "Popup_Closed" (fun target -> (target :?> Popup).Closed) | ||
ComponentAttributes.defineEvent "Popup_Closed" (fun target -> (target :?> Popup).Closed) | ||
|
||
let Opened = | ||
Attributes.defineEventNoArg "Popup_Opened" (fun target -> (target :?> Popup).Opened) | ||
ComponentAttributes.defineEventNoArg "Popup_Opened" (fun target -> (target :?> Popup).Opened) | ||
|
||
[<AutoOpen>] | ||
module PopupBuilders = | ||
type Fabulous.Avalonia.View with | ||
module ComponentPopupBuilders = | ||
type Fabulous.Avalonia.Components.View with | ||
|
||
/// <summary>Creates a Popup widget.</summary> | ||
/// <param name="isOpen">Whether the popup is open or not.</param> | ||
/// <param name="content">The content of the popup.</param> | ||
static member Popup(isOpen: bool, content: WidgetBuilder<'msg, #IFabControl>) = | ||
WidgetBuilder<'msg, IFabPopup>( | ||
static member Popup(isOpen: bool, content: WidgetBuilder<unit, #IFabComponentControl>) = | ||
WidgetBuilder<unit, IFabComponentPopup>( | ||
Popup.WidgetKey, | ||
AttributesBundle(StackList.one(Popup.IsOpen.WithValue(isOpen)), ValueSome [| Popup.Child.WithValue(content.Compile()) |], ValueNone) | ||
) | ||
|
||
type PopupModifiers = | ||
/// <summary>Sets the WindowManagerAddShadowHint property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The WindowManagerAddShadowHint value.</param> | ||
[<Extension>] | ||
static member inline windowManagerAddShadowHint(this: WidgetBuilder<'msg, #IFabPopup>, value: bool) = | ||
this.AddScalar(Popup.WindowManagerAddShadowHint.WithValue(value)) | ||
|
||
/// <summary>Sets the InheritsTransform property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The InheritsTransform value.</param> | ||
[<Extension>] | ||
static member inline inheritsTransform(this: WidgetBuilder<'msg, #IFabPopup>, value: bool) = | ||
this.AddScalar(Popup.InheritsTransform.WithValue(value)) | ||
|
||
/// <summary>Sets the PlacementAnchor property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The PlacementAnchor value.</param> | ||
[<Extension>] | ||
static member inline placementAnchor(this: WidgetBuilder<'msg, #IFabPopup>, value: PopupAnchor) = | ||
this.AddScalar(Popup.PlacementAnchor.WithValue(value)) | ||
|
||
/// <summary>Sets the PlacementConstraintAdjustment property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The PlacementConstraintAdjustment value.</param> | ||
[<Extension>] | ||
static member inline placementConstraintAdjustment(this: WidgetBuilder<'msg, #IFabPopup>, value: PopupPositionerConstraintAdjustment) = | ||
this.AddScalar(Popup.PlacementConstraintAdjustment.WithValue(value)) | ||
|
||
/// <summary>Sets the PlacementGravity property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The PlacementGravity value.</param> | ||
[<Extension>] | ||
static member inline placementGravity(this: WidgetBuilder<'msg, #IFabPopup>, value: PopupGravity) = | ||
this.AddScalar(Popup.PlacementGravity.WithValue(value)) | ||
|
||
/// <summary>Sets the Placement property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The Placement value.</param> | ||
[<Extension>] | ||
static member inline placement(this: WidgetBuilder<'msg, #IFabPopup>, value: PlacementMode) = | ||
this.AddScalar(Popup.Placement.WithValue(value)) | ||
|
||
/// <summary>Sets the PlacementTarget property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The PlacementTarget value.</param> | ||
[<Extension>] | ||
static member inline placementTarget(this: WidgetBuilder<'msg, #IFabPopup>, value: ViewRef<#Control>) = | ||
match value.TryValue with | ||
| None -> this | ||
| Some value -> this.AddScalar(Popup.PlacementTarget.WithValue(value)) | ||
|
||
/// <summary>Sets the PlacementRect property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The PlacementRect value.</param> | ||
[<Extension>] | ||
static member inline placementRect(this: WidgetBuilder<'msg, #IFabPopup>, value: Rect) = | ||
this.AddScalar(Popup.PlacementRect.WithValue(value)) | ||
|
||
/// <summary>Sets the OverlayDismissEventPassThrough property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The OverlayDismissEventPassThrough value.</param> | ||
[<Extension>] | ||
static member inline overlayDismissEventPassThrough(this: WidgetBuilder<'msg, #IFabPopup>, value: bool) = | ||
this.AddScalar(Popup.OverlayDismissEventPassThrough.WithValue(value)) | ||
|
||
/// <summary>Sets the HorizontalOffset property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The HorizontalOffset value.</param> | ||
[<Extension>] | ||
static member inline horizontalOffset(this: WidgetBuilder<'msg, #IFabPopup>, value: float) = | ||
this.AddScalar(Popup.HorizontalOffset.WithValue(value)) | ||
|
||
/// <summary>Sets the IsLightDismissEnabled property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The IsLightDismissEnabled value.</param> | ||
[<Extension>] | ||
static member inline isLightDismissEnabled(this: WidgetBuilder<'msg, #IFabPopup>, value: bool) = | ||
this.AddScalar(Popup.IsLightDismissEnabled.WithValue(value)) | ||
|
||
/// <summary>Sets the VerticalOffset property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The VerticalOffset value.</param> | ||
[<Extension>] | ||
static member inline verticalOffset(this: WidgetBuilder<'msg, #IFabPopup>, value: float) = | ||
this.AddScalar(Popup.VerticalOffset.WithValue(value)) | ||
|
||
/// <summary>Sets the Topmost property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The Topmost value.</param> | ||
[<Extension>] | ||
static member inline topmost(this: WidgetBuilder<'msg, #IFabPopup>, value: bool) = | ||
this.AddScalar(Popup.Topmost.WithValue(value)) | ||
|
||
/// <summary>Sets the OverlayInputPassThroughElement property.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The OverlayInputPassThroughElement value.</param> | ||
[<Extension>] | ||
static member inline overlayInputPassThroughElement(this: WidgetBuilder<'msg, #IFabPopup>, value: IInputElement) = | ||
this.AddScalar(Popup.OverlayInputPassThroughElement.WithValue(value)) | ||
|
||
type ComponentPopupModifiers = | ||
/// <summary>Listens to the Popup Closed event.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="msg">Raised when the Popup is closed.</param> | ||
[<Extension>] | ||
static member inline onClosed(this: WidgetBuilder<'msg, #IFabPopup>, msg: 'msg) = | ||
this.AddScalar(Popup.Closed.WithValue(fun _ -> box msg)) | ||
static member inline onClosed(this: WidgetBuilder<unit, #IFabComponentPopup>, msg: unit -> unit) = | ||
this.AddScalar(ComponentPopup.Closed.WithValue(fun _ -> msg())) | ||
|
||
/// <summary>Listens to the Popup Opened event.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="msg">Raised when the Popup is opened.</param> | ||
[<Extension>] | ||
static member inline onOpened(this: WidgetBuilder<'msg, #IFabPopup>, msg: 'msg) = | ||
this.AddScalar(Popup.Opened.WithValue(MsgValue msg)) | ||
static member inline onOpened(this: WidgetBuilder<unit, #IFabComponentPopup>, msg: unit -> unit) = | ||
this.AddScalar(ComponentPopup.Opened.WithValue(msg)) | ||
|
||
/// <summary>Link a ViewRef to access the direct Popup control instance.</summary> | ||
/// <param name="this">Current widget.</param> | ||
/// <param name="value">The ViewRef instance that will receive access to the underlying control.</param> | ||
[<Extension>] | ||
static member inline reference(this: WidgetBuilder<'msg, IFabPopup>, value: ViewRef<Popup>) = | ||
static member inline reference(this: WidgetBuilder<unit, IFabComponentPopup>, value: ViewRef<Popup>) = | ||
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.