Debian Codegraph @

shiny/example/textedit/main.go

raw symbols SCIP
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build example
6 // +build example
7
8 //
9 // This build tag means that "go install golang.org/x/exp/shiny/..." doesn't
10 // install this example program. Use "go run main.go" to run it or "go install
11 // -tags=example" to install it.
12
13 // Textedit is a basic text editor.
14 package main
15
16 // TODO: cursors + editing (not just viewing) text, key + mouse events,
17 // scrolling, load/save, clipboard.
18
19 import (
20 "log"
21
22 "golang.org/x/exp/shiny/driver"
23 "golang.org/x/exp/shiny/screen"
24 "golang.org/x/exp/shiny/unit"
25 "golang.org/x/exp/shiny/widget"
26 "golang.org/x/exp/shiny/widget/node"
27 "golang.org/x/exp/shiny/widget/theme"
28 )
29
30 func stretch(n node.Node, alongWeight int) node.Node {
31 return widget.WithLayoutData(n, widget.FlowLayoutData{
32 AlongWeight: alongWeight,
33 ExpandAlong: true,
34 ShrinkAlong: true,
35 ExpandAcross: true,
36 ShrinkAcross: true,
37 })
38 }
39
40 func main() {
41 log.SetFlags(0)
42 driver.Main(func(s screen.Screen) {
43 header := widget.NewUniform(theme.Neutral,
44 widget.NewPadder(widget.AxisBoth, unit.Ems(0.5),
45 widget.NewFlow(widget.AxisHorizontal,
46 widget.NewLabel("TODO: status"),
47 stretch(widget.NewSpace(), 1),
48 widget.NewLabel("TODO: Menu"),
49 ),
50 ),
51 )
52 divider := widget.NewSizer(unit.Value{}, unit.DIPs(2),
53 widget.NewUniform(theme.Foreground, nil),
54 )
55 body := widget.NewText(prideAndPrejudice)
56
57 w := widget.NewFlow(widget.AxisVertical,
58 stretch(widget.NewSheet(header), 0),
59 stretch(widget.NewSheet(divider), 0),
60 // TODO: make the body's sheet scrollable.
61 stretch(widget.NewSheet(body), 1),
62 )
63
64 if err := widget.RunWindow(s, w, &widget.RunWindowOptions{
65 NewWindowOptions: screen.NewWindowOptions{
66 Title: "TextEdit Shiny Example",
67 },
68 }); err != nil {
69 log.Fatal(err)
70 }
71 })
72 }
73
74 // prideAndPrejudice comes from http://www.gutenberg.org/cache/epub/1342/pg1342.txt
75 const prideAndPrejudice = `PRIDE AND PREJUDICE
76
77 By Jane Austen
78
79
80
81 Chapter 1
82
83
84 It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.
85
86 However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered the rightful property of some one or other of their daughters.
87
88 "My dear Mr. Bennet," said his lady to him one day, "have you heard that Netherfield Park is let at last?"
89
90 Mr. Bennet replied that he had not.
91
92 "But it is," returned she; "for Mrs. Long has just been here, and she told me all about it."
93
94 Mr. Bennet made no answer.
95
96 "Do you not want to know who has taken it?" cried his wife impatiently.
97
98 "_You_ want to tell me, and I have no objection to hearing it."
99
100 This was invitation enough.
101
102 "Why, my dear, you must know, Mrs. Long says that Netherfield is taken by a young man of large fortune from the north of England; that he came down on Monday in a chaise and four to see the place, and was so much delighted with it, that he agreed with Mr. Morris immediately; that he is to take possession before Michaelmas, and some of his servants are to be in the house by the end of next week."
103
104 "What is his name?"
105
106 "Bingley."
107
108 "Is he married or single?"
109
110 "Oh! Single, my dear, to be sure! A single man of large fortune; four or five thousand a year. What a fine thing for our girls!"
111
112 "How so? How can it affect them?"
113
114 "My dear Mr. Bennet," replied his wife, "how can you be so tiresome! You must know that I am thinking of his marrying one of them."
115
116 "Is that his design in settling here?"
117
118 "Design! Nonsense, how can you talk so! But it is very likely that he _may_ fall in love with one of them, and therefore you must visit him as soon as he comes."
119
120 "I see no occasion for that. You and the girls may go, or you may send them by themselves, which perhaps will be still better, for as you are as handsome as any of them, Mr. Bingley may like you the best of the party."
121
122 "My dear, you flatter me. I certainly _have_ had my share of beauty, but I do not pretend to be anything extraordinary now. When a woman has five grown-up daughters, she ought to give over thinking of her own beauty."
123
124 "In such cases, a woman has not often much beauty to think of."
125
126 "But, my dear, you must indeed go and see Mr. Bingley when he comes into the neighbourhood."
127
128 "It is more than I engage for, I assure you."
129
130 "But consider your daughters. Only think what an establishment it would be for one of them. Sir William and Lady Lucas are determined to go, merely on that account, for in general, you know, they visit no newcomers. Indeed you must go, for it will be impossible for _us_ to visit him if you do not."
131
132 "You are over-scrupulous, surely. I dare say Mr. Bingley will be very glad to see you; and I will send a few lines by you to assure him of my hearty consent to his marrying whichever he chooses of the girls; though I must throw in a good word for my little Lizzy."
133
134 "I desire you will do no such thing. Lizzy is not a bit better than the others; and I am sure she is not half so handsome as Jane, nor half so good-humoured as Lydia. But you are always giving _her_ the preference."
135
136 "They have none of them much to recommend them," replied he; "they are all silly and ignorant like other girls; but Lizzy has something more of quickness than her sisters."
137
138 "Mr. Bennet, how _can_ you abuse your own children in such a way? You take delight in vexing me. You have no compassion for my poor nerves."
139
140 "You mistake me, my dear. I have a high respect for your nerves. They are my old friends. I have heard you mention them with consideration these last twenty years at least."
141
142 "Ah, you do not know what I suffer."
143
144 "But I hope you will get over it, and live to see many young men of four thousand a year come into the neighbourhood."
145
146 "It will be no use to us, if twenty such should come, since you will not visit them."
147
148 "Depend upon it, my dear, that when there are twenty, I will visit them all."
149
150 Mr. Bennet was so odd a mixture of quick parts, sarcastic humour, reserve, and caprice, that the experience of three-and-twenty years had been insufficient to make his wife understand his character. _Her_ mind was less difficult to develop. She was a woman of mean understanding, little information, and uncertain temper. When she was discontented, she fancied herself nervous. The business of her life was to get her daughters married; its solace was visiting and news.`