示例#1
0
文件: showcase.go 项目: ego008/gowut
// setNoWrap sets WHITE_SPACE_NOWRAP to all children of the specified panel.
func setNoWrap(panel gwu.Panel) {
	count := panel.CompsCount()
	for i := count - 1; i >= 0; i-- {
		panel.CompAt(i).Style().SetWhiteSpace(gwu.WHITE_SPACE_NOWRAP)
	}
}
示例#2
0
文件: main.go 项目: gnewton/goperu
func (zz ExpanderHandler) HandleEvent(e gwu.Event) {

	switch t := e.Src().(type) {
	case gwu.Expander:
		dir, _ := expanderDir[t]
		//fmt.Println("Dir=" + dir)
		files, _ := ioutil.ReadDir(dir)
		var p gwu.Panel
		var table gwu.Table
		p = nil

		dirList := make([]gwu.Comp, 0, 0)
		fileLabelList := make([]gwu.Comp, 0, 0)
		fileTimeList := make([]gwu.Comp, 0, 0)
		fileSizeList := make([]gwu.Comp, 0, 0)

		for _, f := range files {
			if p == nil {
				p = gwu.NewPanel()
				t.SetContent(p)
				table = gwu.NewTable()
				table.SetCellPadding(5)
				p.Add(table)
			}
			if f.IsDir() {
				// owned by root // only works on linux
				newExpander := makeExpander(f.Name())
				newExpander.SetToolTip("DIR - Click to view contents")
				newExpander.Style().SetColor("blue")
				if dir == "/" {
					expanderDir[newExpander] = dir + f.Name()
				} else {
					expanderDir[newExpander] = dir + "/" + f.Name()
				}
				newExpander.AddEHandler(handler, gwu.ETYPE_STATE_CHANGE)
				dirList = append(dirList, newExpander)
			} else {
				fileLabel := gwu.NewLabel(f.Name())
				fileLabel.Style().SetPaddingLeft("20")
				fileLabel.SetToolTip("FILE")
				fileLabel.AddEHandler(foobar, gwu.ETYPE_MOUSE_DOWN)
				fileLabelList = append(fileLabelList, fileLabel)

				fileTimeLabel := gwu.NewLabel(f.ModTime().Format(layout))
				fileTimeList = append(fileTimeList, fileTimeLabel)
				fileSizeLabel := gwu.NewLabel(strconv.FormatInt(f.Size(), 10) + "k")
				fileSizeList = append(fileSizeList, fileSizeLabel)
			}
		}
		row := 0
		for _, dir := range dirList {
			table.Add(dir, row, 0)
			row = row + 1
		}
		for i, _ := range fileLabelList {
			table.Add(fileLabelList[i], row, 0)
			rfmt := table.CellFmt(row, 0)
			rfmt.SetHAlign(gwu.HA_LEFT)
			rfmt.SetVAlign(gwu.VA_TOP)

			table.Add(fileTimeList[i], row, 1)
			rfmt = table.CellFmt(row, 1)
			rfmt.SetHAlign(gwu.HA_LEFT)
			rfmt.SetVAlign(gwu.VA_TOP)

			table.Add(fileSizeList[i], row, 2)
			rfmt = table.CellFmt(row, 2)
			rfmt.SetHAlign(gwu.HA_RIGHT)
			rfmt.SetVAlign(gwu.VA_TOP)

			row = row + 1
		}

	default:
		// t is some other type that we didn't name.
	}

}