-
-
Save atsushieno/8f93bb13177677c78c9a to your computer and use it in GitHub Desktop.
Xwt + Observable.FromEventPattern<T>() in F#
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
// Learn more about F# at http://fsharp.net | |
// See the 'F# Tutorial' project for more help. | |
open System | |
open Xwt | |
open System.Reactive.Linq | |
type MyWindow () as this = | |
inherit Window () | |
do | |
this.Closed.Add (fun ea -> Application.Exit ()) | |
let label = new Label () | |
let f = new Frame (WidthRequest = 200.0, HeightRequest = 200.0) | |
let eo = Observable.FromEventPattern<MouseMovedEventArgs> (f, "MouseMoved") | |
let sample = eo.Sample (TimeSpan.FromSeconds 1.0) | |
sample.Subscribe (fun v -> label.Text <- v.EventArgs.Position.ToString ()) | |
let vb = new VBox () | |
vb.PackStart (f) | |
vb.PackStart (label) | |
this.Content <- vb | |
[<EntryPoint>] | |
let main argv = | |
printfn "%A" argv | |
Application.Initialize () | |
let x = new MyWindow () | |
x.Show () | |
Application.Run () | |
0 // return an integer exit code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment