engine/character_window/src/page_content.rs

63 lines
1.3 KiB
Rust

use crate::*;
use std::sync::Arc;
use crate::content::{Content, ContentUpdate, ContentWrapper};
use super::traits::*;
pub struct EmptyRightSide;
impl RightSide for EmptyRightSide {
fn refresh(&mut self, _engine: &Engine, _hero: Entity) -> Result<()> {
unreachable!()
}
fn base(&self) -> &Arc<GuiSnippet> {
unreachable!()
}
}
pub struct PageContent<T: Send + Sync> {
content: Content<T>,
tooltip: Arc<GuiSnippet>,
right_side: Box<dyn RightSide>,
}
impl<T: Send + Sync> PageContent<T> {
pub fn new<R>(content: Content<T>, tooltip: Arc<GuiSnippet>, right_side: R) -> Self
where
R: RightSide + 'static,
{
Self {
content,
tooltip,
right_side: Box::new(right_side),
}
}
}
impl<T: Send + Sync> PageContentWrapper for PageContent<T>
where
Content<T>: ContentUpdate,
{
fn content(&self) -> &dyn ContentWrapper {
&self.content
}
fn content_mut(&mut self) -> &mut dyn ContentWrapper {
&mut self.content
}
fn tooltip(&self) -> &Arc<GuiSnippet> {
&self.tooltip
}
fn right_side(&self) -> &dyn RightSide {
&*self.right_side
}
fn right_side_mut(&mut self) -> &mut dyn RightSide {
&mut *self.right_side
}
}