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
20 changes: 5 additions & 15 deletions examples/open_parented/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use baseview::{
Event, EventStatus, PhySize, Window, WindowEvent, WindowHandle, WindowHandler,
WindowScalePolicy,
WindowOpenOptions,
};
use std::num::NonZeroU32;

Expand All @@ -19,12 +19,9 @@ impl ParentWindowHandler {
let mut surface = unsafe { softbuffer::Surface::new(&ctx, window) }.unwrap();
surface.resize(NonZeroU32::new(512).unwrap(), NonZeroU32::new(512).unwrap()).unwrap();

let window_open_options = baseview::WindowOpenOptions {
title: "baseview child".into(),
size: baseview::Size::new(256.0, 256.0),
scale: WindowScalePolicy::SystemScaleFactor,
gl_config: None,
};
let window_open_options =
WindowOpenOptions::new().with_size(256.0, 256.0).with_title("baseview child");

let child_window =
Window::open_parented(window, window_open_options, ChildWindowHandler::new);

Expand Down Expand Up @@ -124,14 +121,7 @@ impl WindowHandler for ChildWindowHandler {
}

fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview".into(),
size: baseview::Size::new(512.0, 512.0),
scale: WindowScalePolicy::SystemScaleFactor,

// TODO: Add an example that uses the OpenGL context
gl_config: None,
};
let window_open_options = WindowOpenOptions::new().with_size(512.0, 512.0);

Window::open_blocking(window_open_options, ParentWindowHandler::new);
}
9 changes: 2 additions & 7 deletions examples/open_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rtrb::{Consumer, RingBuffer};
#[cfg(target_os = "macos")]
use baseview::{copy_to_clipboard, MouseEvent};
use baseview::{
Event, EventStatus, PhySize, Window, WindowEvent, WindowHandler, WindowScalePolicy,
Event, EventStatus, PhySize, Window, WindowEvent, WindowHandler, WindowOpenOptions,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -63,12 +63,7 @@ impl WindowHandler for OpenWindowExample {
}

fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview".into(),
size: baseview::Size::new(512.0, 512.0),
scale: WindowScalePolicy::SystemScaleFactor,
gl_config: None,
};
let window_open_options = WindowOpenOptions::new().with_size(512.0, 512.0);

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

Expand Down
13 changes: 5 additions & 8 deletions examples/render_femtovg/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use baseview::gl::GlConfig;
use baseview::{
Event, EventStatus, MouseEvent, PhyPoint, Size, Window, WindowEvent, WindowHandler, WindowInfo,
WindowOpenOptions, WindowScalePolicy,
WindowOpenOptions,
};
use femtovg::renderer::OpenGl;
use femtovg::{Canvas, Color};
Expand Down Expand Up @@ -95,13 +95,10 @@ impl WindowHandler for FemtovgExample {
}

fn main() {
let window_open_options = WindowOpenOptions {
title: "Femtovg on Baseview".into(),
size: Size::new(512.0, 512.0),
scale: WindowScalePolicy::SystemScaleFactor,

gl_config: Some(GlConfig { alpha_bits: 8, ..GlConfig::default() }),
};
let window_open_options = WindowOpenOptions::new()
.with_title("Femtovg on Baseview")
.with_size(512.0, 512.0)
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

Window::open_blocking(window_open_options, FemtovgExample::new);
}
Expand Down
34 changes: 33 additions & 1 deletion src/window_open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,43 @@ pub struct WindowOpenOptions {
/// If provided, then an OpenGL context will be created for this window. You'll be able to
/// access this context through [crate::Window::gl_context].
///
/// By default this is set to `None`.
/// By default, this is set to `None`.
#[cfg(feature = "opengl")]
pub gl_config: Option<GlConfig>,
}

impl WindowOpenOptions {
#[inline]
pub fn new() -> Self {
Self::default()
}

#[inline]
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = title.into();
self
}

#[inline]
pub fn with_size(mut self, width: f64, height: f64) -> Self {
self.size = Size::new(width, height);
self
}

#[inline]
pub fn with_scale_policy(mut self, scale: WindowScalePolicy) -> Self {
self.scale = scale;
self
}

#[cfg(feature = "opengl")]
#[inline]
pub fn with_gl_config(mut self, gl_config: impl Into<Option<GlConfig>>) -> Self {
self.gl_config = gl_config.into();
self
}
}

impl Default for WindowOpenOptions {
fn default() -> Self {
Self {
Expand Down
Loading