clipboard: fix get_text() on macos
parent
925b40e2c0
commit
d50c919879
|
@ -1360,6 +1360,7 @@ inline int sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
|
|||
@end
|
||||
@interface _sapp_macos_window_delegate : NSObject<NSWindowDelegate>
|
||||
@end
|
||||
|
||||
#if defined(SOKOL_METAL)
|
||||
@interface _sapp_macos_view : MTKView
|
||||
@end
|
||||
|
|
|
@ -3,6 +3,9 @@ module clipboard
|
|||
#include <libkern/OSAtomic.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#flag -framework Cocoa
|
||||
|
||||
#include "@VROOT/vlib/clipboard/clipboard_darwin.m"
|
||||
|
||||
pub struct Clipboard {
|
||||
pb voidptr
|
||||
last_cb_serial i64
|
||||
|
@ -10,11 +13,12 @@ mut:
|
|||
foo int // TODO remove, for mut hack
|
||||
}
|
||||
|
||||
fn C.darwin_new_pasteboard() voidptr
|
||||
fn C.darwin_get_pasteboard_text() byteptr
|
||||
|
||||
fn new_clipboard() &Clipboard {
|
||||
pb := voidptr(0)
|
||||
#pb = [NSPasteboard generalPasteboard];
|
||||
cb := &Clipboard{
|
||||
pb: pb
|
||||
pb: C.darwin_new_pasteboard()// pb
|
||||
}
|
||||
return cb
|
||||
}
|
||||
|
@ -59,13 +63,11 @@ fn (mut cb Clipboard) set_text(text string) bool {
|
|||
|
||||
fn (mut cb Clipboard) get_text() string {
|
||||
cb.foo = 0
|
||||
#NSString *ns_clip;
|
||||
utf8_clip := byteptr(0)
|
||||
#ns_clip = [cb->pb stringForType:NSStringPboardType]; //NSPasteboardTypeString
|
||||
#if (ns_clip == nil) {
|
||||
#return tos3(""); //in case clipboard is empty
|
||||
#}
|
||||
#utf8_clip = [ns_clip UTF8String];
|
||||
if isnil(cb.pb) {
|
||||
return ''
|
||||
}
|
||||
|
||||
utf8_clip := C.darwin_get_pasteboard_text(cb.pb)
|
||||
return unsafe {utf8_clip.vstring()}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
//NSPasteboard* darwin_new_pasteboard() {
|
||||
void* darwin_new_pasteboard() {
|
||||
return (__bridge void*) [NSPasteboard generalPasteboard];
|
||||
}
|
||||
|
||||
char* darwin_get_pasteboard_text(void* pb) {
|
||||
NSString *ns_clip = [((__bridge NSPasteboard*)pb) stringForType:NSStringPboardType]; //NSPasteboardTypeString
|
||||
if (ns_clip == nil) {
|
||||
return "";
|
||||
}
|
||||
return [ns_clip UTF8String];
|
||||
}
|
|
@ -114,9 +114,9 @@ pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
|
|||
}
|
||||
// text := text_.trim_space() // TODO remove/optimize
|
||||
mut text := text_
|
||||
if text.contains('\t') {
|
||||
text = text.replace('\t', ' ')
|
||||
}
|
||||
//if text.contains('\t') {
|
||||
//text = text.replace('\t', ' ')
|
||||
//}
|
||||
ctx.set_cfg(cfg)
|
||||
scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale }
|
||||
C.fonsDrawText(ctx.ft.fons, x * scale, y * scale, text.str, 0) // TODO: check offsets/alignment
|
||||
|
|
Loading…
Reference in New Issue