Esempio n. 1
2
func (tvc TableViewColumn) Create(tv *walk.TableView) error {
	w := walk.NewTableViewColumn()

	if err := w.SetAlignment(walk.Alignment1D(tvc.Alignment)); err != nil {
		return err
	}
	w.SetDataMember(tvc.DataMember)
	if tvc.Format != "" {
		if err := w.SetFormat(tvc.Format); err != nil {
			return err
		}
	}
	if err := w.SetPrecision(tvc.Precision); err != nil {
		return err
	}
	if err := w.SetTitle(tvc.Title); err != nil {
		return err
	}
	if err := w.SetVisible(!tvc.Hidden); err != nil {
		return err
	}
	if err := w.SetWidth(tvc.Width); err != nil {
		return err
	}

	return tv.Columns().Add(w)
}
Esempio n. 2
0
File: table.go Progetto: sunclx/walk
func main() {
	model := NewFooModel("img")
	foo := &TableViewColumnFormat{Title: "创建时间", Format: "2006-01-02", Width: 150}
	var tv *walk.TableView
	MainWindow{
		Title:  "TableView",
		Size:   Size{800, 600},
		Layout: VBox{},
		DataBinder: DataBinder{
			DataSource: foo,
			AutoSubmit: true,
			OnSubmitted: func() {
				fmt.Println(foo)
			},
		},
		Children: []Widget{
			Composite{
				Layout: HBox{},
				Children: []Widget{
					RadioButtonGroup{
						DataMember: "Alignment",
						Buttons: []RadioButton{
							RadioButton{
								Name:  "leftAlign",
								Text:  "左对齐",
								Value: AlignFar,
								OnClicked: func() {
									tv.Columns().Add(walk.NewTableViewColumn())
									model.PublishRowsReset()
								},
							},
							RadioButton{
								Name:  "leftAlign",
								Text:  "居中",
								Value: AlignCenter,
								OnClicked: func() {
									tv.Columns().At(4).SetAlignment(walk.AlignCenter)
									model.PublishRowsReset()
								},
							},
							RadioButton{
								Name:  "leftAlign",
								Text:  "右对齐",
								Value: AlignNear,
								OnClicked: func() {
									tv.Columns().At(4).SetAlignment(walk.AlignFar)
									//tv.Columns().Clear()
									model.PublishRowsReset()
								},
							},
						},
					},
				},
			},

			TableView{
				AssignTo:              &tv,
				AlternatingRowBGColor: walk.RGB(183, 208, 65),
				CheckBoxes:            true,
				ColumnsOrderable:      true,
				Columns: []TableViewColumn{
					{Title: "#"},
					{Title: "原文件名"},
					{Title: "类型"},
					{Title: "新文件名"},
					{Title: "创建时间", Format: "2006-01-02 15:04:05", Width: 150, Alignment: foo.Alignment, DataMember: "", Hidden: false, Precision: 2},
					{Title: "修改时间", Format: "2006-01-02 15:04:05", Width: 150, DataMember: "", Alignment: foo.Alignment},
				},
				Model: model,
			},
		},
	}.Run()
}