widgetry/widgets/
stash.rs1use std::cell::RefCell;
2use std::rc::Rc;
3
4use crate::{EventCtx, GfxCtx, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput};
5
6pub struct Stash<T> {
9 value: Rc<RefCell<T>>,
10}
11
12impl<T: 'static> Stash<T> {
13 pub fn new_widget(name: &str, value: T) -> Widget {
14 Widget::new(Box::new(Stash {
15 value: Rc::new(RefCell::new(value)),
16 }))
17 .named(name)
18 }
19
20 pub(crate) fn get_value(&self) -> Rc<RefCell<T>> {
21 self.value.clone()
22 }
23}
24
25impl<T: 'static> WidgetImpl for Stash<T> {
26 fn get_dims(&self) -> ScreenDims {
27 ScreenDims::square(0.0)
28 }
29
30 fn set_pos(&mut self, _: ScreenPt) {}
31
32 fn event(&mut self, _: &mut EventCtx, _: &mut WidgetOutput) {}
33 fn draw(&self, _: &mut GfxCtx) {}
34}