Example #1
0
func (win *Window) Label(ms *mouse.Mouse, txt string, x, y, w, h int) *Label {

	lab := &Label{
		parent: win,
		fb:     win.fb,
		txt:    txt,
	}

	win.Children.PushFront(lab)

	lab.Element = base.Element{
		Id:         base.GenerateId(),
		X:          x,
		Y:          y,
		ScreenX:    win.Element.X + x,
		ScreenY:    win.Element.Y + y,
		Width:      w,
		Height:     h,
		InvMsgPipe: win.InvMsgPipe,
		Font:       fonts.Default(),
	}

	lab.Draw()

	return lab
}
Example #2
0
// style should be one of BS_TEXT, BS_ICON_TEXT, BS_ICON
// icon should be nil for BS_TEXT
// txt should be empty string for BS_ICON
func (win *Window) Button(style byte, ms *mouse.Mouse, icon image.Image, txt string, fnClick clickHandler, x, y, w, h int) *Button {

	but := &Button{
		parent:     win,
		fb:         win.fb,
		wasClicked: false,
		clickHndr:  fnClick,
		txt:        txt,
		style:      style,
		icon:       icon,
		pushed:     false,
	}

	win.Children.PushFront(but)

	but.Element = base.Element{
		Id:         base.GenerateId(),
		X:          x,
		Y:          y,
		ScreenX:    win.Element.X + x,
		ScreenY:    win.Element.Y + y,
		Width:      w,
		Height:     h,
		InvMsgPipe: win.InvMsgPipe,
		Font:       fonts.Default(),
	}

	ms.RegisterMouse(but.Element.Id, but.Mouse, nil, &but.Element.ScreenX, &but.Element.ScreenY, w, h)

	but.Draw()

	return but
}
Example #3
0
func (win *Window) CheckBox(style byte, ms *mouse.Mouse, txt string, fnClick clickHandler, x, y int) *CheckBox {

	cb := &CheckBox{
		parent:    win,
		fb:        win.fb,
		clickHndr: fnClick,
		txt:       txt,
		style:     style,
		checked:   false,
		mouseIn:   false,
	}

	win.Children.PushFront(cb)

	cb.Element = base.Element{
		Id:         base.GenerateId(),
		X:          x,
		Y:          y,
		ScreenX:    win.Element.X + x,
		ScreenY:    win.Element.Y + y,
		Width:      tk.cbChecked.Bounds().Dx(),
		Height:     tk.cbChecked.Bounds().Dy(),
		InvMsgPipe: win.InvMsgPipe,
		Font:       fonts.Default(),
	}

	var totalWidth, totalHeight int

	if txt != "" {
		w, h, _ := fonts.ExpectedSize(cb.Element.Font, txt)
		totalWidth = cb.Element.Width + ICON_TEXT_SPACE + int(w)

		if int(h) > cb.Element.Height {
			totalHeight = int(h)
		} else {
			totalHeight = cb.Element.Height
		}
	} else {
		totalWidth = cb.Element.Width
		totalHeight = cb.Element.Height
	}

	ms.RegisterMouse(cb.Element.Id, cb.Mouse, nil, &cb.Element.ScreenX, &cb.Element.ScreenY, totalWidth, totalHeight)

	cb.Draw()

	return cb
}