Skip to main content

perspective_viewer/ui/
modal.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use std::cell::Cell;
14use std::rc::Rc;
15
16use yew::html::ImplicitClone;
17use yew::prelude::*;
18
19use crate::utils::WeakScope;
20
21/// Whether a modal has been flipped to open upward from its anchor, provided
22/// as a Yew context by `PortalModal`.
23#[derive(Clone, Default, Eq, PartialEq)]
24pub struct ModalOrientation(Rc<Cell<bool>>);
25
26impl ImplicitClone for ModalOrientation {}
27
28impl ModalOrientation {
29    pub fn set(&self, value: bool) {
30        self.0.set(value);
31    }
32}
33
34impl From<ModalOrientation> for bool {
35    fn from(x: ModalOrientation) -> Self {
36        x.0.get()
37    }
38}
39
40/// Props that expose a weak link to their component, so an owner can send it
41/// messages after the fact (the column-style editors hosted in a modal).
42pub trait ModalLink<T>
43where
44    T: Component,
45{
46    fn weak_link(&self) -> &'_ WeakScope<T>;
47}
48
49pub trait SetModalLink {
50    fn set_modal_link(&self);
51}
52
53impl<T> SetModalLink for &Context<T>
54where
55    T: Component,
56    T::Properties: ModalLink<T>,
57{
58    fn set_modal_link(&self) {
59        *self.props().weak_link().borrow_mut() = Some(self.link().clone());
60    }
61}