engine/character_window/src/page_content.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

2024-08-25 12:30:03 +00:00
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!()
}
}
2024-08-27 12:06:06 +00:00
pub struct PageContent<A: Ability + 'static, T: Send + Sync> {
content: Content<A, T>,
2024-08-25 12:30:03 +00:00
tooltip: Arc<GuiSnippet>,
right_side: Box<dyn RightSide>,
}
2024-08-27 12:06:06 +00:00
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
2024-08-25 12:30:03 +00:00
where
R: RightSide + 'static,
{
Self {
content,
tooltip,
right_side: Box::new(right_side),
}
}
}
2024-08-27 12:06:06 +00:00
impl<A: Ability + 'static, T: Send + Sync> PageContentWrapper for PageContent<A, T>
2024-08-25 12:30:03 +00:00
where
2024-08-27 12:06:06 +00:00
Content<A, T>: ContentUpdate,
2024-08-25 12:30:03 +00:00
{
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
}
}