Skip to content

Implemented a way to choose logical or physical sizing/position#38

Merged
twlite merged 17 commits into
webviewjs:mainfrom
Lawtro37:main2
Jun 20, 2026
Merged

Implemented a way to choose logical or physical sizing/position#38
twlite merged 17 commits into
webviewjs:mainfrom
Lawtro37:main2

Conversation

@Lawtro37

Copy link
Copy Markdown
Contributor

Also added other functions such as, "getSize()", "setPosition()" and "getPosition()" all suporting both logical and physical sizing/positioning.

Lawtro37 added 6 commits June 19, 2026 14:43
This will open a file browser window that can be customised via the "FileDialogOptions" and "FileFilters".
Also added other functions such as, "get_size", "set_position" and "get_position" all suporting both logical and physical sizing/positioning.
Also added other functions such as, "getSize", "setPosition" and "getPosition" all suporting both logical and physical sizing/positioning.
@Lawtro37

Copy link
Copy Markdown
Contributor Author

ignore the file dialoge stuff I removed that, its in another pull request

@twlite twlite left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@twlite

twlite commented Jun 19, 2026

Copy link
Copy Markdown
Member

@Lawtro37 could you fix the merge conflict?

@Lawtro37

Copy link
Copy Markdown
Contributor Author

uh oh
give me a sec I'll make it not have that function for android

@Lawtro37

Copy link
Copy Markdown
Contributor Author

I am very stupid. wtf am I doing. I can just keep the structs as they are.

…ng not supported on android

why didn't I do this from the start?
I have no idea what I was doing before.
@Lawtro37

Copy link
Copy Markdown
Contributor Author

Okay finally.
It should be safe to merge the PR now.

@Lawtro37

Copy link
Copy Markdown
Contributor Author

wait hold on somehow I managed to remove the main thing of this PR. Let me fix that.

@Lawtro37

Copy link
Copy Markdown
Contributor Author

holy merge conflict

@Lawtro37

Copy link
Copy Markdown
Contributor Author

@twlite I don't see anything about set_min_size() or set_max_size() from cf8cc47 in the merge conflict but they are not implemented in my fork or anything so idk what's going to happen to that if you merge this PR.

@zhuxiaojt

Copy link
Copy Markdown
Contributor

Merging won't cause conflicts, but you should be able to find two set_position functions with the same name along with other functions.

Fragment of cf8cc47:

+ // ── Position ────────────────────────────────────────────────────────────────
+ 
+ /// Returns the window's outer top-left position in physical pixels, or
+ /// `null` if the platform does not expose it.
+ #[napi]
+ pub fn get_position(&self) -> Option<Position> {
+   self.window.outer_position().ok().map(|p| Position { x: p.x, y: p.y })
+ }
+ 
+ /// Move the window so its outer top-left corner is at (`x`, `y`) in
+ /// physical pixels.
+ #[napi]
+ pub fn set_position(&self, x: i32, y: i32) {
+   self.window.set_outer_position(PhysicalPosition::new(x, y));
+ }
+ 
+ /// Center the window on its current monitor.  Does nothing if the current
+ /// monitor cannot be determined.
+ #[napi]
+ pub fn center(&self) {
+   if let Some(monitor) = self.window.current_monitor() {
+     let mpos = monitor.position();
+     let msize = monitor.size();
+     let wsize = self.window.outer_size();
+     let x = mpos.x + (msize.width as i32 - wsize.width as i32) / 2;
+     let y = mpos.y + (msize.height as i32 - wsize.height as i32) / 2;
+     self.window.set_outer_position(PhysicalPosition::new(x, y));
+   }
+ }
+ 
+ // ── Size queries & constraints ───────────────────────────────────────────────
+ 
+ /// Inner (content-area) size in physical pixels.
+ #[napi]
+ pub fn get_size(&self) -> Dimensions {
+   let s = self.window.inner_size();
+   Dimensions { width: s.width, height: s.height }
+ }
+ 
+ /// Outer (including decorations) size in physical pixels.
+ #[napi]
+ pub fn get_outer_size(&self) -> Dimensions {
+   let s = self.window.outer_size();
+   Dimensions { width: s.width, height: s.height }
+ }
+ 
+ /// Set minimum inner size.  Pass `null` / `undefined` for both to remove the
+ /// constraint.
+ #[napi]
+ pub fn set_min_size(&self, width: Option<f64>, height: Option<f64>) {
+   let size: Option<winit::dpi::Size> = match (width, height) {
+     (Some(w), Some(h)) => Some(LogicalSize::new(w, h).into()),
+     _ => None,
+   };
+   self.window.set_min_inner_size(size);
+ }
+ 
+ /// Set maximum inner size.  Pass `null` / `undefined` for both to remove the
+ /// constraint.
+ #[napi]
+ pub fn set_max_size(&self, width: Option<f64>, height: Option<f64>) {
+   let size: Option<winit::dpi::Size> = match (width, height) {
+     (Some(w), Some(h)) => Some(LogicalSize::new(w, h).into()),
+     _ => None,
+   };
+   self.window.set_max_inner_size(size);
+ }

@Lawtro37

Copy link
Copy Markdown
Contributor Author

Merging won't cause conflicts, but you should be able to find two set_position functions with the same name along with other functions.

Fragment of cf8cc47:

+ // ── Position ────────────────────────────────────────────────────────────────
+ 
+ /// Returns the window's outer top-left position in physical pixels, or
+ /// `null` if the platform does not expose it.
+ #[napi]
+ pub fn get_position(&self) -> Option<Position> {
+   self.window.outer_position().ok().map(|p| Position { x: p.x, y: p.y })
+ }
+ 
+ /// Move the window so its outer top-left corner is at (`x`, `y`) in
+ /// physical pixels.
+ #[napi]
+ pub fn set_position(&self, x: i32, y: i32) {
+   self.window.set_outer_position(PhysicalPosition::new(x, y));
+ }
+ 
+ /// Center the window on its current monitor.  Does nothing if the current
+ /// monitor cannot be determined.
+ #[napi]
+ pub fn center(&self) {
+   if let Some(monitor) = self.window.current_monitor() {
+     let mpos = monitor.position();
+     let msize = monitor.size();
+     let wsize = self.window.outer_size();
+     let x = mpos.x + (msize.width as i32 - wsize.width as i32) / 2;
+     let y = mpos.y + (msize.height as i32 - wsize.height as i32) / 2;
+     self.window.set_outer_position(PhysicalPosition::new(x, y));
+   }
+ }
+ 
+ // ── Size queries & constraints ───────────────────────────────────────────────
+ 
+ /// Inner (content-area) size in physical pixels.
+ #[napi]
+ pub fn get_size(&self) -> Dimensions {
+   let s = self.window.inner_size();
+   Dimensions { width: s.width, height: s.height }
+ }
+ 
+ /// Outer (including decorations) size in physical pixels.
+ #[napi]
+ pub fn get_outer_size(&self) -> Dimensions {
+   let s = self.window.outer_size();
+   Dimensions { width: s.width, height: s.height }
+ }
+ 
+ /// Set minimum inner size.  Pass `null` / `undefined` for both to remove the
+ /// constraint.
+ #[napi]
+ pub fn set_min_size(&self, width: Option<f64>, height: Option<f64>) {
+   let size: Option<winit::dpi::Size> = match (width, height) {
+     (Some(w), Some(h)) => Some(LogicalSize::new(w, h).into()),
+     _ => None,
+   };
+   self.window.set_min_inner_size(size);
+ }
+ 
+ /// Set maximum inner size.  Pass `null` / `undefined` for both to remove the
+ /// constraint.
+ #[napi]
+ pub fn set_max_size(&self, width: Option<f64>, height: Option<f64>) {
+   let size: Option<winit::dpi::Size> = match (width, height) {
+     (Some(w), Some(h)) => Some(LogicalSize::new(w, h).into()),
+     _ => None,
+   };
+   self.window.set_max_inner_size(size);
+ }

Ah yes, I see now. it was not were I expected it to be.
Should be all good now. 👍

Comment thread Cargo.toml Outdated
@twlite twlite merged commit a15755f into webviewjs:main Jun 20, 2026
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

Successfully merging this pull request may close these issues.

3 participants