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

chore(examples): showcase usage of softbuffer in transparent example #863

Merged
merged 2 commits into from
Jan 18, 2024
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ url = "2"
image = "0.24"
env_logger = "0.10"

[target."cfg(target_os = \"windows\")".dev-dependencies]
softbuffer = "0.4.1"

[target."cfg(any(target_os = \"android\", target_os = \"windows\"))".dependencies]
once_cell = "1"

Expand Down
29 changes: 29 additions & 0 deletions examples/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright 2021-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0

use std::{num::NonZeroU32, rc::Rc};

use tao::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
Expand All @@ -19,6 +21,14 @@ fn main() {
.build(&event_loop)
.unwrap();

#[cfg(windows)]
let (window, _context, mut surface) = {
let window = Rc::new(window);
let context = softbuffer::Context::new(window.clone()).unwrap();
let surface = softbuffer::Surface::new(&context, window.clone()).unwrap();
(window, context, surface)
};

window.set_title("A fantastic window!");

event_loop.run(move |event, _, control_flow| {
Expand All @@ -30,6 +40,25 @@ fn main() {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,

#[cfg(windows)]
Event::RedrawRequested(_) => {
let (width, height) = {
let size = window.inner_size();
(size.width, size.height)
};
surface
.resize(
NonZeroU32::new(width).unwrap(),
NonZeroU32::new(height).unwrap(),
)
.unwrap();

let mut buffer = surface.buffer_mut().unwrap();
buffer.fill(0);
buffer.present().unwrap();
}

_ => (),
}
});
Expand Down
Loading