Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to get webview inside Nigui? #186

Open
harrier77 opened this issue May 11, 2024 · 2 comments
Open

It is possible to get webview inside Nigui? #186

harrier77 opened this issue May 11, 2024 · 2 comments

Comments

@harrier77
Copy link

harrier77 commented May 11, 2024

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.

@harrier77
Copy link
Author

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.

@harrier77
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant