webview_java icon indicating copy to clipboard operation
webview_java copied to clipboard

The default size cannot be set when creating a Webview directly.

Open HKMV opened this issue 1 year ago • 7 comments

Use Webview wv = new Webview(true, 800, 600); create Webview; You will see that the window changes from small to large, instead of being 800x600 when it appears.

Looking at the source code, I found that Webview(true, 800, 600) only calls the setSize method internally, and does not set the initial size.

How do I set the default size during initialization?

OS:Windows11 JDK: OpenJDK21

HKMV avatar Sep 02 '24 03:09 HKMV

我遇到了同样的问题,在创建Webview实例并且执行setSize()的时候会发生动画过渡不太流畅的窗口尺寸变化。

后来我发现作者的主页 fork 了一个仓库 https://github.com/e3ndr/webview-nightly-build-fork 这个项目的script文件夹中有脚本可以生成dll文件,可以通过修改webview.h来生成目标webview.dllWebView2Loader.dll

在 https://github.com/e3ndr/webview-nightly-build-fork/blob/build-latest-commit/webview.h 这个文件中有一处代码为:

constexpr const int initial_width = 640;
constexpr const int initial_height = 480;
set_size(initial_width, initial_height, WEBVIEW_HINT_NONE);

image 刚好经过我测试640x480就是webview_java这个项目创建窗口时默认的尺寸,但是由于我对C/C++语言不太熟悉,能力有限。如果能够办法将下面这部分代码中的 initial_widthinitial_height 通过Java程序调用webview的时候传进来,应该是可以避免你说的这个问题的。

set_size(initial_width, initial_height, WEBVIEW_HINT_NONE);

isinvon avatar Nov 03 '24 09:11 isinvon

@isinvon 感谢,我略微有些了解,我抽空看下

HKMV avatar Nov 03 '24 14:11 HKMV

@isinvon 你好,我这边已做适配,在我电脑上测试已经可以。java项目中暂时只提交了win下x86_64的类库,后面再补全其他的。

webview: https://github.com/HKMV/webview-nightly-build-fork webview_java: https://github.com/HKMV/webview_java

HKMV avatar Nov 04 '24 08:11 HKMV

@HKMV 测试完美,真是太感谢您了!!!!

isinvon avatar Nov 04 '24 08:11 isinvon

Can confirm, NotJustAnna/webview fixes behavior highlighted by this issue and issue https://github.com/webview/webview_java/issues/34.

https://github.com/user-attachments/assets/8bd08163-d21f-4ea1-a262-560c3852800c

NotJustAnna avatar Apr 16 '25 11:04 NotJustAnna

Can confirm, NotJustAnna/webview fixes behavior highlighted by this issue and issue https://github.com/webview/webview_java/issues/34.

I have fixed this problem above, you can take it as a reference, my repair is as follows: webview: https://github.com/HKMV/webview-nightly-build-fork webview_java: https://github.com/HKMV/webview_java https://github.com/user-attachments/assets/8bd08163-d21f-4ea1-a262-560c3852800c

HKMV avatar Apr 16 '25 14:04 HKMV

Can confirm, NotJustAnna/webview fixes behavior highlighted by this issue and issue #34.

I have fixed this problem above, you can take it as a reference, my repair is as follows: webview: https://github.com/HKMV/webview-nightly-build-fork webview_java: https://github.com/HKMV/webview_java https://github.com/user-attachments/assets/8bd08163-d21f-4ea1-a262-560c3852800c

The fix was made mostly by being on the main repository, as SteffenL highlighted here: https://github.com/webview/webview/issues/1296#issuecomment-2809307173

I believe the following PRs were meant to fix the issue described by webview/webview_java#30:

These PRs introduced dispatch_size_default() less than a month ago.

The fix on my fork was just removing the setSize() call made by webview_java and updating binaries to run on the latest commit.

NotJustAnna avatar Apr 16 '25 14:04 NotJustAnna