mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
apps: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ module gioui.org/apps
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gioui.org/ui v0.0.0-20190720142241-cd244f21ab23
|
gioui.org/ui v0.0.0-20190721094448-b6290990ad93
|
||||||
github.com/google/go-github/v24 v24.0.1
|
github.com/google/go-github/v24 v24.0.1
|
||||||
golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f
|
golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f
|
||||||
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
|
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
|
||||||
|
|||||||
+29
-48
@@ -50,10 +50,7 @@ import (
|
|||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
w *app.Window
|
w *app.Window
|
||||||
cfg app.Config
|
faces measure.Faces
|
||||||
faces *measure.Faces
|
|
||||||
|
|
||||||
inputs input.Queue
|
|
||||||
|
|
||||||
fab *ActionButton
|
fab *ActionButton
|
||||||
|
|
||||||
@@ -77,7 +74,7 @@ type App struct {
|
|||||||
|
|
||||||
type userPage struct {
|
type userPage struct {
|
||||||
config ui.Config
|
config ui.Config
|
||||||
faces *measure.Faces
|
faces measure.Faces
|
||||||
invalidate func()
|
invalidate func()
|
||||||
user *user
|
user *user
|
||||||
commitsList *layout.List
|
commitsList *layout.List
|
||||||
@@ -102,8 +99,6 @@ type icon struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ActionButton struct {
|
type ActionButton struct {
|
||||||
config ui.Config
|
|
||||||
inputs input.Queue
|
|
||||||
face text.Face
|
face text.Face
|
||||||
Open bool
|
Open bool
|
||||||
icons []*icon
|
icons []*icon
|
||||||
@@ -182,6 +177,7 @@ func colorMaterial(ops *ui.Ops, color color.RGBA) ui.MacroOp {
|
|||||||
func (a *App) run() error {
|
func (a *App) run() error {
|
||||||
a.profiling = *stats
|
a.profiling = *stats
|
||||||
ops := new(ui.Ops)
|
ops := new(ui.Ops)
|
||||||
|
var cfg app.Config
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case users := <-a.updateUsers:
|
case users := <-a.updateUsers:
|
||||||
@@ -227,14 +223,14 @@ func (a *App) run() error {
|
|||||||
}
|
}
|
||||||
case app.DrawEvent:
|
case app.DrawEvent:
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
a.cfg = e.Config
|
a.faces.Reset(&cfg)
|
||||||
|
cfg = e.Config
|
||||||
cs := layout.RigidConstraints(e.Size)
|
cs := layout.RigidConstraints(e.Size)
|
||||||
a.Layout(ops, cs)
|
a.Layout(&cfg, a.w.Queue(), ops, cs)
|
||||||
if a.profiling {
|
if a.profiling {
|
||||||
a.layoutTimings(ops, cs)
|
a.layoutTimings(&cfg, a.w.Queue(), ops, cs)
|
||||||
}
|
}
|
||||||
a.w.Draw(ops)
|
a.w.Draw(ops)
|
||||||
a.faces.Frame()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,25 +240,17 @@ func newApp(w *app.Window) *App {
|
|||||||
a := &App{
|
a := &App{
|
||||||
w: w,
|
w: w,
|
||||||
updateUsers: make(chan []*user),
|
updateUsers: make(chan []*user),
|
||||||
inputs: w.Queue(),
|
|
||||||
}
|
}
|
||||||
a.faces = &measure.Faces{Config: &a.cfg}
|
|
||||||
a.usersList = &layout.List{
|
a.usersList = &layout.List{
|
||||||
Config: &a.cfg,
|
Axis: layout.Vertical,
|
||||||
Inputs: a.inputs,
|
|
||||||
Axis: layout.Vertical,
|
|
||||||
}
|
}
|
||||||
a.fab = &ActionButton{
|
a.fab = &ActionButton{
|
||||||
config: &a.cfg,
|
|
||||||
inputs: a.inputs,
|
|
||||||
face: a.face(fonts.regular, 11),
|
face: a.face(fonts.regular, 11),
|
||||||
sendIco: &icon{src: icons.ContentSend, size: ui.Dp(24)},
|
sendIco: &icon{src: icons.ContentSend, size: ui.Dp(24)},
|
||||||
icons: []*icon{},
|
icons: []*icon{},
|
||||||
}
|
}
|
||||||
a.edit2 = &text.Editor{
|
a.edit2 = &text.Editor{
|
||||||
Config: &a.cfg,
|
Face: a.face(fonts.italic, 14),
|
||||||
Inputs: a.inputs,
|
|
||||||
Face: a.face(fonts.italic, 14),
|
|
||||||
//Alignment: text.End,
|
//Alignment: text.End,
|
||||||
SingleLine: true,
|
SingleLine: true,
|
||||||
Hint: "Hint",
|
Hint: "Hint",
|
||||||
@@ -271,8 +259,6 @@ func newApp(w *app.Window) *App {
|
|||||||
}
|
}
|
||||||
a.edit2.SetText("Single line editor. Edit me!")
|
a.edit2.SetText("Single line editor. Edit me!")
|
||||||
a.edit = &text.Editor{
|
a.edit = &text.Editor{
|
||||||
Config: &a.cfg,
|
|
||||||
Inputs: a.inputs,
|
|
||||||
Face: a.face(fonts.regular, 16),
|
Face: a.face(fonts.regular, 16),
|
||||||
Material: theme.text,
|
Material: theme.text,
|
||||||
//Alignment: text.End,
|
//Alignment: text.End,
|
||||||
@@ -379,8 +365,8 @@ func (a *App) face(f *sfnt.Font, size float32) text.Face {
|
|||||||
return a.faces.For(f, ui.Sp(size))
|
return a.faces.For(f, ui.Sp(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) layoutTimings(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) layoutTimings(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
for _, e := range a.inputs.Events(a) {
|
for _, e := range q.Events(a) {
|
||||||
if e, ok := e.(system.ProfileEvent); ok {
|
if e, ok := e.(system.ProfileEvent); ok {
|
||||||
a.profile = e
|
a.profile = e
|
||||||
}
|
}
|
||||||
@@ -393,43 +379,42 @@ func (a *App) layoutTimings(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
al := layout.Align{Alignment: layout.NE}
|
al := layout.Align{Alignment: layout.NE}
|
||||||
cs = al.Begin(ops, cs)
|
cs = al.Begin(ops, cs)
|
||||||
in := layout.Inset{Top: ui.Dp(16)}
|
in := layout.Inset{Top: ui.Dp(16)}
|
||||||
cs = in.Begin(&a.cfg, ops, cs)
|
cs = in.Begin(c, ops, cs)
|
||||||
txt := fmt.Sprintf("m: %d %s", mallocs, a.profile.Timings)
|
txt := fmt.Sprintf("m: %d %s", mallocs, a.profile.Timings)
|
||||||
dims := text.Label{Material: theme.text, Face: a.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
|
dims := text.Label{Material: theme.text, Face: a.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
|
||||||
dims = in.End(dims)
|
dims = in.End(dims)
|
||||||
return al.End(dims)
|
return al.End(dims)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) Layout(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
for i := range a.userClicks {
|
for i := range a.userClicks {
|
||||||
click := &a.userClicks[i]
|
click := &a.userClicks[i]
|
||||||
for _, e := range click.Events(a.inputs) {
|
for _, e := range click.Events(q) {
|
||||||
if e.Type == gesture.TypeClick {
|
if e.Type == gesture.TypeClick {
|
||||||
a.selectedUser = a.newUserPage(a.users[i])
|
a.selectedUser = a.newUserPage(a.users[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if a.selectedUser == nil {
|
if a.selectedUser == nil {
|
||||||
return a.layoutUsers(ops, cs)
|
return a.layoutUsers(c, q, ops, cs)
|
||||||
} else {
|
} else {
|
||||||
return a.selectedUser.Layout(ops, cs)
|
return a.selectedUser.Layout(c, q, ops, cs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) newUserPage(user *user) *userPage {
|
func (a *App) newUserPage(user *user) *userPage {
|
||||||
up := &userPage{
|
up := &userPage{
|
||||||
config: &a.cfg,
|
|
||||||
faces: a.faces,
|
faces: a.faces,
|
||||||
invalidate: a.w.Invalidate,
|
invalidate: a.w.Invalidate,
|
||||||
user: user,
|
user: user,
|
||||||
commitsList: &layout.List{Config: &a.cfg, Inputs: a.inputs, Axis: layout.Vertical},
|
commitsList: &layout.List{Axis: layout.Vertical},
|
||||||
commitsResult: make(chan []*github.Commit, 1),
|
commitsResult: make(chan []*github.Commit, 1),
|
||||||
}
|
}
|
||||||
up.fetchCommits(a.ctx)
|
up.fetchCommits(a.ctx)
|
||||||
return up
|
return up
|
||||||
}
|
}
|
||||||
|
|
||||||
func (up *userPage) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (up *userPage) Layout(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
l := up.commitsList
|
l := up.commitsList
|
||||||
if l.Dragging() {
|
if l.Dragging() {
|
||||||
key.HideInputOp{}.Add(ops)
|
key.HideInputOp{}.Add(ops)
|
||||||
@@ -439,15 +424,14 @@ func (up *userPage) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
up.commits = commits
|
up.commits = commits
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
for l.Init(ops, cs, len(up.commits)); l.More(); l.Next() {
|
for l.Init(c, q, ops, cs, len(up.commits)); l.More(); l.Next() {
|
||||||
l.Elem(up.commit(ops, l.Constraints(), l.Index()))
|
l.Elem(up.commit(c, ops, l.Constraints(), l.Index()))
|
||||||
}
|
}
|
||||||
return l.Layout()
|
return l.Layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (up *userPage) commit(ops *ui.Ops, cs layout.Constraints, index int) layout.Dimens {
|
func (up *userPage) commit(c ui.Config, ops *ui.Ops, cs layout.Constraints, index int) layout.Dimens {
|
||||||
u := up.user
|
u := up.user
|
||||||
c := up.config
|
|
||||||
msg := up.commits[index].GetMessage()
|
msg := up.commits[index].GetMessage()
|
||||||
label := text.Label{Material: theme.text, Face: up.faces.For(fonts.regular, ui.Sp(12)), Text: msg}
|
label := text.Label{Material: theme.text, Face: up.faces.For(fonts.regular, ui.Sp(12)), Text: msg}
|
||||||
in := layout.Inset{Top: ui.Dp(16), Right: ui.Dp(8), Left: ui.Dp(8)}
|
in := layout.Inset{Top: ui.Dp(16), Right: ui.Dp(8), Left: ui.Dp(8)}
|
||||||
@@ -493,14 +477,13 @@ func (up *userPage) fetchCommits(ctx context.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) layoutUsers(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
c := &a.cfg
|
|
||||||
st := (&layout.Stack{Alignment: layout.Start}).Init(ops, cs)
|
st := (&layout.Stack{Alignment: layout.Start}).Init(ops, cs)
|
||||||
cs = st.Rigid()
|
cs = st.Rigid()
|
||||||
al := layout.Align{Alignment: layout.SE}
|
al := layout.Align{Alignment: layout.SE}
|
||||||
in := layout.UniformInset(ui.Dp(16))
|
in := layout.UniformInset(ui.Dp(16))
|
||||||
cs = in.Begin(c, ops, al.Begin(ops, cs))
|
cs = in.Begin(c, ops, al.Begin(ops, cs))
|
||||||
dims := a.fab.Layout(ops, cs)
|
dims := a.fab.Layout(c, q, ops, cs)
|
||||||
dims = al.End(in.End(dims))
|
dims = al.End(in.End(dims))
|
||||||
c2 := st.End(dims)
|
c2 := st.End(dims)
|
||||||
|
|
||||||
@@ -514,7 +497,7 @@ func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
in := layout.UniformInset(ui.Dp(16))
|
in := layout.UniformInset(ui.Dp(16))
|
||||||
sz := c.Px(ui.Dp(200))
|
sz := c.Px(ui.Dp(200))
|
||||||
cs = layout.RigidConstraints(cs.Constrain(image.Point{X: sz, Y: sz}))
|
cs = layout.RigidConstraints(cs.Constrain(image.Point{X: sz, Y: sz}))
|
||||||
dims = a.edit.Layout(ops, in.Begin(c, ops, cs))
|
dims = a.edit.Layout(c, q, ops, in.Begin(c, ops, cs))
|
||||||
dims = in.End(dims)
|
dims = in.End(dims)
|
||||||
}
|
}
|
||||||
c1 := f.End(dims)
|
c1 := f.End(dims)
|
||||||
@@ -523,7 +506,7 @@ func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
{
|
{
|
||||||
cs.Width.Min = cs.Width.Max
|
cs.Width.Min = cs.Width.Max
|
||||||
in := layout.Inset{Bottom: ui.Dp(16), Left: ui.Dp(16), Right: ui.Dp(16)}
|
in := layout.Inset{Bottom: ui.Dp(16), Left: ui.Dp(16), Right: ui.Dp(16)}
|
||||||
dims = a.edit2.Layout(ops, in.Begin(c, ops, cs))
|
dims = a.edit2.Layout(c, q, ops, in.Begin(c, ops, cs))
|
||||||
dims = in.End(dims)
|
dims = in.End(dims)
|
||||||
}
|
}
|
||||||
c2 := f.End(dims)
|
c2 := f.End(dims)
|
||||||
@@ -546,7 +529,7 @@ func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
|
|
||||||
cs = f.Flexible(1)
|
cs = f.Flexible(1)
|
||||||
cs.Width.Min = cs.Width.Max
|
cs.Width.Min = cs.Width.Max
|
||||||
dims = a.layoutContributors(ops, cs)
|
dims = a.layoutContributors(c, q, ops, cs)
|
||||||
c4 := f.End(dims)
|
c4 := f.End(dims)
|
||||||
dims = f.Layout(c1, c2, c3, c4)
|
dims = f.Layout(c1, c2, c3, c4)
|
||||||
}
|
}
|
||||||
@@ -554,8 +537,7 @@ func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
return st.Layout(c1, c2)
|
return st.Layout(c1, c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ActionButton) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *ActionButton) Layout(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
c := a.config
|
|
||||||
f := layout.Flex{Axis: layout.Vertical, MainAxisAlignment: layout.Start, CrossAxisAlignment: layout.End}
|
f := layout.Flex{Axis: layout.Vertical, MainAxisAlignment: layout.Start, CrossAxisAlignment: layout.End}
|
||||||
f.Init(ops, cs)
|
f.Init(ops, cs)
|
||||||
cs = f.Rigid()
|
cs = f.Rigid()
|
||||||
@@ -567,13 +549,12 @@ func (a *ActionButton) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens
|
|||||||
return f.Layout(f.End(dims))
|
return f.Layout(f.End(dims))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) layoutContributors(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) layoutContributors(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
c := &a.cfg
|
|
||||||
l := a.usersList
|
l := a.usersList
|
||||||
if l.Dragging() {
|
if l.Dragging() {
|
||||||
key.HideInputOp{}.Add(ops)
|
key.HideInputOp{}.Add(ops)
|
||||||
}
|
}
|
||||||
for l.Init(ops, cs, len(a.users)); l.More(); l.Next() {
|
for l.Init(c, q, ops, cs, len(a.users)); l.More(); l.Next() {
|
||||||
l.Elem(a.user(c, ops, l.Constraints(), l.Index()))
|
l.Elem(a.user(c, ops, l.Constraints(), l.Index()))
|
||||||
}
|
}
|
||||||
return l.Layout()
|
return l.Layout()
|
||||||
|
|||||||
+2
-2
@@ -40,7 +40,7 @@ func loop(w *app.Window) error {
|
|||||||
panic("failed to load font")
|
panic("failed to load font")
|
||||||
}
|
}
|
||||||
var cfg app.Config
|
var cfg app.Config
|
||||||
faces := &measure.Faces{Config: &cfg}
|
var faces measure.Faces
|
||||||
maroon := color.RGBA{127, 0, 0, 255}
|
maroon := color.RGBA{127, 0, 0, 255}
|
||||||
face := faces.For(regular, ui.Sp(72))
|
face := faces.For(regular, ui.Sp(72))
|
||||||
message := "Hello, Gio"
|
message := "Hello, Gio"
|
||||||
@@ -52,6 +52,7 @@ func loop(w *app.Window) error {
|
|||||||
return e.Err
|
return e.Err
|
||||||
case app.DrawEvent:
|
case app.DrawEvent:
|
||||||
cfg = e.Config
|
cfg = e.Config
|
||||||
|
faces.Reset(&cfg)
|
||||||
cs := layout.RigidConstraints(e.Size)
|
cs := layout.RigidConstraints(e.Size)
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
var material ui.MacroOp
|
var material ui.MacroOp
|
||||||
@@ -60,7 +61,6 @@ func loop(w *app.Window) error {
|
|||||||
material.Stop()
|
material.Stop()
|
||||||
text.Label{Material: material, Face: face, Alignment: text.Center, Text: message}.Layout(ops, cs)
|
text.Label{Material: material, Face: face, Alignment: text.Center, Text: message}.Layout(ops, cs)
|
||||||
w.Draw(ops)
|
w.Draw(ops)
|
||||||
faces.Frame()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user