summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basicctrls.go17
-rw-r--r--label_windows.go1
-rw-r--r--textbox_windows.go40
-rw-r--r--textfield_windows.go8
-rw-r--r--zz_test.go6
5 files changed, 63 insertions, 9 deletions
diff --git a/basicctrls.go b/basicctrls.go
index 1ef720b..1f8516d 100644
--- a/basicctrls.go
+++ b/basicctrls.go
@@ -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()
+}
diff --git a/label_windows.go b/label_windows.go
index 8f8f120..49f70fc 100644
--- a/label_windows.go
+++ b/label_windows.go
@@ -7,7 +7,6 @@ import "C"
type label struct {
*controlSingleHWNDWithText
- standalone bool
}
var labelclass = toUTF16("STATIC")
diff --git a/textbox_windows.go b/textbox_windows.go
new file mode 100644
index 0000000..0a68052
--- /dev/null
+++ b/textbox_windows.go
@@ -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
+}
diff --git a/textfield_windows.go b/textfield_windows.go
index d3b4193..1d2025b 100644
--- a/textfield_windows.go
+++ b/textfield_windows.go
@@ -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)
}
diff --git a/zz_test.go b/zz_test.go
index 3f2f079..2634d3a 100644
--- a/zz_test.go
+++ b/zz_test.go
@@ -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)