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

refactor!: migrate to dpi crate #174

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changes/dpi-crate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"muda": "minor"
---

Moved the following items into `dpi` module which is just an export of `dpi` crate:

- `Pixel`
- `validate_scale_factor`
- `LogicalPosition`
- `PhysicalPosition`
- `Position`
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ categories = [ "gui" ]
default = [ "libxdo" ]
libxdo = [ "dep:libxdo" ]
common-controls-v6 = [ ]
serde = [ "dep:serde" ]
serde = [ "dep:serde", "dpi/serde" ]

[dependencies]
crossbeam-channel = "0.5"
keyboard-types = "0.7"
once_cell = "1"
thiserror = "1"
serde = { version = "1", optional = true }
dpi = "0.1"

[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.52"
Expand Down
3 changes: 2 additions & 1 deletion examples/tao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#![allow(unused)]
use muda::{
accelerator::{Accelerator, Code, Modifiers},
dpi::{PhysicalPosition, Position},
AboutMetadata, CheckMenuItem, ContextMenu, IconMenuItem, Menu, MenuEvent, MenuItem,
PhysicalPosition, Position, PredefinedMenuItem, Submenu,
PredefinedMenuItem, Submenu,
};
#[cfg(target_os = "macos")]
use tao::platform::macos::WindowExtMacOS;
Expand Down
3 changes: 2 additions & 1 deletion examples/windows-common-controls-v6/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#![allow(unused)]
use muda::{
accelerator::{Accelerator, Code, Modifiers},
dpi::{PhysicalPosition, Position},
AboutMetadata, CheckMenuItem, ContextMenu, IconMenuItem, Menu, MenuEvent, MenuItem,
PhysicalPosition, Position, PredefinedMenuItem, Submenu,
PredefinedMenuItem, Submenu,
};
#[cfg(target_os = "macos")]
use tao::platform::macos::{EventLoopBuilderExtMacOS, WindowExtMacOS};
Expand Down
3 changes: 2 additions & 1 deletion examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#![allow(unused)]
use muda::{
accelerator::{Accelerator, Code, Modifiers},
dpi::{PhysicalPosition, Position},
AboutMetadata, CheckMenuItem, ContextMenu, IconMenuItem, Menu, MenuEvent, MenuItem,
PhysicalPosition, Position, PredefinedMenuItem, Submenu,
PredefinedMenuItem, Submenu,
};
#[cfg(target_os = "macos")]
use winit::platform::macos::{EventLoopBuilderExtMacOS, WindowExtMacOS};
Expand Down
9 changes: 3 additions & 6 deletions examples/wry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::rc::Rc;

use muda::{
accelerator::{Accelerator, Code, Modifiers},
dpi::Position,
AboutMetadata, CheckMenuItem, ContextMenu, IconMenuItem, Menu, MenuEvent, MenuItem,
PredefinedMenuItem, Submenu,
};
Expand Down Expand Up @@ -254,11 +255,7 @@ fn main() -> wry::Result<()> {
y += menu_bar.allocated_height();
}

show_context_menu(
&window,
&file_m_c,
Some(muda::Position::Logical((x, y).into())),
)
show_context_menu(&window, &file_m_c, Some(Position::Logical((x, y).into())))
}
}
};
Expand Down Expand Up @@ -306,7 +303,7 @@ fn main() -> wry::Result<()> {
})
}

fn show_context_menu(window: &Window, menu: &dyn ContextMenu, position: Option<muda::Position>) {
fn show_context_menu(window: &Window, menu: &dyn ContextMenu, position: Option<Position>) {
println!("Show context menu at position {position:?}");
#[cfg(target_os = "windows")]
menu.show_context_menu_for_hwnd(window.hwnd() as _, position);
Expand Down
237 changes: 0 additions & 237 deletions src/dpi.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/items/submenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use std::{cell::RefCell, mem, rc::Rc};

use crate::{
sealed::IsMenuItemBase, util::AddOp, ContextMenu, IsMenuItem, MenuId, MenuItemKind, Position,
dpi::Position, sealed::IsMenuItemBase, util::AddOp, ContextMenu, IsMenuItem, MenuId,
MenuItemKind,
};

/// A menu that can be added to a [`Menu`] or another [`Submenu`].
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
//! # #[cfg(target_os = "macos")]
//! # let nsview = 0 as *mut objc::runtime::Object;
//! // --snip--
//! let position = muda::PhysicalPosition { x: 100., y: 120. };
//! let position = muda::dpi::PhysicalPosition { x: 100., y: 120. };
//! #[cfg(target_os = "windows")]
//! menu.show_context_menu_for_hwnd(window_hwnd, Some(position.into()));
//! #[cfg(target_os = "linux")]
Expand Down Expand Up @@ -132,7 +132,6 @@ use once_cell::sync::{Lazy, OnceCell};
mod about_metadata;
pub mod accelerator;
mod builders;
mod dpi;
mod error;
mod icon;
mod items;
Expand All @@ -147,7 +146,7 @@ extern crate objc;

pub use about_metadata::AboutMetadata;
pub use builders::*;
pub use dpi::*;
pub use dpi;
pub use error::*;
pub use icon::{BadIcon, Icon, NativeIcon};
pub use items::*;
Expand Down Expand Up @@ -311,7 +310,7 @@ pub trait ContextMenu {
///
/// - `position` is relative to the window top-left corner, if `None`, the cursor position is used.
#[cfg(target_os = "windows")]
fn show_context_menu_for_hwnd(&self, hwnd: isize, position: Option<Position>);
fn show_context_menu_for_hwnd(&self, hwnd: isize, position: Option<dpi::Position>);

/// Attach the menu subclass handler to the given hwnd
/// so you can recieve events from that window using [MenuEvent::receiver]
Expand All @@ -328,7 +327,7 @@ pub trait ContextMenu {
///
/// - `position` is relative to the window top-left corner, if `None`, the cursor position is used.
#[cfg(target_os = "linux")]
fn show_context_menu_for_gtk_window(&self, w: &gtk::Window, position: Option<Position>);
fn show_context_menu_for_gtk_window(&self, w: &gtk::Window, position: Option<dpi::Position>);

/// Get the underlying gtk menu reserved for context menus.
#[cfg(target_os = "linux")]
Expand All @@ -338,7 +337,7 @@ pub trait ContextMenu {
///
/// - `position` is relative to the window top-left corner, if `None`, the cursor position is used.
#[cfg(target_os = "macos")]
fn show_context_menu_for_nsview(&self, view: cocoa::base::id, position: Option<Position>);
fn show_context_menu_for_nsview(&self, view: cocoa::base::id, position: Option<dpi::Position>);

/// Get the underlying NSMenu reserved for context menus.
#[cfg(target_os = "macos")]
Expand Down
Loading
Loading