mirror of
https://github.com/danbulant/cushy
synced 2026-07-09 13:10:57 +00:00
parent
492da3b6ed
commit
884febecfa
4 changed files with 41 additions and 9 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -1178,7 +1178,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kludgine"
|
name = "kludgine"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
source = "git+https://github.com/khonsulabs/kludgine#4da9c9aef372ea6ae22fc18095a098d7189984c2"
|
source = "git+https://github.com/khonsulabs/kludgine#daf7a2df751c2e77ac226d3ddf5a408b85172cc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"alot",
|
"alot",
|
||||||
|
|
@ -3232,9 +3232,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.5.30"
|
version = "0.5.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5"
|
checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use kludgine::app::{AppEvent, AsApplication};
|
||||||
|
|
||||||
use crate::utils::IgnorePoison;
|
use crate::utils::IgnorePoison;
|
||||||
use crate::window::sealed::WindowCommand;
|
use crate::window::sealed::WindowCommand;
|
||||||
|
use crate::window::WindowHandle;
|
||||||
|
|
||||||
/// A Gooey application that has not started running yet.
|
/// A Gooey application that has not started running yet.
|
||||||
pub struct PendingApp {
|
pub struct PendingApp {
|
||||||
|
|
@ -116,7 +117,7 @@ pub trait Run: Sized {
|
||||||
/// A type that can be opened as a window in an application.
|
/// A type that can be opened as a window in an application.
|
||||||
pub trait Open: Sized {
|
pub trait Open: Sized {
|
||||||
/// Opens the provided type as a window inside of `app`.
|
/// Opens the provided type as a window inside of `app`.
|
||||||
fn open<App>(self, app: &App) -> crate::Result
|
fn open<App>(self, app: &App) -> crate::Result<Option<WindowHandle>>
|
||||||
where
|
where
|
||||||
App: Application;
|
App: Application;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -467,7 +467,7 @@ impl<T> Open for T
|
||||||
where
|
where
|
||||||
T: MakeWidget,
|
T: MakeWidget,
|
||||||
{
|
{
|
||||||
fn open<App>(self, app: &App) -> crate::Result
|
fn open<App>(self, app: &App) -> crate::Result<Option<crate::window::WindowHandle>>
|
||||||
where
|
where
|
||||||
App: Application,
|
App: Application,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -327,12 +327,12 @@ impl<Behavior> Open for Window<Behavior>
|
||||||
where
|
where
|
||||||
Behavior: WindowBehavior,
|
Behavior: WindowBehavior,
|
||||||
{
|
{
|
||||||
fn open<App>(self, app: &App) -> crate::Result
|
fn open<App>(self, app: &App) -> crate::Result<Option<WindowHandle>>
|
||||||
where
|
where
|
||||||
App: Application,
|
App: Application,
|
||||||
{
|
{
|
||||||
let gooey = app.gooey().clone();
|
let gooey = app.gooey().clone();
|
||||||
let _handle = GooeyWindow::<Behavior>::open_with(
|
let handle = GooeyWindow::<Behavior>::open_with(
|
||||||
app,
|
app,
|
||||||
sealed::Context {
|
sealed::Context {
|
||||||
user: self.context,
|
user: self.context,
|
||||||
|
|
@ -356,7 +356,7 @@ where
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(handle.map(WindowHandle::from))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_in(self, app: PendingApp) -> crate::Result {
|
fn run_in(self, app: PendingApp) -> crate::Result {
|
||||||
|
|
@ -1318,6 +1318,18 @@ where
|
||||||
WindowCommand::Redraw => {
|
WindowCommand::Redraw => {
|
||||||
window.set_needs_redraw();
|
window.set_needs_redraw();
|
||||||
}
|
}
|
||||||
|
WindowCommand::RequestClose => {
|
||||||
|
let mut window = RunningWindow::new(
|
||||||
|
window,
|
||||||
|
&self.gooey,
|
||||||
|
&self.focused,
|
||||||
|
&self.occluded,
|
||||||
|
&self.inner_size,
|
||||||
|
);
|
||||||
|
if self.behavior.close_requested(&mut window) {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1386,7 +1398,7 @@ pub(crate) mod sealed {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum WindowCommand {
|
pub enum WindowCommand {
|
||||||
Redraw,
|
Redraw,
|
||||||
// RequestClose,
|
RequestClose,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1487,3 +1499,22 @@ fn default_family(query: Family<'_>) -> Option<FamilyOwned> {
|
||||||
.and_then(|output| String::from_utf8(output.stdout).ok())
|
.and_then(|output| String::from_utf8(output.stdout).ok())
|
||||||
.map(FamilyOwned::Name)
|
.map(FamilyOwned::Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A handle to an open Gooey window.
|
||||||
|
pub struct WindowHandle(kludgine::app::WindowHandle<sealed::WindowCommand>);
|
||||||
|
|
||||||
|
impl WindowHandle {
|
||||||
|
/// Request that the window closes.
|
||||||
|
///
|
||||||
|
/// A window may disallow itself from being closed by customizing
|
||||||
|
/// [`WindowBehavior::close_requested`].
|
||||||
|
pub fn request_close(&self) {
|
||||||
|
let _result = self.0.send(sealed::WindowCommand::RequestClose);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<kludgine::app::WindowHandle<sealed::WindowCommand>> for WindowHandle {
|
||||||
|
fn from(handle: kludgine::app::WindowHandle<sealed::WindowCommand>) -> Self {
|
||||||
|
WindowHandle(handle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue