performance fixes
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
facile pop culture reference 2026-09-15 00:40:52 +03:00
parent c9a89eeb1d
commit 48aaa3933a
4 changed files with 38 additions and 21 deletions

2
dizzle

@ -1 +1 @@
Subproject commit b6c1bb5f9400c28de1709df78c18e0d4d5618a15
Subproject commit 3d04622e4266eac65021da6cd3d378e84a843b87

View file

@ -211,24 +211,24 @@ pub fn bar_areas <'a, S: Screen> (
let XYWH(x0, y0, w0, h0) = to.area();
Ok(match split {
Split::South => (
to.size(XYWH(x0, y0, w0, n), a)?,
to.size(XYWH(x0, y0 + n, w0, h0 - n), b)?,
Some(XYWH(x0, y0, w0, n)),
Some(XYWH(x0, y0 + n, w0, h0 - n)),
),
Split::East => (
to.size(XYWH(x0, y0, n, h0), a)?,
to.size(XYWH(x0 + n, y0, w0 - n, h0), b)?,
Some(XYWH(x0, y0, n, h0)),
Some(XYWH(x0 + n, y0, w0 - n, h0)),
),
Split::North => (
to.size(XYWH(x0, y0 + h0 - n, w0, n), a)?,
to.size(XYWH(x0, y0, w0, h0 - n), b)?,
Some(XYWH(x0, y0 + h0 - n, w0, n)),
Some(XYWH(x0, y0, w0, h0 - n)),
),
Split::West => (
to.size(XYWH(x0 + w0 - n, y0, n, h0), a)?,
to.size(XYWH(x0, y0, w0 - n, h0), b)?,
Some(XYWH(x0 + w0 - n, y0, n, h0)),
Some(XYWH(x0, y0, w0 - n, h0)),
),
Split::Above | Split::Below => (
to.size(XYWH(x0, y0, w0, h0), a)?,
to.size(XYWH(x0, y0, w0, h0), b)?,
Some(XYWH(x0, y0, w0, h0)),
Some(XYWH(x0, y0, w0, h0)),
),
})
}

View file

@ -126,10 +126,12 @@ impl Screen for Tui {
let prev = self.area();
if let Some(area) = area.into() {
*self.area_mut() = area.into();
let result = draw(self);
*self.area_mut() = prev;
result
} else {
draw(self)
}
let result = draw(self);
*self.area_mut() = prev;
result
}
}

View file

@ -1,11 +1,19 @@
use crate::*;
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.
///
/// Width is computed using [unicode_width].
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> {
fn as_ref (&self) -> &str {
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> {
fn as_ref (&self) -> &str {
self.1.as_ref()
@ -127,12 +130,24 @@ mod text_term {
});
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> {
let XYWH(x, y, w, h) = to.area();
let mut max_w = 0u16;
let mut max_h = 0u16;
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;
max_w = max_w.max(length);
max_h += 1;
@ -142,7 +157,7 @@ mod text_term {
}
}
} 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;
max_w = max_w.max(length);
max_h += 1;