Пример #1
1
func initGUI() {

	/*
		ff := ui.ListFontFamilies()
		for i := 0; i < ff.NumFamilies(); i++ {
			log.Printf("%3d. Font family '%s'\n", i + 1, ff.Family(i))
		}
	*/

	window := ui.NewWindow("Привет мир!", 800, 480, false)
	window.SetMargined(true)

	progress := ui.NewProgressBar()
	labelTime := ui.NewLabel("")

	labelInfo := ui.NewLabel("Info")
	labelInfoButtonHandler := func(b *ui.Button) {
		labelInfo.SetText("Click button " + b.Text())
	}

	hbox := ui.NewHorizontalBox()
	hbox.SetPadded(true)

	hbox.Append(func() *ui.Box {
		box := ui.NewVerticalBox()
		box.SetPadded(true)

		box.Append(func() *ui.Button {
			button := ui.NewButton("Button 1")
			button.OnClicked(labelInfoButtonHandler)
			return button
		}(), false)
		box.Append(func() *ui.Button {
			button := ui.NewButton("Button 2")
			button.OnClicked(labelInfoButtonHandler)
			return button
		}(), false)
		box.Append(func() *ui.Button {
			button := ui.NewButton("Button 3")
			button.OnClicked(labelInfoButtonHandler)
			return button
		}(), false)
		box.Append(ui.NewHorizontalSeparator(), false)

		label := ui.NewLabel("It's all")
		box.Append(label, true)

		box.Append(func() *ui.Button {
			button := ui.NewButton("Exit")
			button.OnClicked(func(*ui.Button) {
				ui.Quit()
			})
			return button
		}(), false)

		return box
	}(), false)

	areaHandler := NewHistogramAreaHandler(20)
	area := ui.NewArea(areaHandler)

	hbox.Append(func() *ui.Box {
		box := ui.NewVerticalBox()
		box.SetPadded(true)
		box.Append(labelInfo, false)
		box.Append(labelTime, false)

		tab := ui.NewTab()
		tab.Append("Histogram demo", area)
		tab.Append("Controls demo", func() *ui.Box {
			box := ui.NewVerticalBox()
			box.SetPadded(true)

			box.Append(ui.NewEntry(), false)
			box.Append(ui.NewCheckbox("Check it"), false)
			box.Append(func() *ui.RadioButtons {
				radio := ui.NewRadioButtons()
				radio.Append("Radio button 1")
				radio.Append("Radio button 2")
				radio.Append("Radio button 3")
				return radio
			}(), false)
			box.Append(func() *ui.Group {
				combo := ui.NewCombobox()
				combo.Append("First")
				combo.Append("Second")
				combo.Append("Third")
				combo.Append("Fourth")
				combo.OnSelected(func(cb *ui.Combobox) {
					ui.MsgBoxError(window, "OnSelected", "Line #"+strconv.Itoa(cb.Selected()+1))
				})
				group := ui.NewGroup("Can't get text, only index")
				group.SetChild(combo)
				return group
			}(), false)
			box.Append(ui.NewSlider(0, 100), false)
			box.Append(ui.NewSpinbox(0, 10), false)
			box.Append(ui.NewDatePicker(), false)
			box.Append(ui.NewDateTimePicker(), false)

			return box
		}())
		tab.Append("Tab 3", ui.NewLabel("At tab 3"))
		box.Append(tab, true)

		box.Append(progress, false)

		return box
	}(), true)

	window.SetChild(hbox)

	window.OnClosing(func(*ui.Window) bool {
		log.Println("Window close")
		ui.Quit()
		return true
	})
	window.Show()

	progressCounter := 0
	progressTicker := time.NewTicker(time.Millisecond * 50)
	go func() {
		for _ = range progressTicker.C {
			// Что бы записать значение в виджет используем потокобезопасный вызов
			ui.QueueMain(func() {
				progress.SetValue(progressCounter)
			})
			progressCounter++
			if progressCounter > 100 {
				progressCounter = 0
			}
		}
	}()

	timeTicker := time.NewTicker(time.Millisecond * 10)
	go func() {
		for t := range timeTicker.C {
			// Что бы записать значение в виджет используем потокобезопасный вызов
			ui.QueueMain(func() {
				labelTime.SetText(t.Format(time.StampMilli))
			})
		}
	}()

	hystogrammTicker := time.NewTicker(time.Millisecond * 500)
	go func() {
		for _ = range hystogrammTicker.C {
			// Что бы записать значение в виджет используем потокобезопасный вызов
			ui.QueueMain(func() {
				areaHandler.Push(rand.Intn(100))
				area.QueueRedrawAll()
			})
		}
	}()

	log.Println("InitGUI done")
}
Пример #2
0
func showPreview(img *image.RGBA) {
	w2 = ui.NewWindow("Stuff", img.Bounds().Dx(), img.Bounds().Dy(), ui.NewArea(img.Bounds().Dx(), img.Bounds().Dy(), (*imageArea)(img)))
	w2.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w2.Show()
}
Пример #3
0
// Creates a new UIDoc control. This can be added to a ui.Window, ui.Box, etc.
func New() *UIDoc {
	r := &UIDoc{}
	r.area = ui.NewScrollingArea(&drawHandler{r}, 400, 400)
	r.measureArea = ui.NewArea(&measureHandler{r})
	r.box = ui.NewVerticalBox()
	toolbarContainer := ui.NewHorizontalBox()
	toolbarHeightRetainer := ui.NewHorizontalSeparator()
	toolbarContainer.Append(toolbarHeightRetainer, false)
	toolbarContainer.Append(r.measureArea, true)
	r.box.Append(r.area, true)
	r.box.Append(toolbarContainer, false)
	return r
}
Пример #4
0
// Creates the tab for the specified song. Calls updateLabels and updateCover
// with the create argument to true. Defines two grids : igrid and ogrid
// igrid contains all the labels
// ogrid groups the area containing the image handler and the igrid
func (s *song) createTab() {
	s.generateLabels(true)
	s.generateCover(true)
	// Inside Grid
	igrid := ui.NewGrid()
	igrid.Add(s.title, nil, ui.South, false, ui.LeftTop, false, ui.LeftTop, 1, 1)
	igrid.Add(s.album, nil, ui.South, false, ui.LeftTop, false, ui.LeftTop, 1, 1)
	igrid.Add(s.artist, nil, ui.South, false, ui.LeftTop, false, ui.LeftTop, 1, 1)
	igrid.Add(s.year, nil, ui.South, false, ui.LeftTop, false, ui.LeftTop, 1, 1)
	// Outside Grid
	ogrid := ui.NewGrid()
	ogrid.Add(ui.NewArea(100, 100, &areaHandler{s.cover}), nil, ui.South, false, ui.LeftTop, true, ui.LeftTop, 1, 1)
	ogrid.Add(igrid, nil, ui.East, false, ui.LeftTop, true, ui.LeftTop, 1, 1)
	s.stack = ui.NewVerticalStack(ogrid)
}
Пример #5
0
func initGUI() {
	b := ui.NewButton("Button")
	c := ui.NewCheckbox("Checkbox")
	tf := ui.NewTextField()
	tf.SetText("Text Field")
	pf := ui.NewPasswordField()
	pf.SetText("Password Field")
	l := ui.NewStandaloneLabel("Label")

	t := ui.NewTab()
	t.Append("Tab 1", ui.Space())
	t.Append("Tab 2", ui.Space())
	t.Append("Tab 3", ui.Space())

	g := ui.NewGroup("Group", ui.Space())

	icons, il := readIcons()
	table := ui.NewTable(reflect.TypeOf(icons[0]))
	table.Lock()
	d := table.Data().(*[]icon)
	*d = icons
	table.Unlock()
	table.LoadImageList(il)

	area := ui.NewArea(200, 200, &areaHandler{tileImage(20)})

	stack := ui.NewVerticalStack(
		b,
		c,
		tf,
		pf,
		l,
		t,
		g,
		table,
		area)
	stack.SetStretchy(5)
	stack.SetStretchy(6)
	stack.SetStretchy(7)
	stack.SetStretchy(8)

	w = ui.NewWindow("Window", 400, 500, stack)
	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w.Show()
}
Пример #6
0
func main() {
	simulation.Init()

	timer_10ms := time.Tick(10 * time.Millisecond)

	go ui.Do(func() {
		widthFloat := float64(inWidth * dpi)
		heightFloat := float64(inHeight * dpi)
		width := int(widthFloat)
		height := int(heightFloat)

		// Give ourselves a drawable canvas:
		canvas := &canvasArea{
			img: image.NewRGBA(image.Rect(0, 0, width, height)),
		}
		area := ui.NewArea(width, height, canvas)
		w := ui.NewWindow("e-minor v2", width+8*2, height+28*2, area)
		w.SetMargined(false)
		w.OnClosing(func() bool {
			ui.Stop()
			return true
		})

		w.Show()

		// This *should* be in the main UI message loop, but the 'ui' package does not expose the message loop.
		go func() {
			for {
				select {
				case <-timer_10ms:
					simulation.Timer_10msec()
				default:
					simulation.Handle()
				}
			}
		}()
	})

	err := ui.Go()
	if err != nil {
		panic(err)
	}
}