Skip to content

Commit 40e1700

Browse files
authored
Extend Winit window configuration, change default rendering colour (lapce#124)
* extend winit window creation, re-export winit, make wgpu render transparent * format code * fix transparency to 0.0
1 parent 920ca6b commit 40e1700

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

src/app.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use once_cell::sync::Lazy;
44
use parking_lot::Mutex;
55
use winit::{
66
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy},
7+
monitor::MonitorHandle,
78
window::WindowId,
89
};
910

@@ -143,6 +144,14 @@ impl Application {
143144
f(proxy);
144145
}
145146
}
147+
148+
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
149+
self.event_loop.available_monitors()
150+
}
151+
152+
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
153+
self.event_loop.primary_monitor()
154+
}
146155
}
147156

148157
pub fn quit_app() {

src/app_handle.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ impl ApplicationHandle {
194194
window_builder = window_builder.with_decorations(false);
195195
}
196196
}
197+
if let Some(transparent) = config.with_transparency {
198+
window_builder = window_builder.with_transparent(transparent);
199+
}
200+
if let Some(fullscreen) = config.fullscreen {
201+
window_builder = window_builder.with_fullscreen(Some(fullscreen));
202+
}
203+
if let Some(window_level) = config.window_level {
204+
window_builder = window_builder.with_window_level(window_level);
205+
}
206+
if let Some(title) = config.title {
207+
window_builder = window_builder.with_title(title);
208+
}
197209
}
198210
let result = window_builder.build(event_loop);
199211
let window = match result {

src/window.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use kurbo::{Point, Size};
2+
pub use winit::window::Fullscreen;
23
pub use winit::window::ResizeDirection;
34
pub use winit::window::Theme;
5+
pub use winit::window::WindowButtons;
46
pub use winit::window::WindowId;
7+
pub use winit::window::WindowLevel;
58

69
use crate::{
710
app::{add_app_update_event, AppUpdateEvent},
@@ -13,6 +16,13 @@ pub struct WindowConfig {
1316
pub(crate) size: Option<Size>,
1417
pub(crate) position: Option<Point>,
1518
pub(crate) show_titlebar: Option<bool>,
19+
pub(crate) with_transparency: Option<bool>,
20+
pub(crate) fullscreen: Option<Fullscreen>,
21+
pub(crate) window_icon: Option<bool>,
22+
pub(crate) title: Option<String>,
23+
pub(crate) enabled_buttons: Option<WindowButtons>,
24+
pub(crate) resizable: Option<bool>,
25+
pub(crate) window_level: Option<WindowLevel>,
1626
}
1727

1828
impl WindowConfig {
@@ -30,6 +40,41 @@ impl WindowConfig {
3040
self.show_titlebar = Some(show_titlebar);
3141
self
3242
}
43+
44+
pub fn with_transparency(mut self, with_transparency: bool) -> Self {
45+
self.with_transparency = Some(with_transparency);
46+
self
47+
}
48+
49+
pub fn fullscreen(mut self, fullscreen: Fullscreen) -> Self {
50+
self.fullscreen = Some(fullscreen);
51+
self
52+
}
53+
54+
pub fn window_icon(mut self, window_icon: bool) -> Self {
55+
self.window_icon = Some(window_icon);
56+
self
57+
}
58+
59+
pub fn title(mut self, title: impl Into<String>) -> Self {
60+
self.title = Some(title.into());
61+
self
62+
}
63+
64+
pub fn enabled_buttons(mut self, enabled_buttons: WindowButtons) -> Self {
65+
self.enabled_buttons = Some(enabled_buttons);
66+
self
67+
}
68+
69+
pub fn resizable(mut self, resizable: bool) -> Self {
70+
self.resizable = Some(resizable);
71+
self
72+
}
73+
74+
pub fn window_level(mut self, window_level: WindowLevel) -> Self {
75+
self.window_level = Some(window_level);
76+
self
77+
}
3378
}
3479

3580
/// create a new window. You'll need to create Application first, otherwise it

vger/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,12 @@ impl Renderer for VgerRenderer {
442442
view: &texture_view,
443443
resolve_target: None,
444444
ops: wgpu::Operations {
445-
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
445+
load: wgpu::LoadOp::Clear(wgpu::Color {
446+
r: 0.0,
447+
g: 0.0,
448+
b: 0.0,
449+
a: 0.0,
450+
}),
446451
store: StoreOp::Store,
447452
},
448453
})],

0 commit comments

Comments
 (0)