-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc.go
43 lines (36 loc) · 1.63 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2018, Mark "Happy-Ferret" Bauermeister
//
// This software may be modified and distributed under the terms
// of the BSD license. See the LICENSE file for details.
/*
Package text provides text rendering helper functions and an abstraction to
create input text windows.
The DrawText rendering function included takes a window, font information and
text and creates an image with the text written on it. The image is then
painted to the window provided, and the window is resized to "snugly" fit the
text. (Note that DrawText has a subtle bug that will manifest itself with large
font sizes. Please see the bugs section.)
The other useful part of this package is the Input window type. It is an
abstraction over xwindow.Window that provides an input box like window. The
Input type's methods can then be used to easily add and remove text from the
input box in response to KeyPress events. (You must write the KeyPress event
handler.)
Here's a minimal example for creating an input window and allowing the user to
type into it:
input := text.NewInput(XUtilValue, RootId, 500, 0, font, 20.0,
textColor, bgColor)
input.Listen(xproto.EventMaskKeyPress)
xevent.KeyPressFun(
func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
if keybind.KeyMatch(X, "BackSpace", ev.State, ev.Detail) {
input.Remove()
} else {
input.Add(ev.State, ev.Detail)
}
}).Connect(X, input.Id)
Since the Input type embeds an xwindow.Window, it can be thought of as a
regular window with special methods for handling text display.
Note that a slightly more involved and working example can be found in
text/examples/input/main.go.
*/
package text