mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
This commit is contained in:
parent
c9a89eeb1d
commit
48aaa3933a
4 changed files with 38 additions and 21 deletions
2
dizzle
2
dizzle
|
|
@ -1 +1 @@
|
||||||
Subproject commit b6c1bb5f9400c28de1709df78c18e0d4d5618a15
|
Subproject commit 3d04622e4266eac65021da6cd3d378e84a843b87
|
||||||
|
|
@ -211,24 +211,24 @@ pub fn bar_areas <'a, S: Screen> (
|
||||||
let XYWH(x0, y0, w0, h0) = to.area();
|
let XYWH(x0, y0, w0, h0) = to.area();
|
||||||
Ok(match split {
|
Ok(match split {
|
||||||
Split::South => (
|
Split::South => (
|
||||||
to.size(XYWH(x0, y0, w0, n), a)?,
|
Some(XYWH(x0, y0, w0, n)),
|
||||||
to.size(XYWH(x0, y0 + n, w0, h0 - n), b)?,
|
Some(XYWH(x0, y0 + n, w0, h0 - n)),
|
||||||
),
|
),
|
||||||
Split::East => (
|
Split::East => (
|
||||||
to.size(XYWH(x0, y0, n, h0), a)?,
|
Some(XYWH(x0, y0, n, h0)),
|
||||||
to.size(XYWH(x0 + n, y0, w0 - n, h0), b)?,
|
Some(XYWH(x0 + n, y0, w0 - n, h0)),
|
||||||
),
|
),
|
||||||
Split::North => (
|
Split::North => (
|
||||||
to.size(XYWH(x0, y0 + h0 - n, w0, n), a)?,
|
Some(XYWH(x0, y0 + h0 - n, w0, n)),
|
||||||
to.size(XYWH(x0, y0, w0, h0 - n), b)?,
|
Some(XYWH(x0, y0, w0, h0 - n)),
|
||||||
),
|
),
|
||||||
Split::West => (
|
Split::West => (
|
||||||
to.size(XYWH(x0 + w0 - n, y0, n, h0), a)?,
|
Some(XYWH(x0 + w0 - n, y0, n, h0)),
|
||||||
to.size(XYWH(x0, y0, w0 - n, h0), b)?,
|
Some(XYWH(x0, y0, w0 - n, h0)),
|
||||||
),
|
),
|
||||||
Split::Above | Split::Below => (
|
Split::Above | Split::Below => (
|
||||||
to.size(XYWH(x0, y0, w0, h0), a)?,
|
Some(XYWH(x0, y0, w0, h0)),
|
||||||
to.size(XYWH(x0, y0, w0, h0), b)?,
|
Some(XYWH(x0, y0, w0, h0)),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,10 +126,12 @@ impl Screen for Tui {
|
||||||
let prev = self.area();
|
let prev = self.area();
|
||||||
if let Some(area) = area.into() {
|
if let Some(area) = area.into() {
|
||||||
*self.area_mut() = area.into();
|
*self.area_mut() = area.into();
|
||||||
}
|
|
||||||
let result = draw(self);
|
let result = draw(self);
|
||||||
*self.area_mut() = prev;
|
*self.area_mut() = prev;
|
||||||
result
|
result
|
||||||
|
} else {
|
||||||
|
draw(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
29
src/text.rs
29
src/text.rs
|
|
@ -1,11 +1,19 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
pub(crate) use ::unicode_width::*;
|
pub(crate) use ::unicode_width::*;
|
||||||
|
|
||||||
|
/// Displays a multi-line text string.
|
||||||
|
pub struct Text<T: AsRef<str>>(T);
|
||||||
|
|
||||||
/// Displays an owned [str]-like with fixed maximum width.
|
/// Displays an owned [str]-like with fixed maximum width.
|
||||||
///
|
///
|
||||||
/// Width is computed using [unicode_width].
|
/// Width is computed using [unicode_width].
|
||||||
pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
|
pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
|
||||||
|
|
||||||
|
/// Displays a borrowed [str]-like with fixed maximum width
|
||||||
|
///
|
||||||
|
/// Width is computed using [unicode_width].
|
||||||
|
pub struct TrimStr<'a, T: AsRef<str>>(pub u16, pub &'a T);
|
||||||
|
|
||||||
impl<T: AsRef<str>> AsRef<str> for TrimString<T> {
|
impl<T: AsRef<str>> AsRef<str> for TrimString<T> {
|
||||||
fn as_ref (&self) -> &str {
|
fn as_ref (&self) -> &str {
|
||||||
self.1.as_ref()
|
self.1.as_ref()
|
||||||
|
|
@ -18,11 +26,6 @@ impl<'a, T: AsRef<str>> TrimString<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Displays a borrowed [str]-like with fixed maximum width
|
|
||||||
///
|
|
||||||
/// Width is computed using [unicode_width].
|
|
||||||
pub struct TrimStr<'a, T: AsRef<str>>(pub u16, pub &'a T);
|
|
||||||
|
|
||||||
impl<T: AsRef<str>> AsRef<str> for TrimStr<'_, T> {
|
impl<T: AsRef<str>> AsRef<str> for TrimStr<'_, T> {
|
||||||
fn as_ref (&self) -> &str {
|
fn as_ref (&self) -> &str {
|
||||||
self.1.as_ref()
|
self.1.as_ref()
|
||||||
|
|
@ -127,12 +130,24 @@ mod text_term {
|
||||||
});
|
});
|
||||||
|
|
||||||
impl<'a> Draw<Tui> for &str {
|
impl<'a> Draw<Tui> for &str {
|
||||||
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
|
let XYWH(x, y, w, h) = to.area();
|
||||||
|
if h > 0 {
|
||||||
|
to.buffer().map(|buf|buf.set_stringn(x, y, self, w as usize, Style::default()));
|
||||||
|
Ok(Some(XYWH(x, y, w.min(self.len() as u16), 1)))
|
||||||
|
} else {
|
||||||
|
Ok(Some(XYWH(x, y, 0, 0)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<str>> Draw<Tui> for Text<T> {
|
||||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
let XYWH(x, y, w, h) = to.area();
|
let XYWH(x, y, w, h) = to.area();
|
||||||
let mut max_w = 0u16;
|
let mut max_w = 0u16;
|
||||||
let mut max_h = 0u16;
|
let mut max_h = 0u16;
|
||||||
if to.buffer().is_some() {
|
if to.buffer().is_some() {
|
||||||
for (index, line) in self.split("\n").enumerate() {
|
for (index, line) in self.0.as_ref().split("\n").enumerate() {
|
||||||
let length = width_chars_max(w, line) as u16;
|
let length = width_chars_max(w, line) as u16;
|
||||||
max_w = max_w.max(length);
|
max_w = max_w.max(length);
|
||||||
max_h += 1;
|
max_h += 1;
|
||||||
|
|
@ -142,7 +157,7 @@ mod text_term {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (index, line) in self.split("\n").enumerate() {
|
for line in self.0.as_ref().split("\n") {
|
||||||
let length = width_chars_max(w, line) as u16;
|
let length = width_chars_max(w, line) as u16;
|
||||||
max_w = max_w.max(length);
|
max_w = max_w.max(length);
|
||||||
max_h += 1;
|
max_h += 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue