-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathViewModelBase.fs
71 lines (56 loc) · 2.25 KB
/
ViewModelBase.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace FVim
open def
open common
open wcwidth
open log
open ReactiveUI
open Avalonia
open System
open System.Reactive.Disposables
open System.Runtime.CompilerServices
[<Extension>]
type ActivatableExt() =
[<Extension>]
static member inline Watch (this: IActivatableView, xs: IDisposable seq) =
this.WhenActivated(fun (disposables: CompositeDisposable) ->
xs |> Seq.iter (fun x -> x.DisposeWith(disposables) |> ignore)) |> ignore
[<Extension>]
static member inline Watch (this: IActivatableViewModel, xs: IDisposable seq) =
this.WhenActivated(fun (disposables: CompositeDisposable) ->
xs |> Seq.iter (fun x -> x.DisposeWith(disposables) |> ignore)) |> ignore
[<Extension>]
static member inline Do (this: IActivatableView, fn: unit -> unit) =
do fn()
Disposable.Empty
[<Extension>]
static member inline Do (this: IActivatableViewModel, fn: unit -> unit) =
do fn()
Disposable.Empty
type ViewModelBase(_x: float option, _y: float option, _w: float option, _h: float option) =
inherit ReactiveObject()
let activator = new ViewModelActivator()
let mutable m_x = _d 0.0 _x
let mutable m_y = _d 0.0 _y
let mutable m_w = _d 0.0 _w
let mutable m_h = _d 0.0 _h
let mutable m_tick = 0
new() = ViewModelBase(None, None, None, None)
new(_posX: float option, _posY: float option, _size: Size option) = ViewModelBase(_posX, _posY, Option.map(fun (s: Size) -> s.Width) _size, Option.map(fun (s: Size) -> s.Height) _size)
interface IActivatableViewModel with
member __.Activator = activator
member this.X
with get() : float = m_x
and set(v) = ignore <| this.RaiseAndSetIfChanged(&m_x, v, "X")
member this.Y
with get() : float = m_y
and set(v) = ignore <| this.RaiseAndSetIfChanged(&m_y, v, "Y")
member this.Height
with get(): float = m_h
and set(v) = ignore <| this.RaiseAndSetIfChanged(&m_h, v, "Height")
member this.Width
with get(): float = m_w
and set(v) = ignore <| this.RaiseAndSetIfChanged(&m_w, v, "Width")
member this.RenderTick
with get() : int = m_tick
and set(v) =
ignore <| this.RaiseAndSetIfChanged(&m_tick, v, "RenderTick")