Exemple #1
0
func createTxLabel(attr *TxAttributes) (*gtk.Widget, error) {
	grid, err := gtk.GridNew()
	if err != nil {
		return nil, err
	}
	grid.SetHExpand(true)

	var amtLabel *gtk.Label
	var description *gtk.Label
	var icon *gtk.Image
	switch attr.Direction {
	case Send:
		amtLabel, err = gtk.LabelNew(amountStr(attr.Amount))
		if err != nil {
			return nil, err
		}

		description, err = gtk.LabelNew(fmt.Sprintf("Send (%s)", attr.Address))
		if err != nil {
			return nil, err
		}

		icon, err = gtk.ImageNewFromIconName("go-next",
			gtk.ICON_SIZE_SMALL_TOOLBAR)
		if err != nil {
			return nil, err
		}

	case Recv:
		amtLabel, err = gtk.LabelNew(amountStr(attr.Amount))
		if err != nil {
			return nil, err
		}

		description, err = gtk.LabelNew(fmt.Sprintf("Receive (%s)", attr.Address))
		if err != nil {
			return nil, err
		}

		icon, err = gtk.ImageNewFromIconName("go-previous",
			gtk.ICON_SIZE_SMALL_TOOLBAR)
		if err != nil {
			return nil, err
		}
	}
	grid.Attach(icon, 0, 0, 2, 2)
	grid.Attach(description, 2, 1, 2, 1)
	description.SetHAlign(gtk.ALIGN_START)
	grid.Attach(amtLabel, 3, 0, 1, 1)
	amtLabel.SetHAlign(gtk.ALIGN_END)
	amtLabel.SetHExpand(true)

	date, err := gtk.LabelNew(attr.Date.Format("Jan 2, 2006 at 3:04 PM"))
	if err != nil {
		return nil, err
	}
	grid.Attach(date, 2, 0, 1, 1)
	date.SetHAlign(gtk.ALIGN_START)

	grid.SetHAlign(gtk.ALIGN_FILL)

	return &grid.Container.Widget, nil
}