mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
cmd/gophers,cmd/hello: update to latest API
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-20190618193019-7354874bb5bc
|
gioui.org/ui v0.0.0-20190621141729-898c3c5d7d7c
|
||||||
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-20190321205749-f0864edee7f3
|
golang.org/x/exp v0.0.0-20190321205749-f0864edee7f3
|
||||||
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f
|
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f
|
||||||
|
|||||||
+37
-39
@@ -49,10 +49,10 @@ import (
|
|||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
w *app.Window
|
w *app.Window
|
||||||
cfg *ui.Config
|
cfg ui.Config
|
||||||
faces measure.Faces
|
faces *measure.Faces
|
||||||
|
|
||||||
queue *input.Queue
|
inputs *input.Queue
|
||||||
|
|
||||||
fab *ActionButton
|
fab *ActionButton
|
||||||
|
|
||||||
@@ -70,8 +70,8 @@ type App struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type userPage struct {
|
type userPage struct {
|
||||||
cfg *ui.Config
|
config *ui.Config
|
||||||
faces measure.Faces
|
faces *measure.Faces
|
||||||
redraw redrawer
|
redraw redrawer
|
||||||
user *user
|
user *user
|
||||||
commitsList *layout.List
|
commitsList *layout.List
|
||||||
@@ -98,8 +98,9 @@ type icon struct {
|
|||||||
type redrawer func()
|
type redrawer func()
|
||||||
|
|
||||||
type ActionButton struct {
|
type ActionButton struct {
|
||||||
|
config *ui.Config
|
||||||
|
inputs input.Events
|
||||||
face text.Face
|
face text.Face
|
||||||
cfg *ui.Config
|
|
||||||
Open bool
|
Open bool
|
||||||
icons []*icon
|
icons []*icon
|
||||||
sendIco *icon
|
sendIco *icon
|
||||||
@@ -177,7 +178,7 @@ func (a *App) run() error {
|
|||||||
case e := <-a.w.Events():
|
case e := <-a.w.Events():
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case input.Event:
|
case input.Event:
|
||||||
a.queue.Add(e)
|
a.inputs.Add(e)
|
||||||
if e, ok := e.(key.Chord); ok {
|
if e, ok := e.(key.Chord); ok {
|
||||||
switch e.Name {
|
switch e.Name {
|
||||||
case key.NameEscape:
|
case key.NameEscape:
|
||||||
@@ -213,7 +214,6 @@ func (a *App) run() error {
|
|||||||
case app.Draw:
|
case app.Draw:
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
a.cfg = e.Config
|
a.cfg = e.Config
|
||||||
a.faces.Cfg = a.cfg
|
|
||||||
cs := layout.ExactConstraints(a.w.Size())
|
cs := layout.ExactConstraints(a.w.Size())
|
||||||
a.Layout(ops, cs)
|
a.Layout(ops, cs)
|
||||||
if a.w.Profiling {
|
if a.w.Profiling {
|
||||||
@@ -232,8 +232,8 @@ func (a *App) run() error {
|
|||||||
al.End(dims)
|
al.End(dims)
|
||||||
}
|
}
|
||||||
a.w.Draw(ops)
|
a.w.Draw(ops)
|
||||||
a.queue.Frame(ops)
|
a.inputs.Frame(ops)
|
||||||
a.w.SetTextInput(a.queue.InputState())
|
a.w.SetTextInput(a.inputs.InputState())
|
||||||
a.faces.Frame()
|
a.faces.Frame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,10 +245,17 @@ func newApp(w *app.Window) *App {
|
|||||||
a := &App{
|
a := &App{
|
||||||
w: w,
|
w: w,
|
||||||
updateUsers: make(chan []*user),
|
updateUsers: make(chan []*user),
|
||||||
queue: new(input.Queue),
|
inputs: new(input.Queue),
|
||||||
|
}
|
||||||
|
a.faces = &measure.Faces{Config: &a.cfg}
|
||||||
|
a.usersList = &layout.List{
|
||||||
|
Config: &a.cfg,
|
||||||
|
Inputs: a.inputs,
|
||||||
|
Axis: layout.Vertical,
|
||||||
}
|
}
|
||||||
a.usersList = &layout.List{Axis: layout.Vertical}
|
|
||||||
a.fab = &ActionButton{
|
a.fab = &ActionButton{
|
||||||
|
config: &a.cfg,
|
||||||
|
inputs: a.inputs,
|
||||||
face: a.face(fonts.regular, 9),
|
face: a.face(fonts.regular, 9),
|
||||||
sendIco: &icon{src: icons.ContentSend, size: ui.Dp(24)},
|
sendIco: &icon{src: icons.ContentSend, size: ui.Dp(24)},
|
||||||
icons: []*icon{},
|
icons: []*icon{},
|
||||||
@@ -256,12 +263,16 @@ func newApp(w *app.Window) *App {
|
|||||||
btnsClicker: new(gesture.Click),
|
btnsClicker: new(gesture.Click),
|
||||||
}
|
}
|
||||||
a.edit2 = &text.Editor{
|
a.edit2 = &text.Editor{
|
||||||
|
Config: &a.cfg,
|
||||||
|
Inputs: a.inputs,
|
||||||
Face: a.face(fonts.italic, 14),
|
Face: a.face(fonts.italic, 14),
|
||||||
//Alignment: text.End,
|
//Alignment: text.End,
|
||||||
SingleLine: true,
|
SingleLine: true,
|
||||||
}
|
}
|
||||||
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, 14),
|
Face: a.face(fonts.regular, 14),
|
||||||
//Alignment: text.End,
|
//Alignment: text.End,
|
||||||
//SingleLine: true,
|
//SingleLine: true,
|
||||||
@@ -382,28 +393,23 @@ func (a *App) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
if a.selectedUser == nil {
|
if a.selectedUser == nil {
|
||||||
return a.layoutUsers(ops, cs)
|
return a.layoutUsers(ops, cs)
|
||||||
} else {
|
} else {
|
||||||
a.selectedUser.Update(a.cfg, a.queue)
|
|
||||||
return a.selectedUser.Layout(ops, cs)
|
return a.selectedUser.Layout(ops, cs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserPage(ctx context.Context, user *user, redraw redrawer, faces measure.Faces) *userPage {
|
func (a *App) newUserPage(user *user) *userPage {
|
||||||
up := &userPage{
|
up := &userPage{
|
||||||
faces: faces,
|
config: &a.cfg,
|
||||||
redraw: redraw,
|
faces: a.faces,
|
||||||
|
redraw: a.w.Redraw,
|
||||||
user: user,
|
user: user,
|
||||||
commitsList: &layout.List{Axis: layout.Vertical},
|
commitsList: &layout.List{Config: &a.cfg, Inputs: a.inputs, Axis: layout.Vertical},
|
||||||
commitsResult: make(chan []*github.Commit, 1),
|
commitsResult: make(chan []*github.Commit, 1),
|
||||||
}
|
}
|
||||||
up.fetchCommits(ctx)
|
up.fetchCommits(a.ctx)
|
||||||
return up
|
return up
|
||||||
}
|
}
|
||||||
|
|
||||||
func (up *userPage) Update(cfg *ui.Config, queue input.Events) {
|
|
||||||
up.cfg = cfg
|
|
||||||
up.commitsList.Update(up.cfg, queue)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (up *userPage) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (up *userPage) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
l := up.commitsList
|
l := up.commitsList
|
||||||
if l.Dragging() {
|
if l.Dragging() {
|
||||||
@@ -427,7 +433,7 @@ func (up *userPage) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
|||||||
|
|
||||||
func (up *userPage) commit(ops *ui.Ops, cs layout.Constraints, index int) layout.Dimens {
|
func (up *userPage) commit(ops *ui.Ops, cs layout.Constraints, index int) layout.Dimens {
|
||||||
u := up.user
|
u := up.user
|
||||||
c := up.cfg
|
c := up.config
|
||||||
msg := up.commits[index].GetMessage()
|
msg := up.commits[index].GetMessage()
|
||||||
gdraw.OpColor{Col: textColor}.Add(ops)
|
gdraw.OpColor{Col: textColor}.Add(ops)
|
||||||
label := text.Label{Face: up.faces.For(fonts.regular, ui.Sp(12)), Text: msg}
|
label := text.Label{Face: up.faces.For(fonts.regular, ui.Sp(12)), Text: msg}
|
||||||
@@ -474,10 +480,7 @@ func (up *userPage) fetchCommits(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) layoutUsers(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
c := a.cfg
|
c := &a.cfg
|
||||||
a.fab.Update(c, a.queue)
|
|
||||||
a.edit.Update(c, a.queue)
|
|
||||||
a.edit2.Update(c, a.queue)
|
|
||||||
st := layout.Stack{Alignment: layout.Center}
|
st := layout.Stack{Alignment: layout.Center}
|
||||||
st.Init(ops, cs)
|
st.Init(ops, cs)
|
||||||
cs = st.Rigid()
|
cs = st.Rigid()
|
||||||
@@ -535,14 +538,10 @@ 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) Update(c *ui.Config, q input.Events) {
|
|
||||||
a.cfg = c
|
|
||||||
a.btnsClicker.Update(q)
|
|
||||||
a.btnClicker.Update(q)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ActionButton) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *ActionButton) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
c := a.cfg
|
a.btnsClicker.Update(a.inputs)
|
||||||
|
a.btnClicker.Update(a.inputs)
|
||||||
|
c := a.config
|
||||||
fabCol := brandColor
|
fabCol := brandColor
|
||||||
f := layout.Flex{Axis: layout.Vertical, MainAxisAlignment: layout.Start, CrossAxisAlignment: layout.End, MainAxisSize: layout.Min}
|
f := layout.Flex{Axis: layout.Vertical, MainAxisAlignment: layout.Start, CrossAxisAlignment: layout.End, MainAxisSize: layout.Min}
|
||||||
f.Init(ops, cs)
|
f.Init(ops, cs)
|
||||||
@@ -557,9 +556,8 @@ func (a *ActionButton) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) layoutContributors(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) layoutContributors(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
c := a.cfg
|
c := &a.cfg
|
||||||
l := a.usersList
|
l := a.usersList
|
||||||
l.Update(c, a.queue)
|
|
||||||
if l.Dragging() {
|
if l.Dragging() {
|
||||||
key.OpHideInput{}.Add(ops)
|
key.OpHideInput{}.Add(ops)
|
||||||
}
|
}
|
||||||
@@ -578,9 +576,9 @@ func (a *App) layoutContributors(ops *ui.Ops, cs layout.Constraints) layout.Dime
|
|||||||
func (a *App) user(ops *ui.Ops, cs layout.Constraints, c *ui.Config, index int) layout.Dimens {
|
func (a *App) user(ops *ui.Ops, cs layout.Constraints, c *ui.Config, index int) layout.Dimens {
|
||||||
u := a.users[index]
|
u := a.users[index]
|
||||||
click := &a.userClicks[index]
|
click := &a.userClicks[index]
|
||||||
for _, r := range click.Update(a.queue) {
|
for _, r := range click.Update(a.inputs) {
|
||||||
if r.Type == gesture.TypeClick {
|
if r.Type == gesture.TypeClick {
|
||||||
a.selectedUser = newUserPage(a.ctx, u, a.w.Redraw, a.faces)
|
a.selectedUser = a.newUserPage(u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elem := layout.Flex{Axis: layout.Vertical, MainAxisAlignment: layout.Start, CrossAxisAlignment: layout.Start}
|
elem := layout.Flex{Axis: layout.Vertical, MainAxisAlignment: layout.Start, CrossAxisAlignment: layout.Start}
|
||||||
|
|||||||
+3
-2
@@ -42,7 +42,8 @@ func loop(w *app.Window) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("failed to load font")
|
panic("failed to load font")
|
||||||
}
|
}
|
||||||
var faces measure.Faces
|
var cfg ui.Config
|
||||||
|
faces := &measure.Faces{Config: &cfg}
|
||||||
maroon := color.NRGBA{127, 0, 0, 255}
|
maroon := color.NRGBA{127, 0, 0, 255}
|
||||||
face := faces.For(regular, ui.Sp(72))
|
face := faces.For(regular, ui.Sp(72))
|
||||||
message := "Hello, Gio"
|
message := "Hello, Gio"
|
||||||
@@ -51,7 +52,7 @@ func loop(w *app.Window) {
|
|||||||
e := <-w.Events()
|
e := <-w.Events()
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case app.Draw:
|
case app.Draw:
|
||||||
faces.Cfg = e.Config
|
cfg = e.Config
|
||||||
cs := layout.ExactConstraints(w.Size())
|
cs := layout.ExactConstraints(w.Size())
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
draw.OpColor{Col: maroon}.Add(ops)
|
draw.OpColor{Col: maroon}.Add(ops)
|
||||||
|
|||||||
Reference in New Issue
Block a user