mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
- okay, that seems to have fixed the FieldH/FieldV issue? - thought that'd never happen - still not happy with how Layout override is working
This commit is contained in:
parent
731f4a971e
commit
8c54510f63
9 changed files with 179 additions and 118 deletions
|
|
@ -11,7 +11,6 @@ mod tui_border; pub use self::tui_border::*;
|
|||
mod tui_button; pub use self::tui_button::*;
|
||||
mod tui_color; pub use self::tui_color::*;
|
||||
mod tui_error; pub use self::tui_error::*;
|
||||
mod tui_field; pub use self::tui_field::*;
|
||||
mod tui_phat; pub use self::tui_phat::*;
|
||||
mod tui_repeat; pub use self::tui_repeat::*;
|
||||
mod tui_scroll; pub use self::tui_scroll::*;
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
use crate::*;
|
||||
|
||||
impl<T: TuiContent, U: TuiContent> Draw<TuiOut> for FieldH<ItemTheme, T, U> {
|
||||
fn draw (&self, to: &mut TuiOut) { to.place(&self.content()) }
|
||||
}
|
||||
impl<T: TuiContent, U: TuiContent> Draw<TuiOut> for FieldV<ItemTheme, T, U> {
|
||||
fn draw (&self, to: &mut TuiOut) { to.place(&self.content()) }
|
||||
}
|
||||
|
||||
// TODO:
|
||||
pub struct Field<T, U> {
|
||||
pub direction: Direction,
|
||||
pub label: Option<T>,
|
||||
pub label_fg: Option<ItemColor>,
|
||||
pub label_bg: Option<ItemColor>,
|
||||
pub label_align: Option<Direction>,
|
||||
pub value: Option<U>,
|
||||
pub value_fg: Option<ItemColor>,
|
||||
pub value_bg: Option<ItemColor>,
|
||||
pub value_align: Option<Direction>,
|
||||
}
|
||||
impl<T: Content<TuiOut>, U: Content<TuiOut>> HasContent<TuiOut> for Field<T, U> {
|
||||
fn content (&self) -> impl Content<TuiOut> {
|
||||
"TODO"
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> Field<T, U> {
|
||||
pub fn new (direction: Direction) -> Field<(), ()> {
|
||||
Field {
|
||||
direction,
|
||||
label: None,
|
||||
label_fg: None,
|
||||
label_bg: None,
|
||||
label_align: None,
|
||||
value: None,
|
||||
value_fg: None,
|
||||
value_bg: None,
|
||||
value_align: None,
|
||||
}
|
||||
}
|
||||
pub fn label <L> (
|
||||
self,
|
||||
label: Option<L>,
|
||||
align: Option<Direction>,
|
||||
fg: Option<ItemColor>,
|
||||
bg: Option<ItemColor>
|
||||
) -> Field<L, U> {
|
||||
Field {
|
||||
label,
|
||||
label_fg: fg,
|
||||
label_bg: bg,
|
||||
label_align: align,
|
||||
..self
|
||||
}
|
||||
}
|
||||
pub fn value <V> (
|
||||
self,
|
||||
value: Option<V>,
|
||||
align: Option<Direction>,
|
||||
fg: Option<ItemColor>,
|
||||
bg: Option<ItemColor>
|
||||
) -> Field<T, V> {
|
||||
Field {
|
||||
value,
|
||||
value_fg: fg,
|
||||
value_bg: bg,
|
||||
value_align: align,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,35 @@
|
|||
use crate::*;
|
||||
use crate::ratatui::prelude::Position;
|
||||
use unicode_width::{UnicodeWidthStr, UnicodeWidthChar};
|
||||
impl Layout<TuiOut> for &str { fn layout (&self, to: [u16;4]) -> [u16;4] { to.center_xy([width_chars_max(to.w(), self), 1]) } }
|
||||
impl Draw<TuiOut> for &str { fn draw (&self, to: &mut TuiOut) { let [x, y, w, ..] = self.layout(to.area()); to.text(&self, x, y, w) } }
|
||||
impl Layout<TuiOut> for String { fn layout (&self, to: [u16;4]) -> [u16;4] { self.as_str().layout(to) } }
|
||||
impl Draw<TuiOut> for String { fn draw (&self, to: &mut TuiOut) { self.as_str().draw(to) } }
|
||||
impl Layout<TuiOut> for Arc<str> { fn layout (&self, to: [u16;4]) -> [u16;4] { self.as_ref().layout(to) } }
|
||||
impl Draw<TuiOut> for Arc<str> { fn draw (&self, to: &mut TuiOut) { self.as_ref().draw(to) } }
|
||||
|
||||
impl Draw<TuiOut> for &str {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let [x, y, w, ..] = self.layout(to.area());
|
||||
to.text(&self, x, y, w)
|
||||
}
|
||||
}
|
||||
impl Draw<TuiOut> for String {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
self.as_str().draw(to)
|
||||
}
|
||||
}
|
||||
impl Draw<TuiOut> for Arc<str> {
|
||||
fn draw (&self, to: &mut TuiOut) { self.as_ref().draw(to) }
|
||||
}
|
||||
|
||||
impl Layout<TuiOut> for &str {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] { to.center_xy([width_chars_max(to.w(), self), 1]) }
|
||||
}
|
||||
impl Layout<TuiOut> for String {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.as_str().layout(to)
|
||||
}
|
||||
}
|
||||
impl Layout<TuiOut> for Arc<str> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.as_ref().layout(to)
|
||||
}
|
||||
}
|
||||
|
||||
fn width_chars_max (max: u16, text: impl AsRef<str>) -> u16 {
|
||||
let mut width: u16 = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue