mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
more built-in centering
This commit is contained in:
parent
8454b95df8
commit
a6a4eb80fd
5 changed files with 33 additions and 17 deletions
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue