Added Textbox and implemented it on Windows.
This commit is contained in:
parent
ba31d13c6d
commit
92c7598d9d
|
@ -121,3 +121,20 @@ type Group interface {
|
|||
func NewGroup(text string, control Control) Group {
|
||||
return newGroup(text, control)
|
||||
}
|
||||
|
||||
// Textbox represents a multi-line text entry box.
|
||||
// Text in a Textbox is unformatted, and scrollbars are applied automatically.
|
||||
// TODO rename to TextBox? merge with TextField (but cannot use Invalid())? enable/disable line wrapping?
|
||||
// TODO events
|
||||
type Textbox interface {
|
||||
Control
|
||||
|
||||
// Text and SetText get and set the Textbox's text.
|
||||
Text() string
|
||||
SetText(text string)
|
||||
}
|
||||
|
||||
// NewTextbox creates a new Textbox.
|
||||
func NewTextbox() Textbox {
|
||||
return newTextbox()
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import "C"
|
|||
|
||||
type label struct {
|
||||
*controlSingleHWNDWithText
|
||||
standalone bool
|
||||
}
|
||||
|
||||
var labelclass = toUTF16("STATIC")
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// 23 october 2014
|
||||
|
||||
package ui
|
||||
|
||||
// #include "winapi_windows.h"
|
||||
import "C"
|
||||
|
||||
type textbox struct {
|
||||
*controlSingleHWNDWithText
|
||||
}
|
||||
|
||||
// TODO autohide scrollbars
|
||||
func newTextbox() Textbox {
|
||||
hwnd := C.newControl(editclass,
|
||||
// TODO ES_AUTOHSCROLL/ES_AUTOVSCROLL as well?
|
||||
// TODO word wrap
|
||||
C.ES_LEFT | C.ES_MULTILINE | C.ES_NOHIDESEL | C.ES_WANTRETURN | C.WS_HSCROLL | C.WS_VSCROLL,
|
||||
C.WS_EX_CLIENTEDGE)
|
||||
t := &textbox{
|
||||
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
|
||||
}
|
||||
t.fpreferredSize = t.xpreferredSize
|
||||
C.controlSetControlFont(t.hwnd)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *textbox) Text() string {
|
||||
return t.text()
|
||||
}
|
||||
|
||||
func (t *textbox) SetText(text string) {
|
||||
t.setText(text)
|
||||
}
|
||||
|
||||
// just reuse the preferred textfield width
|
||||
// TODO allow alternate widths
|
||||
// TODO current height probably can be better calculated
|
||||
func (t *textbox) xpreferredSize(d *sizing) (width, height int) {
|
||||
return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d) * 3
|
||||
}
|
|
@ -16,13 +16,6 @@ type textfield struct {
|
|||
|
||||
var editclass = toUTF16("EDIT")
|
||||
|
||||
/*
|
||||
notes about multiline text boxes
|
||||
- ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | ES_WANTRETURN
|
||||
(ES_AUTOVSCROLL as well?)
|
||||
(what about word wrap?)
|
||||
*/
|
||||
|
||||
func startNewTextField(style C.DWORD) *textfield {
|
||||
hwnd := C.newControl(editclass,
|
||||
style|C.textfieldStyle,
|
||||
|
@ -77,6 +70,7 @@ const (
|
|||
textfieldHeight = 14
|
||||
)
|
||||
|
||||
// TODO allow custom preferred widths
|
||||
func (t *textfield) xpreferredSize(d *sizing) (width, height int) {
|
||||
return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d)
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ type testwin struct {
|
|||
repainter *repainter
|
||||
fe *ForeignEvent
|
||||
festack Stack
|
||||
festack2 Stack
|
||||
festart Button
|
||||
felabel Label
|
||||
festop Button
|
||||
|
@ -148,7 +149,10 @@ func (tw *testwin) addfe() {
|
|||
tw.openbtn, tw.fnlabel)
|
||||
tw.festack.SetStretchy(4)
|
||||
tw.festack.SetStretchy(6)
|
||||
tw.festack = newHorizontalStack(tw.festack, Space())
|
||||
tw.festack2 = newVerticalStack(Space(), NewTextbox())
|
||||
tw.festack2.SetStretchy(0)
|
||||
tw.festack2.SetStretchy(1)
|
||||
tw.festack = newHorizontalStack(tw.festack, tw.festack2)
|
||||
tw.festack.SetStretchy(0)
|
||||
tw.festack.SetStretchy(1)
|
||||
tw.t.Append("Foreign Events", tw.festack)
|
||||
|
|
Loading…
Reference in New Issue