finestra/window/mod.rs
1// Copyright (C) 2024 Tristan Gerritsen <tristan@thewoosh.org>
2// All Rights Reserved.
3
4mod config;
5mod dialog;
6
7use std::borrow::Cow;
8use std::sync::Arc;
9
10pub use self::config::*;
11pub use self::dialog::*;
12
13// Internal: this is a wrapper for invoking methods or making changes to the
14// window by user code.
15/// A reference to a Window. Use this to perform certain actions at runtime.
16/// If you want to modify the look and feel, use]
17/// [WindowConfiguration](super::WindowConfiguration).
18#[derive(Clone)]
19pub struct Window {
20 delegator: Arc<dyn WindowDelegator>,
21}
22
23impl Window {
24 pub(crate) fn new(delegator: Arc<dyn WindowDelegator>) -> Self {
25 Self {
26 delegator,
27 }
28 }
29
30 /// Creates a new dialog. Use the [`DialogBuilder`] to set additional
31 /// properties, before calling [`DialogBuilder::show()`].
32 ///
33 /// ## Example
34 /// ```rust,no_run,ignore
35 /// # use finestra::Window;
36 /// let window: Window;
37 ///
38 /// window.create_dialog("My important message")
39 /// .title("Important App")
40 /// .show();
41 /// ```
42 #[inline]
43 pub fn create_dialog(&self, text: impl Into<Cow<'static, str>>) -> DialogBuilder {
44 self.delegator.create_dialog(text.into())
45 }
46}
47
48pub(crate) trait WindowDelegator {
49 fn create_dialog(&self, text: Cow<'static, str>) -> DialogBuilder;
50}
51
52unsafe impl Send for Window {}
53unsafe impl Sync for Window {}