Skip to content

Commit

Permalink
Extend Winit window configuration, change default rendering colour (#124
Browse files Browse the repository at this point in the history
)

* extend winit window creation, re-export winit, make wgpu render transparent

* format code

* fix transparency to 0.0
  • Loading branch information
panekj authored Nov 1, 2023
1 parent 920ca6b commit 40e1700
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use once_cell::sync::Lazy;
use parking_lot::Mutex;
use winit::{
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy},
monitor::MonitorHandle,
window::WindowId,
};

Expand Down Expand Up @@ -143,6 +144,14 @@ impl Application {
f(proxy);
}
}

pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
self.event_loop.available_monitors()
}

pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.event_loop.primary_monitor()
}
}

pub fn quit_app() {
Expand Down
12 changes: 12 additions & 0 deletions src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ impl ApplicationHandle {
window_builder = window_builder.with_decorations(false);
}
}
if let Some(transparent) = config.with_transparency {
window_builder = window_builder.with_transparent(transparent);
}
if let Some(fullscreen) = config.fullscreen {
window_builder = window_builder.with_fullscreen(Some(fullscreen));
}
if let Some(window_level) = config.window_level {
window_builder = window_builder.with_window_level(window_level);
}
if let Some(title) = config.title {
window_builder = window_builder.with_title(title);
}
}
let result = window_builder.build(event_loop);
let window = match result {
Expand Down
45 changes: 45 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use kurbo::{Point, Size};
pub use winit::window::Fullscreen;
pub use winit::window::ResizeDirection;
pub use winit::window::Theme;
pub use winit::window::WindowButtons;
pub use winit::window::WindowId;
pub use winit::window::WindowLevel;

use crate::{
app::{add_app_update_event, AppUpdateEvent},
Expand All @@ -13,6 +16,13 @@ pub struct WindowConfig {
pub(crate) size: Option<Size>,
pub(crate) position: Option<Point>,
pub(crate) show_titlebar: Option<bool>,
pub(crate) with_transparency: Option<bool>,
pub(crate) fullscreen: Option<Fullscreen>,
pub(crate) window_icon: Option<bool>,
pub(crate) title: Option<String>,
pub(crate) enabled_buttons: Option<WindowButtons>,
pub(crate) resizable: Option<bool>,
pub(crate) window_level: Option<WindowLevel>,
}

impl WindowConfig {
Expand All @@ -30,6 +40,41 @@ impl WindowConfig {
self.show_titlebar = Some(show_titlebar);
self
}

pub fn with_transparency(mut self, with_transparency: bool) -> Self {
self.with_transparency = Some(with_transparency);
self
}

pub fn fullscreen(mut self, fullscreen: Fullscreen) -> Self {
self.fullscreen = Some(fullscreen);
self
}

pub fn window_icon(mut self, window_icon: bool) -> Self {
self.window_icon = Some(window_icon);
self
}

pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}

pub fn enabled_buttons(mut self, enabled_buttons: WindowButtons) -> Self {
self.enabled_buttons = Some(enabled_buttons);
self
}

pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = Some(resizable);
self
}

pub fn window_level(mut self, window_level: WindowLevel) -> Self {
self.window_level = Some(window_level);
self
}
}

/// create a new window. You'll need to create Application first, otherwise it
Expand Down
7 changes: 6 additions & 1 deletion vger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,12 @@ impl Renderer for VgerRenderer {
view: &texture_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.0,
}),
store: StoreOp::Store,
},
})],
Expand Down

0 comments on commit 40e1700

Please sign in to comment.