Skip to content
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
2 changes: 1 addition & 1 deletion examples/cursors/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig::default());

Window::create(window_open_options, CursorsExample::new)?.run_until_closed()?;
Window::create(window_open_options, None, CursorsExample::new)?.run_until_closed()?;
Ok(())
}
3 changes: 2 additions & 1 deletion examples/external-wakeup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

let window = Window::create(window_open_options, |ctx| FemtovgExample::new(ctx, receiver))?;
let window =
Window::create(window_open_options, None, |ctx| FemtovgExample::new(ctx, receiver))?;
let waker = window.waker();
std::thread::spawn(|| run_thread(sender, waker));

Expand Down
4 changes: 2 additions & 2 deletions examples/open_parented/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ParentWindowHandler {
let window_open_options =
WindowSettings::new().with_size(size).with_parent(&window).with_title("baseview child");

let child_window = Window::create(window_open_options, ChildWindowHandler::new)?;
let child_window = Window::create(window_open_options, None, ChildWindowHandler::new)?;
child_window.show()?;

Ok(Self { surface: surface.into(), child_window })
Expand Down Expand Up @@ -116,7 +116,7 @@ fn main() -> Result<(), baseview::Error> {
unsafe { baseview::assume_standalone_in_process() };
let window_open_options = WindowSettings::new().with_size(LogicalSize::new(512.0, 512.0));

Window::create(window_open_options, ParentWindowHandler::new)?.run_until_closed()?;
Window::create(window_open_options, None, ParentWindowHandler::new)?.run_until_closed()?;

Ok(())
}
2 changes: 1 addition & 1 deletion examples/open_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn main() -> Result<(), baseview::Error> {

let (mut tx, rx) = RingBuffer::new(128);

let window = Window::create(window_open_options, |window| {
let window = Window::create(window_open_options, None, |window| {
let ctx = softbuffer::Context::new(window.clone())?;
let mut surface = softbuffer::Surface::new(&ctx, window.clone())?;
let size = window.size().physical;
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin_clack/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {
});
}

let window = Window::create_with_host(options, OpenWindowExample::new, host)?;
let window = Window::create(options, Some(host), OpenWindowExample::new)?;

self.gui.replace(Some(ExamplePluginGui { handle: window }));
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin_clack_femtovg/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {
});
}

let window = Window::create_with_host(options, FemtovgExample::new, host)?;
let window = Window::create(options, Some(host), FemtovgExample::new)?;

self.gui.replace(Some(ExamplePluginGui { handle: window }));
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/render_femtovg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

Window::create(window_open_options, FemtovgExample::new)?.run_until_closed()?;
Window::create(window_open_options, None, FemtovgExample::new)?.run_until_closed()?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion examples/render_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_max_size(LogicalSize::new(512, 512));

Window::create(window_open_options, |c| pollster::block_on(WgpuExample::new(c)))?
Window::create(window_open_options, None, |c| pollster::block_on(WgpuExample::new(c)))?
.run_until_closed()?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/test-frame-pacing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

Window::create(window_open_options, FramePacingTest::new)?.run_until_closed()?;
Window::create(window_open_options, None, FramePacingTest::new)?.run_until_closed()?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion examples/timers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

Window::create(window_open_options, FemtovgExample::new)?.run_until_closed()
Window::create(window_open_options, None, FemtovgExample::new)?.run_until_closed()
}

fn new_random_color() -> Color {
Expand Down
25 changes: 4 additions & 21 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,22 @@ pub struct Window {
}

impl Window {
/// Creates a new window, using the given [`WindowSettings`] and a builder closure to
/// create the associated [`WindowHandler`].
///
/// This function creates the window but does not open or show it.
/// You must use the [`show`](Self::show) method to actually open it
/// (unless you use [`run_until_closed`](Self::run_until_closed), which does it automatically).
#[inline]
pub fn create<H: WindowHandler>(
options: WindowSettings,
handler: impl FnOnce(WindowContext) -> Result<H, HandlerError> + Send + 'static,
) -> Result<Window, Error> {
Self::create_with_host(options, handler, None)
}

/// Creates a new window, using the given [`WindowSettings`] and a builder closure to
/// create the associated [`WindowHandler`], as well as an optional [`Host`] containing callbacks
/// to a potential system that is hosting the window (e.g. in a plug-in setting).
///
/// This function creates the window but does not open or show it.
/// You must use the [`show`](Self::show) method to actually open it
/// (unless you use [`run_until_closed`](Self::run_until_closed), which does it automatically).
///
/// Calling this function with [`None`] for the `host` value is equivalent to calling
/// [`create`](Self::create).
pub fn create_with_host<H: WindowHandler>(
settings: WindowSettings,
#[inline]
pub fn create<H: WindowHandler>(
settings: WindowSettings, host: Option<Host>,
handler: impl FnOnce(WindowContext) -> Result<H, HandlerError> + Send + 'static,
host: impl Into<Option<Host>>,
) -> Result<Window, Error> {
let initializer = WindowInitializer {
settings,
builder: WindowHandlerBuilder::new(handler),
host: host.into().unwrap_or_else(Host::default),
host: host.unwrap_or_default(),
};

Ok(Self {
Expand Down
2 changes: 1 addition & 1 deletion tests/partial-rendering/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

let window = Window::create(window_open_options, FemtovgExample::new)?;
let window = Window::create(window_open_options, None, FemtovgExample::new)?;

window.run_until_closed()?;
Ok(())
Expand Down
Loading