Skip to content

Commit

Permalink
More ComponentViews
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Sep 26, 2024
1 parent dab70ec commit 8065959
Show file tree
Hide file tree
Showing 26 changed files with 286 additions and 1,175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ namespace Fabulous.Avalonia.Components
open System.Runtime.CompilerServices
open Avalonia.Controls.Primitives
open Fabulous
open Fabulous.Avalonia

type IFabAccessText =
type IFabComponentAccessText =
inherit IFabComponentTextBlock
inherit IFabTextBlock

module AccessText =
let WidgetKey = Widgets.register<AccessText>()

let ShowAccessKey =
Attributes.defineAvaloniaPropertyWithEquality AccessText.ShowAccessKeyProperty

[<AutoOpen>]
module AccessTextBuilders =
type Fabulous.Avalonia.View with
module ComponentAccessTextBuilders =
type Fabulous.Avalonia.Components.View with

/// <summary>Creates a AccessText widget.</summary>
/// <param name="text">The text to display.</param>
/// <param name="showAccessKey">Whether to underline the access key in the text.</param>
static member inline AccessText(text: string, showAccessKey: bool) =
WidgetBuilder<'msg, IFabAccessText>(AccessText.WidgetKey, TextBlock.Text.WithValue(text), AccessText.ShowAccessKey.WithValue(showAccessKey))
WidgetBuilder<unit, IFabComponentAccessText>(
AccessText.WidgetKey,
TextBlock.Text.WithValue(text),
AccessText.ShowAccessKey.WithValue(showAccessKey)
)

type AccessTextModifiers =
type ComponentAccessTextModifiers =
/// <summary>Link a ViewRef to access the direct AccessText 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, IFabAccessText>, value: ViewRef<AccessText>) =
static member inline reference(this: WidgetBuilder<'msg, IFabComponentAccessText>, value: ViewRef<AccessText>) =
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
180 changes: 18 additions & 162 deletions src/Fabulous.Avalonia/ComponentViews/Controls/Primitives/Popup.fs
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))
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,43 @@ open System.Runtime.CompilerServices
open Avalonia.Controls.Primitives
open Avalonia.Layout
open Fabulous
open Fabulous.Avalonia

type IFabScrollBar =
inherit IFabRangeBase

module ScrollBar =
let WidgetKey = Widgets.register<ScrollBar>()

let ViewportSize =
Attributes.defineAvaloniaPropertyWithEquality ScrollBar.ViewportSizeProperty

let Visibility =
Attributes.defineAvaloniaPropertyWithEquality ScrollBar.VisibilityProperty

let Orientation =
Attributes.defineAvaloniaPropertyWithEquality ScrollBar.OrientationProperty

let AllowAutoHide =
Attributes.defineAvaloniaPropertyWithEquality ScrollBar.AllowAutoHideProperty

let HideDelay =
Attributes.defineAvaloniaPropertyWithEquality ScrollBar.HideDelayProperty

let ShowDelay =
Attributes.defineAvaloniaPropertyWithEquality ScrollBar.ShowDelayProperty
type IFabComponentScrollBar =
inherit IFabComponentRangeBase
inherit IFabScrollBar

module ComponentScrollBar =
let Scroll =
Attributes.defineEvent "ScrollBar_Scroll" (fun target -> (target :?> ScrollBar).Scroll)
ComponentAttributes.defineEvent "ScrollBar_Scroll" (fun target -> (target :?> ScrollBar).Scroll)

[<AutoOpen>]
module ScrollBarBuilders =
type Fabulous.Avalonia.View with
module ComponentScrollBarBuilders =
type Fabulous.Avalonia.Components.View with

/// <summary>Creates a ScrollBar widget.</summary>
/// <param name="min">Minimum value.</param>
/// <param name="max">Maximum value.</param>
/// <param name="value">Current value.</param>
/// <param name="fn">Raised when the value changes.</param>
static member inline ScrollBar(min: float, max: float, value: float, fn: float -> 'msg) =
WidgetBuilder<'msg, IFabScrollBar>(
static member inline ScrollBar(min: float, max: float, value: float, fn: float -> unit) =
WidgetBuilder<unit, IFabComponentScrollBar>(
ScrollBar.WidgetKey,
RangeBase.MinimumMaximum.WithValue(struct (min, max)),
RangeBase.ValueChanged.WithValue(ValueEventData.create value fn)
ComponentRangeBase.ValueChanged.WithValue(ComponentValueEventData.create value fn)
)

type ScrollBarModifiers =

/// <summary>Sets the ViewportSize property.</summary>
/// <param name="this">Current widget.</param>
/// <param name="value">The ViewportSize value.</param>
[<Extension>]
static member inline viewportSize(this: WidgetBuilder<'msg, #IFabScrollBar>, value: float) =
this.AddScalar(ScrollBar.ViewportSize.WithValue(value))

/// <summary>Sets the Visibility property.</summary>
/// <param name="this">Current widget.</param>
/// <param name="value">The Visibility value.</param>
[<Extension>]
static member inline visibility(this: WidgetBuilder<'msg, #IFabScrollBar>, value: ScrollBarVisibility) =
this.AddScalar(ScrollBar.Visibility.WithValue(value))

/// <summary>Sets the Orientation property.</summary>
/// <param name="this">Current widget.</param>
/// <param name="value">The Orientation value.</param>
[<Extension>]
static member inline orientation(this: WidgetBuilder<'msg, #IFabScrollBar>, value: Orientation) =
this.AddScalar(ScrollBar.Orientation.WithValue(value))

/// <summary>Sets the AllowAutoHide property.</summary>
/// <param name="this">Current widget.</param>
/// <param name="value">The AllowAutoHide value.</param>
[<Extension>]
static member inline allowAutoHide(this: WidgetBuilder<'msg, #IFabScrollBar>, value: bool) =
this.AddScalar(ScrollBar.AllowAutoHide.WithValue(value))

/// <summary>Sets the HideDelay property.</summary>
/// <param name="this">Current widget.</param>
/// <param name="value">The HideDelay value.</param>
[<Extension>]
static member inline hideDelay(this: WidgetBuilder<'msg, #IFabScrollBar>, value: TimeSpan) =
this.AddScalar(ScrollBar.HideDelay.WithValue(value))

/// <summary>Sets the ShowDelay property.</summary>
/// <param name="this">Current widget.</param>
/// <param name="value">The ShowDelay value.</param>
[<Extension>]
static member inline showDelay(this: WidgetBuilder<'msg, #IFabScrollBar>, value: TimeSpan) =
this.AddScalar(ScrollBar.ShowDelay.WithValue(value))

type ComponentScrollBarModifiers =
/// <summary>Listens to the ScrollBar Scroll event.</summary>
/// <param name="this">Current widget.</param>
/// <param name="fn">Raised when the Scroll value changes.</param>
[<Extension>]
static member inline onScroll(this: WidgetBuilder<'msg, #IFabScrollBar>, fn: ScrollEventArgs -> 'msg) =
this.AddScalar(ScrollBar.Scroll.WithValue(fn))
static member inline onScroll(this: WidgetBuilder<unit, #IFabComponentScrollBar>, fn: ScrollEventArgs -> unit) =
this.AddScalar(ComponentScrollBar.Scroll.WithValue(fn))

/// <summary>Link a ViewRef to access the direct ScrollBar 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, IFabScrollBar>, value: ViewRef<ScrollBar>) =
static member inline reference(this: WidgetBuilder<unit, IFabComponentScrollBar>, value: ViewRef<ScrollBar>) =
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
Loading

0 comments on commit 8065959

Please sign in to comment.