Ejemplo n.º 1
0
func changeTheme(lb *ui.ListBox, btn *ui.Button, tp int) {
	items := ui.ThemeNames()
	dlgType := ui.SelectDialogRadio
	if tp == 1 {
		dlgType = ui.SelectDialogList
	}

	curr := -1
	for i, tName := range items {
		if tName == ui.CurrentTheme() {
			curr = i
			break
		}
	}

	selDlg := ui.CreateSelectDialog("Choose a theme", items, curr, dlgType)
	selDlg.OnClose(func() {
		switch selDlg.Result() {
		case ui.DialogButton1:
			idx := selDlg.Value()
			lb.AddItem(fmt.Sprintf("Selected item: %v", selDlg.Value()))
			lb.SelectItem(lb.ItemCount() - 1)
			if idx != -1 {
				ui.SetCurrentTheme(items[idx])
			}
		}

		btn.SetEnabled(true)
		// ask the composer to repaint all windows
		ui.PutEvent(ui.Event{Type: ui.EventRedraw})
	})
}
Ejemplo n.º 2
0
func createView() *ui.BarChart {

	view := ui.AddWindow(0, 0, 10, 7, "BarChart Demo")
	bch := ui.CreateBarChart(view, 40, 12, 1)

	frmChk := ui.CreateFrame(view, 8, 5, ui.BorderNone, ui.Fixed)
	frmChk.SetPack(ui.Vertical)
	chkTitles := ui.CreateCheckBox(frmChk, ui.AutoSize, "Show Titles", ui.Fixed)
	chkMarks := ui.CreateCheckBox(frmChk, ui.AutoSize, "Show Marks", ui.Fixed)
	chkTitles.SetState(1)
	chkLegend := ui.CreateCheckBox(frmChk, ui.AutoSize, "Show Legend", ui.Fixed)
	chkValues := ui.CreateCheckBox(frmChk, ui.AutoSize, "Show Values", ui.Fixed)
	chkValues.SetState(1)
	chkFixed := ui.CreateCheckBox(frmChk, ui.AutoSize, "Fixed Width", ui.Fixed)
	chkGap := ui.CreateCheckBox(frmChk, ui.AutoSize, "No Gap", ui.Fixed)
	chkMulti := ui.CreateCheckBox(frmChk, ui.AutoSize, "MultiColored", ui.Fixed)
	chkCustom := ui.CreateCheckBox(frmChk, ui.AutoSize, "Custom Colors", ui.Fixed)

	ui.ActivateControl(view, chkTitles)

	chkTitles.OnChange(func(state int) {
		if state == 0 {
			chkMarks.SetEnabled(false)
			bch.SetShowTitles(false)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		} else if state == 1 {
			chkMarks.SetEnabled(true)
			bch.SetShowTitles(true)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		}
	})
	chkMarks.OnChange(func(state int) {
		if state == 0 {
			bch.SetShowMarks(false)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		} else if state == 1 {
			bch.SetShowMarks(true)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		}
	})
	chkLegend.OnChange(func(state int) {
		if state == 0 {
			bch.SetLegendWidth(0)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		} else if state == 1 {
			bch.SetLegendWidth(10)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		}
	})
	chkValues.OnChange(func(state int) {
		if state == 0 {
			bch.SetValueWidth(0)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		} else if state == 1 {
			bch.SetValueWidth(5)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		}
	})
	chkMulti.OnChange(func(state int) {
		if state == 0 {
			d := []ui.BarData{
				{Value: 80, Title: "80%"},
				{Value: 50, Title: "50%"},
				{Value: 150, Title: ">100%"},
			}
			bch.SetData(d)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		} else if state == 1 {
			d := []ui.BarData{
				{Value: 80, Title: "80%", Fg: ui.ColorBlue},
				{Value: 50, Title: "50%", Fg: ui.ColorGreen, Ch: 'X'},
				{Value: 150, Title: ">100%", Fg: ui.ColorYellow},
			}
			bch.SetData(d)
			ui.PutEvent(ui.Event{Type: ui.EventRedraw})
		}
	})
	chkFixed.OnChange(func(state int) {
		if state == 0 {
			bch.SetAutoSize(true)
		} else if state == 1 {
			bch.SetAutoSize(false)
		}
		ui.PutEvent(ui.Event{Type: ui.EventRedraw})
	})
	chkGap.OnChange(func(state int) {
		if state == 1 {
			bch.SetBarGap(0)
		} else if state == 0 {
			bch.SetBarGap(1)
		}
		ui.PutEvent(ui.Event{Type: ui.EventRedraw})
	})
	chkCustom.OnChange(func(state int) {
		if state == 0 {
			bch.OnDrawCell(nil)
		} else if state == 1 {
			bch.OnDrawCell(customColored)
		}
		ui.PutEvent(ui.Event{Type: ui.EventRedraw})
	})

	return bch
}
Ejemplo n.º 3
0
func createView() {

	view := ui.AddWindow(0, 0, 20, 7, "Theme Manager Demo")

	frmLeft := ui.CreateFrame(view, 8, 4, ui.BorderNone, 1)
	frmLeft.SetPack(ui.Vertical)
	frmLeft.SetGaps(ui.KeepValue, 1)
	frmLeft.SetPaddings(1, 1)

	frmTheme := ui.CreateFrame(frmLeft, 8, 1, ui.BorderNone, ui.Fixed)
	frmTheme.SetGaps(1, ui.KeepValue)
	checkBox := ui.CreateCheckBox(frmTheme, ui.AutoSize, "Use ListBox", ui.Fixed)
	btnTheme := ui.CreateButton(frmTheme, ui.AutoSize, 4, "Select theme", ui.Fixed)
	ui.CreateFrame(frmLeft, 1, 1, ui.BorderNone, 1)

	frmPb := ui.CreateFrame(frmLeft, 8, 1, ui.BorderNone, ui.Fixed)
	ui.CreateLabel(frmPb, 1, 1, "[", ui.Fixed)
	pb := ui.CreateProgressBar(frmPb, 20, 1, 1)
	pb.SetLimits(0, 10)
	pb.SetTitle("{{value}} of {{max}}")
	ui.CreateLabel(frmPb, 1, 1, "]", ui.Fixed)

	edit := ui.CreateEditField(frmLeft, 5, "0", ui.Fixed)

	frmEdit := ui.CreateFrame(frmLeft, 8, 1, ui.BorderNone, ui.Fixed)
	frmEdit.SetPaddings(1, 1)
	frmEdit.SetGaps(1, ui.KeepValue)
	btnSet := ui.CreateButton(frmEdit, ui.AutoSize, 4, "Set", ui.Fixed)
	btnStep := ui.CreateButton(frmEdit, ui.AutoSize, 4, "Step", ui.Fixed)
	ui.CreateFrame(frmEdit, 1, 1, ui.BorderNone, 1)
	btnQuit := ui.CreateButton(frmEdit, ui.AutoSize, 4, "Quit", ui.Fixed)

	logBox := ui.CreateListBox(view, 28, 5, ui.Fixed)

	ui.ActivateControl(view, edit)

	edit.OnKeyPress(func(key term.Key) bool {
		if key == term.KeyCtrlM {
			v := edit.Title()
			logBox.AddItem(fmt.Sprintf("New PB value(KeyPress): %v", v))
			logBox.SelectItem(logBox.ItemCount() - 1)
			updateProgress(v, pb)
			return true
		}
		return false
	})
	btnTheme.OnClick(func(ev ui.Event) {
		btnTheme.SetEnabled(false)
		tp := checkBox.State()
		changeTheme(logBox, btnTheme, tp)
	})
	btnSet.OnClick(func(ev ui.Event) {
		v := edit.Title()
		logBox.AddItem(fmt.Sprintf("New ProgressBar value: %v", v))
		logBox.SelectItem(logBox.ItemCount() - 1)
		updateProgress(v, pb)
	})
	btnStep.OnClick(func(ev ui.Event) {
		go pb.Step()
		logBox.AddItem("ProgressBar step")
		logBox.SelectItem(logBox.ItemCount() - 1)
		ui.PutEvent(ui.Event{Type: ui.EventRedraw})
	})
	btnQuit.OnClick(func(ev ui.Event) {
		go ui.Stop()
	})
}