Beispiel #1
0
func (pad *Notepad) init() *Notepad {
	iup.Menu(
		iup.SubMenu("TITLE=File",
			iup.Menu(
				iup.Item(
					iup.Attr("TITLE", "New\tCtrl+N"),
					iup.Attr("TIP", "New File"),
					func(arg *iup.ItemAction) {
						pad.NewFile()
					},
					func(arg *iup.ItemHighlight) {
						pad.ShowStatus(arg.Sender)
					},
				),
				iup.Item(
					iup.Attr("TITLE", "Open\tCtrl+O"),
					iup.Attr("TIP", "Open File"),
					func(arg *iup.ItemAction) {
						runtime.GC()
						pad.Open()
					},
					func(arg *iup.ItemHighlight) {
						pad.ShowStatus(arg.Sender)
					},
				),
				iup.Item(
					iup.Attr("TITLE", "Save\tCtrl+S"),
					iup.Attr("TIP", "Save File"),
					func(arg *iup.ItemAction) {
						pad.Save()
					},
					func(arg *iup.ItemHighlight) {
						pad.ShowStatus(arg.Sender)
					},
				),
				iup.Item(
					iup.Attr("TITLE", "SaveAs"),
					iup.Attr("TIP", "Save File As..."),
					func(arg *iup.ItemAction) {
						pad.SaveAS()
					},
					func(arg *iup.ItemHighlight) {
						pad.ShowStatus(arg.Sender)
					},
				),
				iup.Separator(),
				iup.Item(
					iup.Attr("TITLE", "Quit"),
					iup.Attr("TIP", "Exit Application"),
					func(arg *iup.ItemAction) {
						pad.CheckModify()
						arg.Return = iup.CLOSE
					},
					func(arg *iup.ItemHighlight) {
						pad.ShowStatus(arg.Sender)
					},
				),
			),
		),
		iup.SubMenu("TITLE=Help",
			iup.Menu(
				iup.Item(
					iup.Attr("TITLE", "About"),
					iup.Attr("TIP", "About Notepad"),
					func(arg *iup.ItemAction) {
						iup.Message("About", "\tNotepad 1.0\n\n\[email protected] 2012\t")
					},
					func(arg *iup.ItemHighlight) {
						pad.ShowStatus(arg.Sender)
					},
				),
			),
		),
	).SetName("main_menu")
	pad.edit = iup.Text(
		"EXPAND=YES",
		"MULTILINE=YES",
		"WORDWRAP=YES",
		"TABSIZE=4",
		"NAME=text",
		func(arg *iup.ValueChanged) {
			pad.SetModify()
		},
		func(arg *iup.TextCaret) {
			pad.sts2.SetAttribute("TITLE", fmt.Sprintf("Lin:%d  Col:%d ", arg.Lin, arg.Col))
		},
		func(arg *iup.CommonKeyAny) {
			key := iup.KeyState(arg.Key)
			if !key.IsCtrl() {
				return
			}
			switch key.Key() {
			case 'N':
				pad.NewFile()
			case 'O':
				pad.Open()
			case 'S':
				pad.Save()
			default:
				return
			}
		},
	)
	pad.sts1 = iup.Label(
		"TITLE=Ready",
		"EXPAND=HORIZONTAL",
		"SIZE=50x",
	)
	pad.sts2 = iup.Label(
		"TITLE=\"Lin:1  Col:1\"",
		"EXPAND=NO",
		"SIZE=60x",
	)
	pad.dlg = iup.Dialog(
		iup.Attrs(
			"MENU", "main_menu",
			"TITLE", "Notepad",
			"SHRINK", "YES",
			"SIZE", "300x200",
		),
		iup.Vbox(
			pad.edit,
			iup.Hbox(
				pad.sts1,
				iup.Fill(),
				pad.sts2,
			),
		),
		func(arg *iup.DialogClose) {
			pad.CheckModify()
			arg.Return = iup.CLOSE
		},
	)
	return pad
}
Beispiel #2
0
func ui() {
	var img *iup.Handle
	tree := iup.Tree(
		"EXPANDALL=YES",
	)
	tree.SetName("tree")
	vbox1 := iup.Vbox(
		"TABTITLE=Standard,MARGIN=0x0,GAP=5",
		iup.Frame("TITLE=Frame,EXPAND=YES",
			iup.Vbox(
				iup.Label("TITLE=\"List Label\""),
				iup.List("EXPAND=YES,1=list1", "2=list2", "3=list3"),
			),
		),
		iup.Hbox(
			iup.List("DROPDOWN=YES,EDITBOX=YES", "1=list1", "2=list2"),
			iup.SpinBox(
				iup.Text("VALUE=100"),
			),
			iup.Toggle("TITLE=Toggle,EXPAND=VERTICAL"),
			//			iup.Val("MIN=1,MAX=100"),
		),
		iup.Frame(
			iup.Radio(
				iup.Hbox(
					iup.Toggle("TITLE=1"),
					iup.Toggle("TITLE=2"),
					iup.Toggle("TITLE=3"),
					iup.Toggle("TITLE=4"),
				),
			),
		),
		iup.Text("EXPAND=HORIZONTAL"),
		iup.ProgressBar("MIN=0,MAX=100,VALUE=50,EXPAND=HORIZONTAL"),
		tree,
	)
	vbox2 := iup.Vbox(
		"TABTITLE=Text",
		iup.Text("EXPAND=YES,MULTILINE=YES"),
	)
	vbox3 := iup.Vbox(
		"TABTITLE=Colorbar",
		iup.Colorbar(
			"ORIENTATION=HORIZONTAL",
			"NUM_PARTS=2",
			"SHOW_SECONDARY=YES",
			func(arg *iup.ColorbarSelect) {
				fmt.Println(arg)
			},
		),
	)
	vbox4 := iup.Vbox(
		"TABTITLE=ColorBrowser",
		iup.ColorBrowser(
			"EXPAND=YES",
			func(arg *iup.ColorBrowserDrag) {
				fmt.Printf("R=%d,G=%d,B=%d\n", arg.R, arg.G, arg.B)
			},
		),
	)
	vbox5 := iup.Vbox(
		"TABTITLE=Dial",
		iup.Fill(),
		iup.Dial(),
		iup.Dial("ORIENTATION=VERTICAL"),
		iup.Fill(),
	)
	pplot := iuppplot.PPlot(
		iup.Attr("TITLE", "A simple XY Plot"),
		iup.Attrs(
			"MARGINBOTTOM", "35",
			"MARGINLEFT", "35",
			"AXS_XLABEL", "X",
			"AXS_YLABEL", "Y",
		),
	)
	pplot.Begin(0)
	pplot.Add(0, 0)
	pplot.Add(5, 5)
	pplot.Add(10, 7)
	pplot.End()
	vbox6 := iup.Vbox(
		"TABTITLE=PPlot",
		pplot,
	)
	vbox7 := iup.Vbox(
		"TABTITLE=Matrix",
		iup.Matrix(
			"NUMCOL=5,NUMLIN=10,NUMCOL_VISIBLE=5,NUMLIN_VISIBLE=3,WIDTHDEF=34",
			"RESIZEMATRIX=YES",
		),
	)
	vbox8 := iup.Vbox(
		"TABTITLE=Image",
		iup.Hbox(
			"GAP=10",
			iup.Button("IMAGE=IUP_FileNew"),
			iup.Button("IMAGE=IUP_FileOpen"),
			iup.Button(
				"TITLE=SelectImg",
				func(arg *iup.ButtonAction) {
					file, ok := iup.GetOpenFile("", "*.png;*.jpg;*.bmp;*.jpeg")
					if ok {
						label := arg.Sender.GetDialogChild("img_label")
						if img != nil {
							img.Destroy()
						}
						img = iupim.LoadImage(file)
						if img != nil {
							img.SetName("img_label_image")
							label.(*iup.Handle).SetAttribute("IMAGE", "img_label_image")
							label.(*iup.Handle).Refresh()
						}
					}
				},
			),
		),
		iup.Label("IMAGE=img_label_image", "NAME=img_label"),
	)
	dlg := iup.Dialog(
		iup.Attr("TITLE", "GO-IUP Demo 1.0"),
		"SIZE=350x200",
		"SHRINK=YES",
		"MARGIN=10x10",
		iup.Tabs(
			vbox1,
			vbox2,
			vbox3,
			vbox4,
			vbox5,
			vbox6,
			vbox7,
			vbox8,
		),
	)
	dlg.Show()

	tree.SetAttribute("ADDBRANCH", "Item2")
	tree.SetAttribute("ADDLEAF1", "leaf3")
	tree.SetAttribute("ADDLEAF2", "leaf4")
	tree.SetAttribute("ADDBRANCH", "Item1")
	tree.SetAttribute("ADDLEAF1", "leaf1")
	tree.SetAttribute("ADDLEAF2", "leaf2")

	defer dlg.Destroy()
	iup.MainLoop()
}