blob: 58473db75142b69a18bb5059a612c5c74389ca9d (
plain)
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
|
package gui
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
)
// CustomMultiLineEntry extends widget.Entry to handle Escape key
type CustomMultiLineEntry struct {
widget.Entry
onEscape func()
}
// NewCustomMultiLineEntry creates a new custom multi-line entry
func NewCustomMultiLineEntry() *CustomMultiLineEntry {
entry := &CustomMultiLineEntry{}
entry.MultiLine = true
entry.ExtendBaseWidget(entry)
return entry
}
// TypedKey handles key events
func (e *CustomMultiLineEntry) TypedKey(key *fyne.KeyEvent) {
if key.Name == fyne.KeyEscape && e.onEscape != nil {
e.onEscape()
return
}
e.Entry.TypedKey(key)
}
// SetOnEscape sets the callback for when Escape is pressed
func (e *CustomMultiLineEntry) SetOnEscape(f func()) {
e.onEscape = f
}
// CustomEntry extends widget.Entry to handle Escape key (single-line version)
type CustomEntry struct {
widget.Entry
onEscape func()
}
// NewCustomEntry creates a new custom single-line entry
func NewCustomEntry() *CustomEntry {
entry := &CustomEntry{}
entry.ExtendBaseWidget(entry)
return entry
}
// TypedKey handles key events
func (e *CustomEntry) TypedKey(key *fyne.KeyEvent) {
if key.Name == fyne.KeyEscape && e.onEscape != nil {
e.onEscape()
return
}
e.Entry.TypedKey(key)
}
// SetOnEscape sets the callback for when Escape is pressed
func (e *CustomEntry) SetOnEscape(f func()) {
e.onEscape = f
}
|