/
main.go
136 lines (129 loc) · 4.17 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"gioui.org/app"
"gioui.org/font"
"gioui.org/font/gofont"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op/paint"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget/material"
"github.com/wrnrlr/foxtrot/typeset"
"image/color"
"log"
)
var theme *material.Theme
func main() {
go func() {
w := app.NewWindow()
if err := loop(w); err != nil {
log.Fatal(err)
}
}()
app.Main()
}
func loop(w *app.Window) error {
gtx := &layout.Context{
Queue: w.Queue(),
}
gofont.Register()
theme = material.NewTheme()
theme.TextSize = unit.Sp(12)
theme.Color.Text = black
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx.Reset(e.Config, e.Size)
s := font.Default()
fnt := text.Font{Size: unit.Sp(20)}
f := layout.Flex{Axis: layout.Vertical}
paint.ColorOp{black}.Add(gtx.Ops)
c0 := f.Rigid(gtx, func() {
theme.Label(unit.Sp(38), "Examples:").Layout(gtx)
})
c1 := f.Rigid(gtx, func() {
l := &typeset.Label{Text: "x", MaxWidth: typeset.FitContent}
s1 := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
den := &typeset.Word{Content: l, Superscript: s1}
den.Layout(gtx, s, fnt)
})
c2 := f.Rigid(gtx, func() {
l := &typeset.Label{Text: "q", MaxWidth: typeset.FitContent}
s1 := &typeset.Label{Text: "2i", MaxWidth: typeset.FitContent}
den := &typeset.Word{Content: l, Subscript: s1}
den.Layout(gtx, s, fnt)
})
c3 := f.Rigid(gtx, func() {
l := &typeset.Label{Text: "Abg", MaxWidth: typeset.FitContent}
s1 := &typeset.Label{Text: "q", MaxWidth: typeset.FitContent}
s2 := &typeset.Label{Text: "nN", MaxWidth: typeset.FitContent}
w := typeset.Word{l, s2, s1}
w.Layout(gtx, s, fnt)
})
c4 := f.Rigid(gtx, func() {
num := &typeset.Label{Text: "12", MaxWidth: typeset.FitContent}
den := &typeset.Label{Text: "100", MaxWidth: typeset.FitContent}
fr := &typeset.Fraction{num, den}
fr.Layout(gtx, s, fnt)
})
c5 := f.Rigid(gtx, func() {
num := &typeset.Label{Text: "1", MaxWidth: typeset.FitContent}
l := &typeset.Label{Text: "n", MaxWidth: typeset.FitContent}
s1 := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
den := &typeset.Word{Content: l, Superscript: s1}
fr := &typeset.Fraction{num, den}
fr.Layout(gtx, s, fnt)
})
c6 := f.Rigid(gtx, func() {
x := &typeset.Label{Text: "x", MaxWidth: typeset.FitContent}
num := &typeset.Label{Text: "1", MaxWidth: typeset.FitContent}
den := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
fr := &typeset.Fraction{num, den}
power := &typeset.Word{Content: x, Superscript: fr}
power.Layout(gtx, s, fnt)
})
c7 := f.Rigid(gtx, func() {
a := &typeset.Label{Text: "a", MaxWidth: typeset.FitContent}
as := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
d1 := &typeset.Word{Content: a, Superscript: as}
b := &typeset.Label{Text: "b", MaxWidth: typeset.FitContent}
bs := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
d2 := &typeset.Word{Content: b, Superscript: bs}
p := typeset.Plus(d1, d2)
c := &typeset.Label{Text: "c", MaxWidth: typeset.FitContent}
cs := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
d3 := &typeset.Word{Content: c, Superscript: cs}
p2 := typeset.Plus(d3, p)
p2.Layout(gtx, s, fnt)
})
c8 := f.Rigid(gtx, func() {
a := &typeset.Label{Text: "a", MaxWidth: typeset.FitContent}
d1 := &typeset.Word{Content: a}
l := &typeset.Label{Text: "b", MaxWidth: typeset.FitContent}
s1 := &typeset.Label{Text: "2", MaxWidth: typeset.FitContent}
b := &typeset.Word{Content: l, Superscript: s1}
d2 := &typeset.Word{Content: b}
p := typeset.Plus(d1, d2)
den := &typeset.Label{Text: "100", MaxWidth: typeset.FitContent}
fr := &typeset.Fraction{p, den}
fr.Layout(gtx, s, fnt)
p.Layout(gtx, s, fnt)
})
f.Layout(gtx, c0, c1, c2, c3, c4, c5, c6, c7, c8)
e.Frame(gtx.Ops)
}
}
}
var (
black = rgb(0x000000)
)
func rgb(c uint32) color.RGBA {
return argb(0xff000000 | c)
}
func argb(c uint32) color.RGBA {
return color.RGBA{A: uint8(c >> 24), R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c)}
}