Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atsushieno/8f93bb13177677c78c9a to your computer and use it in GitHub Desktop.
Save atsushieno/8f93bb13177677c78c9a to your computer and use it in GitHub Desktop.
Xwt + Observable.FromEventPattern<T>() in F#
// 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