mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
io/clipboard,app: add WriteOp, ReadOp
Previously, the only way to manipulate the clipboard (read or write) is using the `app.Window`. The new `clipboard.ReadOp` and `clipboard.WriteOp`makes possible to read/write from the widget. Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
@@ -2,9 +2,36 @@
|
||||
|
||||
package clipboard
|
||||
|
||||
import (
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
// Event is generated when the clipboard content is requested.
|
||||
type Event struct {
|
||||
Text string
|
||||
}
|
||||
|
||||
// ReadOp requests the text of the clipboard, delivered to
|
||||
// the current handler through an Event.
|
||||
type ReadOp struct {
|
||||
Tag event.Tag
|
||||
}
|
||||
|
||||
// WriteOp copies Text to the clipboard.
|
||||
type WriteOp struct {
|
||||
Text string
|
||||
}
|
||||
|
||||
func (h ReadOp) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeClipboardReadLen, h.Tag)
|
||||
data[0] = byte(opconst.TypeClipboardRead)
|
||||
}
|
||||
|
||||
func (h WriteOp) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeClipboardWriteLen, &h.Text)
|
||||
data[0] = byte(opconst.TypeClipboardWrite)
|
||||
}
|
||||
|
||||
func (Event) ImplementsEvent() {}
|
||||
|
||||
Reference in New Issue
Block a user