Skip to content

Commit

Permalink
[framework] add paste
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Feb 26, 2023
1 parent 172a52b commit cc93b1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions coreWSI.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ type NormalEvent interface {
FyVOffset(amount Vec2i) NormalEvent
}

// SDL keycode modifiers - https://github.com/libsdl-org/SDL/blob/213fbd0/include/SDL3/SDL_keycode.h#L332-L354
// (also see https://wiki.libsdl.org/SDL2/SDLKeycodeLookup)
const (
ModifierCtrl uint16 = 0x40 | 0x80
ModifierShift uint16 = 0x1 | 0x2
ModifierAlt uint16 = 0x100 | 0x200
)

// KeyEvent represents a key changing state. It uses the same constants as SDL2 because I never planned for key input to be in here, but then someone said "what about a search box". Nevermind that this opens a massive can of worms...
type KeyEvent struct {
Pressed bool
Expand Down
20 changes: 16 additions & 4 deletions framework/uiLibTextInput.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package framework

import (
"fmt"

"github.com/uwu/frenyard"
"github.com/uwu/frenyard/integration"
"github.com/veandco/go-sdl2/sdl"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
)
Expand Down Expand Up @@ -85,7 +88,7 @@ func (tb *UITextbox) FyETick(delta float64) {
if tb._open {
// 3/2 because it just feels a little slow
// and this is an easy way to fix that up
tb._caretBlinker += (delta * 3/2)
tb._caretBlinker += (delta * 3 / 2)

if tb._caretBlinker >= 2 {
tb._caretBlinker -= 2
Expand Down Expand Up @@ -152,9 +155,9 @@ func (tb *UITextbox) FyEDraw(target frenyard.Renderer, under bool) {
}

caretColour := tb._primaryColour
if tb._caretBlinker > 1 || !tb._open {
caretColour = 0
}
if tb._caretBlinker > 1 || !tb._open {
caretColour = 0
}

target.DrawRect(frenyard.DrawRectCommand{
Colour: caretColour,
Expand Down Expand Up @@ -223,6 +226,15 @@ func (tb *UITextbox) FyENormalEvent(ne frenyard.NormalEvent) {
}
tb.rebuild()
}
} else if (ev.Keycode == 118) && ((ev.Modifiers & frenyard.ModifierCtrl) > 0) {
// Ctrl-V
clip, err := sdl.GetClipboardText()
if err != nil {
fmt.Printf("paste threw error: %s\n", err.Error())
} else {
tb._textPre = tb._textPre + clip
tb.rebuild()
}
}
}
}
Expand Down

0 comments on commit cc93b1e

Please sign in to comment.