diff --git a/thirdparty/sokol/sokol_app.h b/thirdparty/sokol/sokol_app.h index da91a2db1f..6300cc855a 100644 --- a/thirdparty/sokol/sokol_app.h +++ b/thirdparty/sokol/sokol_app.h @@ -1360,6 +1360,7 @@ inline int sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } @end @interface _sapp_macos_window_delegate : NSObject @end + #if defined(SOKOL_METAL) @interface _sapp_macos_view : MTKView @end @@ -5452,7 +5453,7 @@ _SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM _sapp_wgl_swap_buffers(); #endif /* NOTE: resizing the swap-chain during resize leads to a substantial - memory spike (hundreds of megabytes for a few seconds). + memory spike (hundreds of megabytes for a few seconds). if (_sapp_win32_update_dimensions()) { #if defined(SOKOL_D3D11) diff --git a/vlib/clipboard/clipboard_darwin.c.v b/vlib/clipboard/clipboard_darwin.c.v index aee2b8045b..a0186bb06b 100644 --- a/vlib/clipboard/clipboard_darwin.c.v +++ b/vlib/clipboard/clipboard_darwin.c.v @@ -3,6 +3,9 @@ module clipboard #include #include #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()} } diff --git a/vlib/clipboard/clipboard_darwin.m b/vlib/clipboard/clipboard_darwin.m new file mode 100644 index 0000000000..586969805e --- /dev/null +++ b/vlib/clipboard/clipboard_darwin.m @@ -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]; +} diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index 6f866b29c5..03f2451e62 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -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