Skip to content

Commit

Permalink
BoolTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Nov 21, 2024
1 parent 4c351c7 commit 59059b3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 27 deletions.
88 changes: 62 additions & 26 deletions samples/Gallery/Pages/ToolTipPage.fs
Original file line number Diff line number Diff line change
@@ -1,37 +1,73 @@
namespace Gallery

open Avalonia.Interactivity
open Avalonia.Media
open Avalonia.Controls
open Fabulous.Avalonia
open Fabulous

open type Fabulous.Avalonia.View

module ToolTipPage =
type Model = { IsOpen: bool }

type Msg = OnLoaded of RoutedEventArgs

let init () = { IsOpen = false }

let targetRef = ViewRef<Border>()

let update msg model =
match msg with
| OnLoaded _ ->
ToolTip.AddToolTipOpeningHandler(targetRef.Value, (fun sender args -> printfn "Opening"))
ToolTip.AddToolTipClosingHandler(targetRef.Value, (fun sender args -> printfn "Closing"))
model

let program =
Program.stateful init update
|> Program.withTrace(fun (format, args) -> System.Diagnostics.Debug.WriteLine(format, box args))
|> Program.withExceptionHandler(fun ex ->
#if DEBUG
printfn $"Exception: %s{ex.ToString()}"
false
#else
true
#endif
)

let view () =
VStack(spacing = 15.) {
Border(TextBlock("Hover over me!"))
.padding(10.)
.background(SolidColorBrush(Colors.LightGray))
.tip(ToolTip("Im a tooltip!"))

Border(TextBlock("Hover over me!"))
.padding(10.)
.background(SolidColorBrush(Colors.LightGray))
.tip(ToolTip("Im a tooltip!").isOpen(true))
.tooltipPlacement(PlacementMode.Top)


Border(TextBlock("Hover over me!"))
.padding(10.)
.background(SolidColorBrush(Colors.LightGray))
.tip(
ToolTip(
VStack() {
TextBlock("ToolTip")
TextBlock("A control which pops up a hint when a control is hovered")
}
Component("ToolTipPage") {
let! _ = Context.Mvu program

VStack(spacing = 15.) {
Border(TextBlock("Hover over me!"))
.padding(10.)
.background(SolidColorBrush(Colors.LightGray))
.tip(ToolTip("Im a tooltip!"))
.reference(targetRef)

Border(TextBlock("Hover over me!"))
.padding(10.)
.background(SolidColorBrush(Colors.LightGray))
.tip(ToolTip("Im a tooltip!").isOpen(true))
.tooltipPlacement(PlacementMode.Top)


Border(TextBlock("Hover over me!"))
.padding(10.)
.background(SolidColorBrush(Colors.LightGray))
.tip(
ToolTip(
VStack() {
TextBlock("ToolTip")
TextBlock("A control which pops up a hint when a control is hovered")
}
)
)
)
.tooltipShowDelay(1000)
.tooltipHorizontalOffset(50.)
.tooltipVerticalOffset(50.)
.tooltipShowDelay(1000)
.tooltipHorizontalOffset(50.)
.tooltipVerticalOffset(50.)
}
|> _.onLoaded(OnLoaded)
}
2 changes: 1 addition & 1 deletion src/Fabulous.Avalonia/Views/MenuItems/TreeViewItem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ type TreeViewItemModifiers =
/// <param name="this">Current widget.</param>
/// <param name="value">Whether the TreeViewItem is expanded.</param>
[<Extension>]
static member inline isExpanded(this: WidgetBuilder<'msg, IFabTreeViewItem>, value: bool) =
static member inline isExpanded(this: WidgetBuilder<'msg, #IFabTreeViewItem>, value: bool) =
this.AddScalar(TreeViewItem.IsExpanded.WithValue(value))
21 changes: 21 additions & 0 deletions src/Fabulous.Avalonia/Views/Styling/Transition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,27 @@ module VectorTransitionBuilders =
TransitionBase.Duration.WithValue(duration)
)

type IFabBoolTransition =
inherit IFabTransition

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

[<AutoOpen>]
module BoolTransitionBuilders =

type Fabulous.Avalonia.View with

/// <summary>Creates a BoolTransition widget.</summary>
/// <param name="property">The property to animate.</param>
/// <param name="duration">The duration of the animation.</param>
static member BoolTransition(property: AvaloniaProperty, duration: TimeSpan) =
WidgetBuilder<'msg, IFabBoolTransition>(
BoolTransition.WidgetKey,
TransitionBase.Property.WithValue(property),
TransitionBase.Duration.WithValue(duration)
)

type IFabEffectTransition =
inherit IFabTransition

Expand Down

0 comments on commit 59059b3

Please sign in to comment.