engine/character_window/src/page_content.rs
2024-08-27 14:06:06 +02:00

63 lines
1.4 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<A: Ability + 'static, T: Send + Sync> {
content: Content<A, T>,
tooltip: Arc<GuiSnippet>,
right_side: Box<dyn RightSide>,
}
impl<A: Ability + 'static, T: Send + Sync> PageContent<A, T> {
pub fn new<R>(content: Content<A, T>, tooltip: Arc<GuiSnippet>, right_side: R) -> Self
where
R: RightSide + 'static,
{
Self {
content,
tooltip,
right_side: Box::new(right_side),
}
}
}
impl<A: Ability + 'static, T: Send + Sync> PageContentWrapper for PageContent<A, T>
where
Content<A, 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
}
}