Skip to content

Commit 0ba1432

Browse files
authored
Merge pull request #1657 from cogentcore/ppath
ppath: fixes from tdewolff/canvas ppath, and a few other misc fixes..
2 parents f52ccd2 + 517121a commit 0ba1432

12 files changed

Lines changed: 91 additions & 20 deletions

File tree

content/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func (ct *Content) open(url string, history bool) {
382382
return
383383
}
384384
sli := strings.Index(url, "/")
385-
if sli > 0 {
385+
if sli > 0 && len(url) > sli+1 && url[sli+1] != '#' {
386386
fb, err := fs.ReadFile(ct.Source, url)
387387
if err != nil {
388388
core.MessageSnackbar(ct, "Resource at: "+url+" not found")

events/key/chord.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,45 @@ type Chord string
2121
// shortcut formatting based on the underlying system platform without import cycles.
2222
var SystemPlatform string
2323

24+
// KeypadMap maps the keypad versions to standard codes,
25+
// for non-printing characters.
26+
var KeypadMap = map[Codes]Codes{
27+
CodeKeypadEnter: CodeReturnEnter,
28+
CodeKeypadFullStop: CodeFullStop,
29+
CodeKeypadEqualSign: CodeEqualSign,
30+
}
31+
32+
// KeypadAlts are alternate codes for keypad keys to use when
33+
// the NumLock key is on.
34+
var KeypadAlts = map[Codes]Codes{
35+
CodeKeypad1: CodeEnd,
36+
CodeKeypad2: CodeDownArrow,
37+
CodeKeypad3: CodePageDown,
38+
CodeKeypad4: CodeLeftArrow,
39+
CodeKeypad6: CodeRightArrow,
40+
CodeKeypad7: CodeHome,
41+
CodeKeypad8: CodeUpArrow,
42+
CodeKeypad9: CodePageUp,
43+
CodeKeypad0: CodeInsert,
44+
CodeKeypadFullStop: CodeDelete,
45+
}
46+
2447
// NewChord returns a string representation of the keyboard event suitable for
2548
// keyboard function maps, etc. Printable runes are sent directly, and
2649
// non-printable ones are converted to their corresponding code names without
2750
// the "Code" prefix.
2851
func NewChord(rn rune, code Codes, mods Modifiers) Chord {
52+
mods.SetFlag(false, CapsLock)
53+
if !mods.HasFlag(NumLock) && code >= CodeKeypadNumLock && code < CodeKeypadEqualSign {
54+
if ac, ok := KeypadAlts[code]; ok {
55+
rn = 0
56+
code = ac
57+
}
58+
}
59+
if ac, ok := KeypadMap[code]; ok {
60+
code = ac
61+
}
62+
mods.SetFlag(false, NumLock)
2963
modstr := mods.ModifiersString()
3064
if modstr != "" && code == CodeSpacebar { // modified space is not regular space
3165
return Chord(modstr + "Spacebar")

events/key/chord_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestChordDecode(t *testing.T) {
1414
RunChordDecode(t, "a")
1515
RunChordDecode(t, "Control+A")
1616
RunChordDecode(t, "ReturnEnter")
17-
RunChordDecode(t, "KeypadEnter")
17+
// RunChordDecode(t, "KeypadEnter") // now returns ReturnEnter
1818
RunChordDecode(t, "Backspace")
1919
RunChordDecode(t, "Escape")
2020
}

events/key/codes.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ const (
165165
CodeCompose Codes = 0x10000
166166
)
167167

168-
// TODO: currently have to use official go stringer for this,
169-
// not custom one, which doesn't currently handle discontinuities
170-
// // go: generate stringer -type=Codes
171-
172168
// TODO: Given we use runes outside the unicode space, should we provide a
173169
// printing function? Related: it's a little unfortunate that printing a
174170
// events.Key with %v gives not very readable output like:
@@ -233,4 +229,14 @@ var CodeRuneMap = map[Codes]rune{
233229
CodeKeypadPlusSign: '+',
234230
CodeKeypadFullStop: '.',
235231
CodeKeypadEqualSign: '=',
232+
CodeKeypad1: '1',
233+
CodeKeypad2: '2',
234+
CodeKeypad3: '3',
235+
CodeKeypad4: '4',
236+
CodeKeypad5: '5',
237+
CodeKeypad6: '6',
238+
CodeKeypad7: '7',
239+
CodeKeypad8: '8',
240+
CodeKeypad9: '9',
241+
CodeKeypad0: '0',
236242
}

events/key/enumgen.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

events/key/modifiers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ const (
2828

2929
// Shift is the "Shift" key.
3030
Shift
31+
32+
// CapsLock indicates that CapsLock is toggled on at time of keypress
33+
CapsLock
34+
35+
// NumLock indicates that NumLock is toggled on at time of keypress
36+
NumLock
3137
)
3238

3339
// ModifiersString returns the string representation of the modifiers using

events/source.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,27 @@ func (es *Source) Key(typ Types, rn rune, code key.Codes, mods key.Modifiers) {
7373
ev.Init()
7474
es.Deque.Send(ev)
7575

76-
_, mapped := key.CodeRuneMap[code]
76+
mrn, mapped := key.CodeRuneMap[code]
7777

78-
if typ == KeyDown && ev.Code < key.CodeLeftControl &&
79-
(ev.HasAnyModifier(key.Control, key.Meta) || !mapped || ev.Code == key.CodeTab) {
78+
if typ != KeyDown {
79+
return
80+
}
81+
82+
if !ev.HasAnyModifier(key.NumLock) && code >= key.CodeKeypadNumLock && code < key.CodeKeypadEqualSign {
83+
if mapped {
84+
rn = mrn
85+
}
86+
che := NewKey(KeyChord, rn, code, mods)
87+
che.Init()
88+
es.Deque.Send(che)
89+
return
90+
}
91+
92+
if ev.Code < key.CodeLeftControl && (ev.HasAnyModifier(key.Control, key.Meta) || !mapped || ev.Code == key.CodeTab) {
8093
che := NewKey(KeyChord, rn, code, mods)
8194
che.Init()
8295
es.Deque.Send(che)
96+
return
8397
}
8498
}
8599

paint/ppath/intersect/bezier.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ func findInflectionPointRangeCubicBezier(p0, p1, p2, p3 math32.Vector2, t, toler
121121
// find the range around an inflection point that we consider flat within the flatness criterion
122122
if math32.IsNaN(t) {
123123
return math32.Inf(1), math32.Inf(1)
124-
}
125-
if t < 0.0 || t > 1.0 {
124+
} else if t < 0.0 || t > 1.0 {
126125
panic("t outside 0.0--1.0 range")
127126
}
128127

@@ -145,12 +144,12 @@ func findInflectionPointRangeCubicBezier(p0, p1, p2, p3 math32.Vector2, t, toler
145144

146145
if ppath.Equal(nr.X, 0.0) && ppath.Equal(nr.Y, 0.0) {
147146
// if rn is still zero, this curve has p0=p1=p2, so it is straight
148-
return 0.0, 1.0
147+
return math32.Max(0.0, 2.0*t-1.0), 1.0
149148
}
150149

151150
s3 := math32.Abs(ns.X*nr.Y-ns.Y*nr.X) / math32.Hypot(nr.X, nr.Y)
152151
if ppath.Equal(s3, 0.0) {
153-
return 0.0, 1.0 // can approximate whole curve linearly
152+
return math32.Max(0.0, 2.0*t-1.0), 1.0 // can approximate whole curve linearly
154153
}
155154

156155
tf := math32.Cbrt(tolerance / s3)

system/driver/desktop/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func (a *App) NewWindow(opts *system.NewWindowOptions) (system.Window, error) {
152152
w.Glw.SetCursorPosCallback(w.CursorPosEvent)
153153
w.Glw.SetCursorEnterCallback(w.CursorEnterEvent)
154154
w.Glw.SetDropCallback(w.DropEvent)
155+
w.Glw.SetInputMode(glfw.LockKeyMods, glfw.True)
155156

156157
w.Show()
157158
a.RunOnMain(func() {

system/driver/desktop/event.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func GlfwMods(mod glfw.ModifierKey) key.Modifiers {
2929
if mod&glfw.ModSuper != 0 {
3030
m.SetFlag(true, key.Meta)
3131
}
32+
if mod&glfw.ModCapsLock != 0 {
33+
m.SetFlag(true, key.CapsLock)
34+
}
35+
if mod&glfw.ModNumLock != 0 {
36+
m.SetFlag(true, key.NumLock)
37+
}
3238
return m
3339
}
3440

@@ -45,6 +51,9 @@ func (w *Window) FocusWindow() *Window {
4551
// physical key
4652
func (w *Window) KeyEvent(gw *glfw.Window, ky glfw.Key, scancode int, action glfw.Action, mod glfw.ModifierKey) {
4753
mods := GlfwMods(mod)
54+
if TheApp.Platform() == system.MacOS {
55+
mods.SetFlag(true, key.NumLock) // mac always acts like numlock is on
56+
}
4857
ec := GlfwKeyCode(ky)
4958
rn := key.CodeRuneMap[ec]
5059
typ := events.KeyDown

0 commit comments

Comments
 (0)