mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
use crate::*;
|
|
use super::*;
|
|
|
|
impl<E: Engine> LayoutDebug<E> for E {}
|
|
|
|
impl<E: Engine> Clone for Measure<E> {
|
|
fn clone (&self) -> Self {
|
|
Self {
|
|
_engine: Default::default(),
|
|
x: self.x.clone(),
|
|
y: self.y.clone(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<E: Engine> std::fmt::Debug for Measure<E> {
|
|
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
|
f.debug_struct("Measure")
|
|
.field("width", &self.x)
|
|
.field("height", &self.y)
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
impl<E: Engine> Measure<E> {
|
|
pub fn w (&self) -> usize { self.x.load(Relaxed) }
|
|
pub fn h (&self) -> usize { self.y.load(Relaxed) }
|
|
pub fn wh (&self) -> [usize;2] { [self.w(), self.h()] }
|
|
pub fn set_w (&self, w: impl Into<usize>) { self.x.store(w.into(), Relaxed) }
|
|
pub fn set_h (&self, h: impl Into<usize>) { self.y.store(h.into(), Relaxed) }
|
|
pub fn set_wh (&self, w: impl Into<usize>, h: impl Into<usize>) { self.set_w(w); self.set_h(h); }
|
|
pub fn format (&self) -> String { format!("{}x{}", self.w(), self.h()) }
|
|
pub fn new () -> Self {
|
|
Self {
|
|
_engine: PhantomData::default(),
|
|
x: Arc::new(0.into()),
|
|
y: Arc::new(0.into()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Render<Tui> for Measure<Tui> {
|
|
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
|
Ok(Some([0u16.into(), 0u16.into()].into()))
|
|
}
|
|
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
|
self.set_w(to.area().w());
|
|
self.set_h(to.area().h());
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl Measure<Tui> {
|
|
pub fn debug (&self) -> ShowMeasure {
|
|
ShowMeasure(&self)
|
|
}
|
|
}
|
|
|
|
render!(<Tui>|self: ShowMeasure<'a>|render(|to: &mut TuiOutput|Ok({
|
|
let w = self.0.w();
|
|
let h = self.0.h();
|
|
to.blit(&format!(" {w} x {h} "), to.area.x(), to.area.y(), Some(
|
|
Style::default().bold().italic().bg(Color::Rgb(255, 0, 255)).fg(Color::Rgb(0,0,0))
|
|
))
|
|
})));
|