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

Extend Winit window configuration, change default rendering colour #124

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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 parking_lot::Mutex;
use winit::{
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy},
monitor::MonitorHandle,
window::WindowId,
};

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

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

Check warning on line 150 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L148-L150

Added lines #L148 - L150 were not covered by tests

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

Check warning on line 154 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L152-L154

Added lines #L152 - L154 were not covered by tests
}

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 @@
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);
}

Check warning on line 208 in src/app_handle.rs

View check run for this annotation

Codecov / codecov/patch

src/app_handle.rs#L197-L208

Added lines #L197 - L208 were not covered by tests
}
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(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 @@
self.show_titlebar = Some(show_titlebar);
self
}

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

Check warning on line 47 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L44-L47

Added lines #L44 - L47 were not covered by tests

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

Check warning on line 52 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L49-L52

Added lines #L49 - L52 were not covered by tests

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

Check warning on line 57 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L54-L57

Added lines #L54 - L57 were not covered by tests

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

Check warning on line 62 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L59-L62

Added lines #L59 - L62 were not covered by tests

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

Check warning on line 67 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L64-L67

Added lines #L64 - L67 were not covered by tests

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

Check warning on line 72 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L69-L72

Added lines #L69 - L72 were not covered by tests

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

Check warning on line 77 in src/window.rs

View check run for this annotation

Codecov / codecov/patch

src/window.rs#L74-L77

Added lines #L74 - L77 were not covered by tests
}

/// 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 @@
view: &texture_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
load: wgpu::LoadOp::Clear(wgpu::Color {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe only do this if the window is transparent? also why a is 0.5 instead of 0.0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there such configuration? The transparency setting is for winit to signal to OS that it might be transparent.

also why a is 0.5 instead of 0.0?

my own custom thing, will fix in a bit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I meant, when the WindowConfig has transparent setting in it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how I'm supposed to do that, winit doesn't even expose the transparency state in Window, only in WindowBuilder

r: 0.0,
g: 0.0,
b: 0.0,
a: 0.5,
}),

Check warning on line 450 in vger/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

vger/src/lib.rs#L445-L450

Added lines #L445 - L450 were not covered by tests
store: StoreOp::Store,
},
})],
Expand Down
Loading