Skip to content

Commit

Permalink
Merge pull request #71 from ModProg/transparent-windows
Browse files Browse the repository at this point in the history
Support transparent windows
  • Loading branch information
ecton authored Nov 10, 2023
2 parents 60e85c7 + 244be0c commit 12b0d80
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 28 additions & 5 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use kludgine::app::WindowBehavior as _;
use kludgine::figures::units::{Px, UPx};
use kludgine::figures::{IntoSigned, IntoUnsigned, Point, Rect, ScreenScale, Size};
use kludgine::render::Drawing;
use kludgine::wgpu::CompositeAlphaMode;
use kludgine::Kludgine;
use tracing::Level;

Expand Down Expand Up @@ -201,6 +202,7 @@ where
GooeyWindow::<Behavior>::run_with(AssertUnwindSafe(sealed::Context {
user: self.context,
settings: RefCell::new(sealed::WindowSettings {
transparent: self.attributes.transparent,
attributes: Some(self.attributes),
occluded: self.occluded,
focused: self.focused,
Expand Down Expand Up @@ -258,6 +260,7 @@ struct GooeyWindow<T> {
max_inner_size: Option<Size<UPx>>,
theme: Option<DynamicReader<ThemePair>>,
current_theme: ThemePair,
transparent: bool,
}

impl<T> GooeyWindow<T>
Expand Down Expand Up @@ -405,6 +408,7 @@ where
.theme
.take()
.expect("theme always present");
let transparent = context.settings.borrow().transparent;
let mut behavior = T::initialize(
&mut RunningWindow::new(window, &focused, &occluded),
context.user,
Expand Down Expand Up @@ -435,6 +439,7 @@ where
max_inner_size: None,
current_theme,
theme,
transparent,
}
}

Expand Down Expand Up @@ -473,8 +478,11 @@ where
let mut layout_context = LayoutContext::new(&mut context);
let window_size = layout_context.gfx.size();

let background_color = layout_context.theme().surface.color;
layout_context.graphics.gfx.fill(background_color);
if !self.transparent {
let background_color = layout_context.theme().surface.color;
layout_context.graphics.gfx.fill(background_color);
}

let actual_size = layout_context.layout(if is_expanded {
Size::new(
ConstraintLimit::Known(window_size.width),
Expand Down Expand Up @@ -577,9 +585,23 @@ where
// wgpu::Limits::downlevel_webgl2_defaults().using_resolution(adapter_limits)
// }

// fn clear_color() -> Option<kludgine::Color> {
// Some(kludgine::Color::BLACK)
// }
fn clear_color(&self) -> Option<kludgine::Color> {
Some(if self.transparent {
kludgine::Color::CLEAR_BLACK
} else {
kludgine::Color::BLACK
})
}

fn composite_alpha_mode(&self, supported_modes: &[CompositeAlphaMode]) -> CompositeAlphaMode {
if dbg!(self.transparent)
&& dbg!(supported_modes).contains(&CompositeAlphaMode::PreMultiplied)
{
CompositeAlphaMode::PreMultiplied
} else {
CompositeAlphaMode::Auto
}
}

// fn focus_changed(&mut self, window: kludgine::app::Window<'_, ()>) {}

Expand Down Expand Up @@ -967,6 +989,7 @@ pub(crate) mod sealed {
pub occluded: Option<Dynamic<bool>>,
pub focused: Option<Dynamic<bool>>,
pub theme: Option<Value<ThemePair>>,
pub transparent: bool,
}

pub enum WindowCommand {
Expand Down

0 comments on commit 12b0d80

Please sign in to comment.