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

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

Open
HKMV opened this issue Sep 2, 2024 · 4 comments
Open

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

HKMV opened this issue Sep 2, 2024 · 4 comments

Comments

@HKMV
Copy link

HKMV commented Sep 2, 2024

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

@isinvon
Copy link

isinvon commented Nov 3, 2024

我遇到了同样的问题,在创建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);

@HKMV
Copy link
Author

HKMV commented Nov 3, 2024

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

@HKMV
Copy link
Author

HKMV commented Nov 4, 2024

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

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

@isinvon
Copy link

isinvon commented Nov 4, 2024

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

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

2 participants