use std::cell::RefCell;
use std::rc::Rc;
use saudade::{Event, EventCtx, Painter, PopupRequest, Rect, Theme, Widget};
pub struct Shared<W>(pub Rc<RefCell<W>>);
impl<W> Shared<W> {
pub fn new(inner: Rc<RefCell<W>>) -> Self {
Self(inner)
}
pub fn handle(&self) -> Rc<RefCell<W>> {
self.0.clone()
}
}
impl<W: Widget> Widget for Shared<W> {
fn bounds(&self) -> Rect {
self.0.borrow().bounds()
}
fn paint(&mut self, painter: &mut Painter, theme: &Theme) {
self.0.borrow_mut().paint(painter, theme);
}
fn paint_overlay(&mut self, painter: &mut Painter, theme: &Theme) {
self.0.borrow_mut().paint_overlay(painter, theme);
}
fn event(&mut self, event: &Event, ctx: &mut EventCtx) {
self.0.borrow_mut().event(event, ctx);
}
fn captures_pointer(&self) -> bool {
self.0.borrow().captures_pointer()
}
fn focusable(&self) -> bool {
self.0.borrow().focusable()
}
fn set_focused(&mut self, focused: bool) {
self.0.borrow_mut().set_focused(focused);
}
fn accepts_accelerators(&self) -> bool {
self.0.borrow().accepts_accelerators()
}
fn layout(&mut self, bounds: Rect) {
self.0.borrow_mut().layout(bounds);
}
fn focus_first(&mut self) -> bool {
self.0.borrow_mut().focus_first()
}
fn popup_request(&self) -> Option<PopupRequest> {
self.0.borrow().popup_request()
}
fn wants_ticks(&self) -> bool {
self.0.borrow().wants_ticks()
}
}