Skip to content

Commit

Permalink
Fix copyable for new gio api
Browse files Browse the repository at this point in the history
  • Loading branch information
psanford committed Nov 30, 2024
1 parent a9fe7b9 commit 748fea5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
12 changes: 8 additions & 4 deletions ui/copyable.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ui

import (
"io"
"strings"

"gioui.org/io/clipboard"
"gioui.org/layout"
"gioui.org/unit"
Expand Down Expand Up @@ -30,10 +33,11 @@ func (c *Copyable) Text() string {
func (r *Copyable) Layout(gtx C) D {
// if the copy button was clicked, write the contents of the editor
// into the system clipboard.
if r.copyButton.Clicked() {
clipboard.WriteOp{
Text: r.text,
}.Add(gtx.Ops)
if r.copyButton.Clicked(gtx) {
gtx.Execute(clipboard.WriteCmd{
Type: "application/text",
Data: io.NopCloser(strings.NewReader(r.text)),
})
}

return D{}
Expand Down
17 changes: 6 additions & 11 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func (ui *UI) sendFile(ctx context.Context, w *app.Window, path, filename string

var (
textMsgEditor = new(RichEditor)
textCodeTxt = new(widget.Editor)
textCodeTxt = new(Copyable)
sendTextBtn = new(widget.Clickable)

rendezvousEditor = &widget.Editor{
Expand All @@ -567,12 +567,12 @@ var (
recvCodeEditor = new(RichEditor)
recvMsgBtn = new(widget.Clickable)
scanQRBtn = new(widget.Clickable)
recvTxtMsg = new(widget.Editor)
recvTxtMsg = new(Copyable)
itemList = &layout.List{
Axis: layout.Vertical,
}

sendFileCodeTxt = new(widget.Editor)
sendFileCodeTxt = new(Copyable)
sendFileBtn = new(widget.Clickable)

topLabel = "Wormhole William"
Expand Down Expand Up @@ -700,8 +700,7 @@ var sendTextTab = Tab{
func(gtx C) D {
if textCodeTxt.Text() != "" {
gtx.Constraints.Max.Y = gtx.Dp(400)
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return material.Editor(th, textCodeTxt, "").Layout(gtx)
return CopyField(th, textCodeTxt).Layout(gtx)
}
return D{}
},
Expand Down Expand Up @@ -758,9 +757,7 @@ var recvTab = Tab{
},
func(gtx C) D {
gtx.Constraints.Max.Y = gtx.Dp(200)
return material.Editor(th, recvTxtMsg, "").Layout(gtx)
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// return CopyField(th, recvTxtMsg).Layout(gtx, th.Shaper, font.Font{}, unit.Sp(12), op.CallOp{}, op.CallOp{})
return CopyField(th, recvTxtMsg).Layout(gtx)
},
}

Expand Down Expand Up @@ -815,9 +812,7 @@ var sendFileTab = Tab{
},
func(gtx C) D {
gtx.Constraints.Max.Y = gtx.Dp(400)
return material.Editor(th, sendFileCodeTxt, "").Layout(gtx)
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// return CopyField(th, sendFileCodeTxt).Layout(gtx, th.Shaper, font.Font{}, unit.Sp(12), op.CallOp{}, op.CallOp{})
return CopyField(th, sendFileCodeTxt).Layout(gtx)
},
func(gtx C) D {
if transferInProgress || confirmInProgress {
Expand Down

0 comments on commit 748fea5

Please sign in to comment.