webview_ruby2 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/webview/webview.h +41 -8
- data/lib/webview_ruby/version.rb +1 -1
- data/lib/webview_ruby.rb +9 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eab6f29582a4a04bebb7dc1dd14db38e2d4d1041afc111c940129e7549f06480
|
4
|
+
data.tar.gz: 8a423ecb26825ae46df65aaeb7d2b6763aeec91addf4d83e8087856cddcf774c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ee929f420cb6e1ebdf72eaca0f5a0630f7d1ffb22279054da5020abeca3d89641a7bf9a7c891b0cf99f9dfe5ddb7f5e9ead22def4cde1a2d60468ebb542710
|
7
|
+
data.tar.gz: b4d969cbc08b75206f8ff9483bf76acacb340b4744aa72424ec79a2604c4abb4589f0596fd00cb3c59a163316b5dd054c3bbb03b43e6c4147866346d8f85241c
|
data/ext/webview/webview.h
CHANGED
@@ -66,6 +66,9 @@ WEBVIEW_API void *webview_get_window(webview_t w);
|
|
66
66
|
// Updates the title of the native window. Must be called from the UI thread.
|
67
67
|
WEBVIEW_API void webview_set_title(webview_t w, const char *title);
|
68
68
|
|
69
|
+
// Update the background color of the native window
|
70
|
+
WEBVIEW_API void webview_set_bg(webview_t w, double r, double g, double b, double a);
|
71
|
+
|
69
72
|
// Window size hints
|
70
73
|
#define WEBVIEW_HINT_NONE 0 // Width and height are default size
|
71
74
|
#define WEBVIEW_HINT_MIN 1 // Width and height are minimum bounds
|
@@ -73,7 +76,7 @@ WEBVIEW_API void webview_set_title(webview_t w, const char *title);
|
|
73
76
|
#define WEBVIEW_HINT_FIXED 3 // Window size can not be changed by a user
|
74
77
|
// Updates native window size. See WEBVIEW_HINT constants.
|
75
78
|
WEBVIEW_API void webview_set_size(webview_t w, int width, int height,
|
76
|
-
int hints);
|
79
|
+
int hints, int margin_top, bool resizable);
|
77
80
|
|
78
81
|
// Navigates webview to the given URL. URL may be a data URI, i.e.
|
79
82
|
// "data:text/text,<html>...</html>". It is often ok not to url-encode it
|
@@ -705,6 +708,7 @@ public:
|
|
705
708
|
},
|
706
709
|
};
|
707
710
|
)script");
|
711
|
+
|
708
712
|
((void (*)(id, SEL, id))objc_msgSend)(m_window, "setContentView:"_sel,
|
709
713
|
m_webview);
|
710
714
|
((void (*)(id, SEL, id))objc_msgSend)(m_window, "makeKeyAndOrderFront:"_sel,
|
@@ -734,25 +738,45 @@ public:
|
|
734
738
|
delete f;
|
735
739
|
}));
|
736
740
|
}
|
741
|
+
|
742
|
+
void set_bg(double r, double g, double b, double a) {
|
743
|
+
((void (*)(id, SEL, id))objc_msgSend)(
|
744
|
+
m_window, "setBackgroundColor:"_sel,
|
745
|
+
((id(*)(id, SEL, double, double, double, double))objc_msgSend)(
|
746
|
+
"NSColor"_cls, "colorWithRed:green:blue:alpha:"_sel, r, g, b, a));
|
747
|
+
}
|
748
|
+
|
737
749
|
void set_title(const std::string title) {
|
738
750
|
((void (*)(id, SEL, id))objc_msgSend)(
|
739
751
|
m_window, "setTitle:"_sel,
|
740
752
|
((id(*)(id, SEL, const char *))objc_msgSend)(
|
741
753
|
"NSString"_cls, "stringWithUTF8String:"_sel, title.c_str()));
|
742
754
|
}
|
743
|
-
void set_size(int width, int height, int hints) {
|
744
|
-
|
745
|
-
|
746
|
-
|
755
|
+
void set_size(int width, int height, int hints, int margin_top, bool resizable) {
|
756
|
+
int style;
|
757
|
+
if (resizable) {
|
758
|
+
style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
759
|
+
NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskFullSizeContentView;
|
760
|
+
} else {
|
761
|
+
printf("not resizable!!!\n");
|
762
|
+
style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
763
|
+
NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskFullSizeContentView;
|
764
|
+
}
|
747
765
|
|
766
|
+
/*
|
748
767
|
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
749
768
|
m_window, "setTitleVisibility:"_sel, NSWindowTitleHidden);
|
769
|
+
*/
|
750
770
|
|
751
771
|
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
752
772
|
m_window, "setTitlebarAppearsTransparent:"_sel, 1);
|
753
773
|
|
774
|
+
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
775
|
+
m_window, "setMovableByWindowBackground:"_sel, 1);
|
776
|
+
|
777
|
+
|
754
778
|
if (hints != WEBVIEW_HINT_FIXED) {
|
755
|
-
|
779
|
+
//style = style | NSWindowStyleMaskResizable;
|
756
780
|
}
|
757
781
|
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
758
782
|
m_window, "setStyleMask:"_sel, style);
|
@@ -767,6 +791,11 @@ public:
|
|
767
791
|
((void (*)(id, SEL, CGRect, BOOL, BOOL))objc_msgSend)(
|
768
792
|
m_window, "setFrame:display:animate:"_sel,
|
769
793
|
CGRectMake(0, 0, width, height), 1, 0);
|
794
|
+
|
795
|
+
((void (*)(id, SEL, CGRect))objc_msgSend)(
|
796
|
+
m_webview, "setFrame:"_sel,
|
797
|
+
CGRectMake(0, 0, width, height - margin_top));
|
798
|
+
|
770
799
|
}
|
771
800
|
((void (*)(id, SEL))objc_msgSend)(m_window, "center"_sel);
|
772
801
|
}
|
@@ -1341,9 +1370,13 @@ WEBVIEW_API void webview_set_title(webview_t w, const char *title) {
|
|
1341
1370
|
static_cast<webview::webview *>(w)->set_title(title);
|
1342
1371
|
}
|
1343
1372
|
|
1373
|
+
WEBVIEW_API void webview_set_bg(webview_t w, double r, double g, double b, double a) {
|
1374
|
+
static_cast<webview::webview *>(w)->set_bg(r, g, b, a);
|
1375
|
+
}
|
1376
|
+
|
1344
1377
|
WEBVIEW_API void webview_set_size(webview_t w, int width, int height,
|
1345
|
-
int hints) {
|
1346
|
-
static_cast<webview::webview *>(w)->set_size(width, height, hints);
|
1378
|
+
int hints, int margin_top, bool resizable) {
|
1379
|
+
static_cast<webview::webview *>(w)->set_size(width, height, hints, margin_top, resizable);
|
1347
1380
|
}
|
1348
1381
|
|
1349
1382
|
WEBVIEW_API void webview_navigate(webview_t w, const char *url) {
|
data/lib/webview_ruby/version.rb
CHANGED
data/lib/webview_ruby.rb
CHANGED
@@ -12,7 +12,8 @@ module WebviewRuby
|
|
12
12
|
attach_function :webview_run, [:pointer], :void
|
13
13
|
attach_function :webview_terminate, [:pointer], :void
|
14
14
|
attach_function :webview_set_title, [:pointer, :string], :void
|
15
|
-
attach_function :
|
15
|
+
attach_function :webview_set_bg, [:pointer, :double, :double, :double, :double], :void
|
16
|
+
attach_function :webview_set_size, [:pointer, :int, :int, :int, :int, :bool], :void
|
16
17
|
attach_function :webview_navigate, [:pointer, :string], :void
|
17
18
|
attach_function :webview_destroy, [:pointer], :void
|
18
19
|
attach_function :webview_bind, [:pointer, :string, :pointer, :pointer], :void
|
@@ -28,12 +29,16 @@ module WebviewRuby
|
|
28
29
|
@window = WebviewRuby.webview_create(debug ? 1 : 0, nil)
|
29
30
|
end
|
30
31
|
|
32
|
+
def set_bg(r, g, b, a)
|
33
|
+
WebviewRuby.webview_set_bg(@window, r, g, b, a)
|
34
|
+
end
|
35
|
+
|
31
36
|
def set_title(title)
|
32
37
|
WebviewRuby.webview_set_title(@window, title)
|
33
38
|
end
|
34
39
|
|
35
|
-
def set_size(width, height, hint=0)
|
36
|
-
WebviewRuby.webview_set_size(@window, width, height, hint)
|
40
|
+
def set_size(width, height, hint=0, margin_top=26, resizable=true)
|
41
|
+
WebviewRuby.webview_set_size(@window, width, height, hint, margin_top, resizable)
|
37
42
|
end
|
38
43
|
|
39
44
|
def navigate(page)
|
@@ -56,7 +61,7 @@ module WebviewRuby
|
|
56
61
|
|
57
62
|
def bind(name, func=nil, &block)
|
58
63
|
callback = FFI::Function.new(:void, [:string, :string, :pointer]) do |seq, req, arg|
|
59
|
-
begin
|
64
|
+
begin
|
60
65
|
params = JSON.parse(req)
|
61
66
|
if func
|
62
67
|
func(*params)
|