more built-in centering

This commit is contained in:
🪞👃🪞 2025-01-01 17:43:48 +01:00
parent 8454b95df8
commit a6a4eb80fd
5 changed files with 33 additions and 17 deletions

View file

@ -13,6 +13,10 @@ pub type Usually<T> = Result<T, Box<dyn Error>>;
/// Standard optional result type.
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
#[cfg(test)] #[test] fn test_dimensions () {
assert_eq!(Area::center(&[10u16, 10, 20, 20]), [20, 20]);
}
#[cfg(test)] #[test] fn test_stub_engine () -> Usually<()> {
struct TestEngine(bool);
struct TestInput(bool);
@ -46,11 +50,11 @@ pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
fn area_mut (&mut self) -> &mut [u16;4] {
&mut self.0
}
fn place (&mut self, _: [u16;4], _: &impl Layout<TestEngine>) {
fn place (&mut self, _: [u16;4], _: &impl Content<TestEngine>) {
()
}
}
impl Layout<TestEngine> for String {
impl Content<TestEngine> for String {
fn render (&self, to: &mut TestOutput) {
to.area_mut().set_w(self.len() as u16);
}
@ -62,8 +66,8 @@ pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
use crate::tui::*;
use std::sync::{Arc, RwLock};
struct TestComponent(String);
impl Layout<Tui> for TestComponent {
fn layout (&self) -> Option<impl Layout<Tui>> {
impl Content<Tui> for TestComponent {
fn content (&self) -> Option<impl Content<Tui>> {
Some(self.0.as_str())
}
}