Implemented a way to choose logical or physical sizing/position#38
Conversation
This will open a file browser window that can be customised via the "FileDialogOptions" and "FileFilters".
…lter" to index.d.ts
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.
|
ignore the file dialoge stuff I removed that, its in another pull request |
|
@Lawtro37 could you fix the merge conflict? |
|
uh oh |
…droid when called
|
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.
|
Okay finally. |
|
wait hold on somehow I managed to remove the main thing of this PR. Let me fix that. |
|
holy merge conflict |
|
Merging won't cause conflicts, but you should be able to find two 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. |
Also added other functions such as, "getSize()", "setPosition()" and "getPosition()" all suporting both logical and physical sizing/positioning.