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

Remove WindowBuilder in favour of WindowAttributes #3400

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion examples/custom_cursors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() -> Result<(), impl std::error::Error> {
let builder = WindowBuilder::new().with_title("A fantastic window!");
#[cfg(wasm_platform)]
let builder = {
use winit::platform::web::WindowBuilderExtWebSys;
use winit::platform::web::WindowAttributesExtWebSys;
builder.with_append(true)
};
let window = builder.build(&event_loop).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/startup_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod example {
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
use winit::event_loop::EventLoop;
use winit::platform::startup_notify::{
EventLoopExtStartupNotify, WindowBuilderExtStartupNotify, WindowExtStartupNotify,
EventLoopExtStartupNotify, WindowAttributesExtStartupNotify, WindowExtStartupNotify,
};
use winit::window::{Window, WindowBuilder, WindowId};

Expand Down
2 changes: 1 addition & 1 deletion examples/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn main() -> Result<(), impl std::error::Error> {
let builder = WindowBuilder::new().with_title("A fantastic window!");
#[cfg(wasm_platform)]
let builder = {
use winit::platform::web::WindowBuilderExtWebSys;
use winit::platform::web::WindowAttributesExtWebSys;
builder.with_append(true)
};
let window = builder.build(&event_loop).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/web_aspect_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod wasm {
dpi::PhysicalSize,
event::{Event, WindowEvent},
event_loop::EventLoop,
platform::web::WindowBuilderExtWebSys,
platform::web::WindowAttributesExtWebSys,
window::{Window, WindowBuilder},
};

Expand Down
2 changes: 1 addition & 1 deletion examples/window_tabbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use winit::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::EventLoop,
keyboard::{Key, NamedKey},
platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS},
platform::macos::{WindowAttributesExtMacOS, WindowExtMacOS},
window::{Window, WindowBuilder},
};

Expand Down
2 changes: 1 addition & 1 deletion examples/x11_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod imple {
use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
platform::x11::WindowBuilderExtX11,
platform::x11::WindowAttributesExtX11,
window::WindowBuilder,
};

Expand Down
7 changes: 1 addition & 6 deletions src/platform/android.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget},
window::{Window, WindowBuilder},
window::Window,
};

use android_activity::{AndroidApp, ConfigurationRef, Rect};
Expand Down Expand Up @@ -32,11 +32,6 @@ impl WindowExtAndroid for Window {

impl<T> EventLoopWindowTargetExtAndroid for EventLoopWindowTarget<T> {}

/// Additional methods on [`WindowBuilder`] that are specific to Android.
pub trait WindowBuilderExtAndroid {}

impl WindowBuilderExtAndroid for WindowBuilder {}

pub trait EventLoopBuilderExtAndroid {
/// Associates the `AndroidApp` that was passed to `android_main()` with the event loop
///
Expand Down
8 changes: 4 additions & 4 deletions src/platform/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use objc2::rc::Id;
use crate::{
event_loop::EventLoop,
monitor::{MonitorHandle, VideoModeHandle},
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};

/// Additional methods on [`EventLoop`] that are specific to iOS.
Expand Down Expand Up @@ -129,8 +129,8 @@ impl WindowExtIOS for Window {
}
}

/// Additional methods on [`WindowBuilder`] that are specific to iOS.
pub trait WindowBuilderExtIOS {
/// Additional methods on [`WindowAttributes`] that are specific to iOS.
pub trait WindowAttributesExtIOS {
/// Sets the [`contentScaleFactor`] of the underlying [`UIWindow`] to `scale_factor`.
///
/// The default value is device dependent, and it's recommended GLES or Metal applications set
Expand Down Expand Up @@ -184,7 +184,7 @@ pub trait WindowBuilderExtIOS {
fn with_preferred_status_bar_style(self, status_bar_style: StatusBarStyle) -> Self;
}

impl WindowBuilderExtIOS for WindowBuilder {
impl WindowAttributesExtIOS for WindowAttributes {
#[inline]
fn with_scale_factor(mut self, scale_factor: f64) -> Self {
self.platform_specific.scale_factor = Some(scale_factor);
Expand Down
11 changes: 6 additions & 5 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
monitor::MonitorHandle,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};

/// Additional methods on [`Window`] that are specific to MacOS.
Expand Down Expand Up @@ -176,15 +176,16 @@ pub enum ActivationPolicy {
Prohibited,
}

/// Additional methods on [`WindowBuilder`] that are specific to MacOS.
/// Additional methods on [`WindowAttributes`] that are specific to MacOS.
///
/// **Note:** Properties dealing with the titlebar will be overwritten by the [`WindowBuilder::with_decorations`] method:
/// **Note:** Properties dealing with the titlebar will be overwritten by the
/// [`WindowAttributes::with_decorations`] method:
/// - `with_titlebar_transparent`
/// - `with_title_hidden`
/// - `with_titlebar_hidden`
/// - `with_titlebar_buttons_hidden`
/// - `with_fullsize_content_view`
pub trait WindowBuilderExtMacOS {
pub trait WindowAttributesExtMacOS {
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> Self;
/// Makes the titlebar transparent and allows the content to appear behind it.
Expand All @@ -211,7 +212,7 @@ pub trait WindowBuilderExtMacOS {
fn with_option_as_alt(self, option_as_alt: OptionAsAlt) -> Self;
}

impl WindowBuilderExtMacOS for WindowBuilder {
impl WindowAttributesExtMacOS for WindowAttributes {
#[inline]
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> Self {
self.platform_specific.movable_by_window_background = movable_by_window_background;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/startup_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::env;

use crate::error::NotSupportedError;
use crate::event_loop::{AsyncRequestSerial, EventLoopWindowTarget};
use crate::window::{ActivationToken, Window, WindowBuilder};
use crate::window::{ActivationToken, Window, WindowAttributes};

/// The variable which is used mostly on X11.
const X11_VAR: &str = "DESKTOP_STARTUP_ID";
Expand All @@ -47,7 +47,7 @@ pub trait WindowExtStartupNotify {
fn request_activation_token(&self) -> Result<AsyncRequestSerial, NotSupportedError>;
}

pub trait WindowBuilderExtStartupNotify {
pub trait WindowAttributesExtStartupNotify {
/// Use this [`ActivationToken`] during window creation.
///
/// Not using such a token upon a window could make your window not gaining
Expand All @@ -74,7 +74,7 @@ impl WindowExtStartupNotify for Window {
}
}

impl WindowBuilderExtStartupNotify for WindowBuilder {
impl WindowAttributesExtStartupNotify for WindowAttributes {
fn with_activation_token(mut self, token: ActivationToken) -> Self {
self.platform_specific.activation_token = Some(token);
self
Expand Down
8 changes: 4 additions & 4 deletions src/platform/wayland.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
monitor::MonitorHandle,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};

use crate::platform_impl::{ApplicationName, Backend};
Expand Down Expand Up @@ -52,8 +52,8 @@ pub trait WindowExtWayland {}

impl WindowExtWayland for Window {}

/// Additional methods on [`WindowBuilder`] that are specific to Wayland.
pub trait WindowBuilderExtWayland {
/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
pub trait WindowAttributesExtWayland {
/// Build window with the given name.
///
/// The `general` name sets an application ID, which should match the `.desktop`
Expand All @@ -64,7 +64,7 @@ pub trait WindowBuilderExtWayland {
fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
}

impl WindowBuilderExtWayland for WindowBuilder {
impl WindowAttributesExtWayland for WindowAttributes {
#[inline]
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
self.platform_specific.name = Some(ApplicationName::new(general.into(), instance.into()));
Expand Down
6 changes: 3 additions & 3 deletions src/platform/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::event_loop::EventLoop;
use crate::event_loop::EventLoopWindowTarget;
use crate::platform_impl::PlatformCustomCursorBuilder;
use crate::window::CustomCursor;
use crate::window::{Window, WindowBuilder};
use crate::window::{Window, WindowAttributes};

use web_sys::HtmlCanvasElement;

Expand Down Expand Up @@ -73,7 +73,7 @@ impl WindowExtWebSys for Window {
}
}

pub trait WindowBuilderExtWebSys {
pub trait WindowAttributesExtWebSys {
/// Pass an [`HtmlCanvasElement`] to be used for this [`Window`]. If [`None`],
/// [`WindowBuilder::build()`] will create one.
///
Expand Down Expand Up @@ -102,7 +102,7 @@ pub trait WindowBuilderExtWebSys {
fn with_append(self, append: bool) -> Self;
}

impl WindowBuilderExtWebSys for WindowBuilder {
impl WindowAttributesExtWebSys for WindowAttributes {
fn with_canvas(mut self, canvas: Option<HtmlCanvasElement>) -> Self {
self.platform_specific.set_canvas(canvas);
self
Expand Down
8 changes: 4 additions & 4 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
monitor::MonitorHandle,
platform::modifier_supplement::KeyEventExtModifierSupplement,
platform_impl::WinIcon,
window::{BadIcon, Icon, Window, WindowBuilder},
window::{BadIcon, Icon, Window, WindowAttributes},
};

/// Window Handle type used by Win32 API
Expand Down Expand Up @@ -160,9 +160,9 @@ impl WindowExtWindows for Window {
}
}

/// Additional methods on `WindowBuilder` that are specific to Windows.
/// Additional methods on `WindowAttributes` that are specific to Windows.
#[allow(rustdoc::broken_intra_doc_links)]
pub trait WindowBuilderExtWindows {
pub trait WindowAttributesExtWindows {
/// Set an owner to the window to be created. Can be used to create a dialog box, for example.
/// This only works when [`WindowBuilder::with_parent_window`] isn't called or set to `None`.
/// Can be used in combination with [`WindowExtWindows::set_enable(false)`](WindowExtWindows::set_enable)
Expand Down Expand Up @@ -215,7 +215,7 @@ pub trait WindowBuilderExtWindows {
fn with_undecorated_shadow(self, shadow: bool) -> Self;
}

impl WindowBuilderExtWindows for WindowBuilder {
impl WindowAttributesExtWindows for WindowAttributes {
#[inline]
fn with_owner_window(mut self, parent: HWND) -> Self {
self.platform_specific.owner = Some(parent);
Expand Down
8 changes: 4 additions & 4 deletions src/platform/x11.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
monitor::MonitorHandle,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};

use crate::dpi::Size;
Expand Down Expand Up @@ -86,8 +86,8 @@ pub trait WindowExtX11 {}

impl WindowExtX11 for Window {}

/// Additional methods on [`WindowBuilder`] that are specific to X11.
pub trait WindowBuilderExtX11 {
/// Additional methods on [`WindowAttributes`] that are specific to X11.
pub trait WindowAttributesExtX11 {
/// Create this window with a specific X11 visual.
fn with_x11_visual(self, visual_id: XVisualID) -> Self;

Expand Down Expand Up @@ -140,7 +140,7 @@ pub trait WindowBuilderExtX11 {
fn with_embed_parent_window(self, parent_window_id: XWindow) -> Self;
}

impl WindowBuilderExtX11 for WindowBuilder {
impl WindowAttributesExtX11 for WindowAttributes {
#[inline]
fn with_x11_visual(mut self, visual_id: XVisualID) -> Self {
self.platform_specific.x11.visual_id = Some(visual_id);
Expand Down
1 change: 0 additions & 1 deletion src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ impl Window {
pub(crate) fn new<T: 'static>(
el: &EventLoopWindowTarget<T>,
_window_attrs: window::WindowAttributes,
_: PlatformSpecificWindowBuilderAttributes,
) -> Result<Self, error::OsError> {
// FIXME this ignores requested window attributes

Expand Down
35 changes: 23 additions & 12 deletions src/platform_impl/ios/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
platform::ios::ValidOrientations,
platform_impl::platform::{
ffi::{UIRectEdge, UIUserInterfaceIdiom},
window::PlatformSpecificWindowBuilderAttributes,
DeviceId, Fullscreen,
},
window::{WindowAttributes, WindowId as RootWindowId},
Expand Down Expand Up @@ -182,15 +181,14 @@ extern_methods!(
impl WinitView {
pub(crate) fn new(
_mtm: MainThreadMarker,
_window_attributes: &WindowAttributes,
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
window_attributes: &WindowAttributes,
frame: CGRect,
) -> Id<Self> {
let this: Id<Self> = unsafe { msg_send_id![Self::alloc(), initWithFrame: frame] };

this.setMultipleTouchEnabled(true);

if let Some(scale_factor) = platform_attributes.scale_factor {
if let Some(scale_factor) = window_attributes.platform_specific.scale_factor {
this.setContentScaleFactor(scale_factor as _);
}

Expand Down Expand Up @@ -385,8 +383,7 @@ impl WinitViewController {

pub(crate) fn new(
mtm: MainThreadMarker,
_window_attributes: &WindowAttributes,
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
window_attributes: &WindowAttributes,
view: &UIView,
) -> Id<Self> {
// These are set properly below, we just to set them to something in the meantime.
Expand All @@ -399,18 +396,33 @@ impl WinitViewController {
});
let this: Id<Self> = unsafe { msg_send_id![super(this), init] };

this.set_prefers_status_bar_hidden(platform_attributes.prefers_status_bar_hidden);
this.set_prefers_status_bar_hidden(
window_attributes
.platform_specific
.prefers_status_bar_hidden,
);

this.set_preferred_status_bar_style(platform_attributes.preferred_status_bar_style.into());
this.set_preferred_status_bar_style(
window_attributes
.platform_specific
.preferred_status_bar_style
.into(),
);

this.set_supported_interface_orientations(mtm, platform_attributes.valid_orientations);
this.set_supported_interface_orientations(
mtm,
window_attributes.platform_specific.valid_orientations,
);

this.set_prefers_home_indicator_auto_hidden(
platform_attributes.prefers_home_indicator_hidden,
window_attributes
.platform_specific
.prefers_home_indicator_hidden,
);

this.set_preferred_screen_edges_deferring_system_gestures(
platform_attributes
window_attributes
.platform_specific
.preferred_screen_edges_deferring_system_gestures
.into(),
);
Expand Down Expand Up @@ -467,7 +479,6 @@ impl WinitUIWindow {
pub(crate) fn new(
mtm: MainThreadMarker,
window_attributes: &WindowAttributes,
_platform_attributes: &PlatformSpecificWindowBuilderAttributes,
frame: CGRect,
view_controller: &UIViewController,
) -> Id<Self> {
Expand Down
Loading