Example #1
0
func run() error {
	engine := qml.NewEngine()

	model, err := Read("model/gopher.obj")
	if err != nil {
		return err
	}

	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(g *Gopher, obj qml.Object) {
			g.Object = obj
			g.model = model
		},
	}})

	component, err := engine.LoadFile(filename)
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Set("x", 560)
	win.Set("y", 320)
	win.Show()
	win.Wait()
	return nil
}
Example #2
0
func run() error {
	engine := qml.NewEngine()
	engine.AddImageProvider("pwd", func(id string, width, height int) image.Image {
		f, err := os.Open(id)
		if err != nil {
			panic(err)
		}
		defer f.Close()
		image, err := png.Decode(f)
		if err != nil {
			panic(err)
		}
		return image
	})

	component, err := engine.LoadFile("imgprovider.qml")
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Show()
	win.Wait()

	return nil
}
Example #3
0
File: main.go Project: hbdlb/qml-1
func run() error {
	engine := qml.NewEngine()
	component, err := engine.LoadFile("clocks.qml")
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Show()
	win.Wait()

	return nil
}
Example #4
0
File: hello.go Project: hbdlb/qml-1
func run() error {
	engine := qml.NewEngine()
	engine.On("quit", func() { os.Exit(0) })

	component, err := engine.LoadString("hello.qml", qmlHello)
	if err != nil {
		return err
	}
	window := component.CreateWindow(nil)
	window.Show()
	window.Wait()
	return nil
}
Example #5
0
func run() error {
	engine := qml.NewEngine()

	engine.On("quit", func() { os.Exit(0) })

	component, err := engine.LoadFile(os.Args[1])
	if err != nil {
		return err
	}
	window := component.CreateWindow(nil)
	window.Show()
	window.Wait()
	return nil
}
Example #6
0
func run() error {
	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(r *GoRect, obj qml.Object) { r.Object = obj },
	}})

	engine := qml.NewEngine()
	component, err := engine.LoadFile("painting.qml")
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Show()
	win.Wait()
	return nil
}
Example #7
0
func run() error {
	engine := qml.NewEngine()
	component, err := engine.LoadString("webview.qml", webview)
	if err != nil {
		return err
	}
	ctrl := &Control{
		done: make(chan error),
		win:  component.CreateWindow(nil),
	}
	engine.Context().SetVar("ctrl", ctrl)
	root := ctrl.win.Root()
	root.On("loadingChanged", ctrl.Snapshot)
	root.Set("url", os.Args[1])
	ctrl.win.Show()
	return <-ctrl.done
}
Example #8
0
func run() error {
	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(v *GoType, obj qml.Object) {},
	}, {
		Init: func(v *GoSingleton, obj qml.Object) { v.Event = "birthday" },

		Singleton: true,
	}})

	engine := qml.NewEngine()
	component, err := engine.LoadFile("customtype.qml")
	if err != nil {
		return err
	}

	value := component.Create(nil)
	fmt.Println("Text is:", value.Interface().(*GoType).Text)
	return nil
}
Example #9
0
func run() error {
	engine := qml.NewEngine()
	colors := &Colors{}
	engine.Context().SetVar("colors", colors)
	component, err := engine.LoadFile("delegate.qml")
	if err != nil {
		return err
	}
	window := component.CreateWindow(nil)
	window.Show()
	go func() {
		n := func() uint8 { return uint8(rand.Intn(256)) }
		for i := 0; i < 100; i++ {
			colors.Add(color.RGBA{n(), n(), n(), 0xff})
			time.Sleep(1 * time.Second)
		}
	}()
	window.Wait()
	return nil
}
Example #10
0
func run() error {
	engine := qml.NewEngine()

	base, err := engine.LoadFile("base.qml")
	if err != nil {
		return err
	}
	rect, err := engine.LoadFile("rect.qml")
	if err != nil {
		return err
	}

	win := base.CreateWindow(nil)
	obj := rect.Create(nil)

	obj.Set("parent", win.Root())

	win.Show()
	win.Wait()

	return nil
}
Example #11
0
File: main.go Project: hbdlb/qml-1
func run() error {
	engine := qml.NewEngine()
	component, err := engine.LoadFile("particle.qml")
	if err != nil {
		return err
	}

	ctrl := Control{Message: "Hello from Go!"}

	context := engine.Context()
	context.SetVar("ctrl", &ctrl)

	window := component.CreateWindow(nil)

	ctrl.Root = window.Root()

	rand.Seed(time.Now().Unix())

	window.Show()
	window.Wait()

	return nil
}