Open harrier77 opened 4 months ago
I wanted to learn something more about Nigui and about nim dynlib import. I tried to show a webkit2 control in a gtk window and I succeded with this two import:
proc webkit_web_view_new(): pointer {.cdecl, dynlib: "libwebkit2gtk-4.0.so", importc.}
proc webkit_web_view_load_uri(webkit:pointer,uri:cstring) {.cdecl, dynlib: "libwebkit2gtk-4.0.so", importc.}
after linking the two proc I have created a gtk window and I have added the webkit control
var g = gtk_init(0,0)
var window = gtk_window_new(0)
let miowbk=webkit_web_view_new()
gtk_container_add(window,miowbk)
gtk_widget_show_all(window)
gtk_main()
But I can not use it with Nigui How can I make a new Nigui control with the webkit inside? I tried subclassing Control and linking webkit_web_view_new() as a pointer to fHandle, everything compiles with no errors but it does not show anything.
Update of my previous post: I have finally found out why there was nothing visible on the Nigui window of the gtk widget I made calling gtk proc webkit_web_view_new(). Height and width were missing in the new created widget . I added them in the new proc and the webkit widget magically showed:
proc newWebkit(): Webkit =
result = new NativeWebkit
result.Webkit.init()
result.NativeWebkit.init()
result.fHandle = webkit_web_view_new()
webkit_web_view_load_uri(result.fHandle, "file://index.html")
result.height=500
result.width=500
result.show()
To make possible to set result.fHandle I had to add a * in platform.types1.nim at line 13, because the original fHandle was private.
ControlImpl* = ref object of Control
fHandle*: pointer
fHScrollbar: pointer
fVScrollbar: pointer
I recently tried webview in Linux and in Windows and it seems very interesting. I found a post on Nim forum with some lines of code with which I compiled a full working webview. I was thinking it should be very useful to have a Nigui window with a webview control inside (the original webview is an independent gtk or win32 window without the possibility to set buttons or other controls). Wxwidget has a control like this, but in Windows it has the old webview and not the new webview2 based on edge/chrome.