mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
0.1.2: fix an import
This commit is contained in:
parent
9b3c8d4ac6
commit
1774419d93
4 changed files with 91 additions and 84 deletions
|
|
@ -0,0 +1,80 @@
|
|||
use crate::*;
|
||||
use ratatui::{prelude::Position, style::Color::*};
|
||||
|
||||
pub struct ScrollbarV {
|
||||
pub offset: usize,
|
||||
pub length: usize,
|
||||
pub total: usize,
|
||||
}
|
||||
|
||||
pub struct ScrollbarH {
|
||||
pub offset: usize,
|
||||
pub length: usize,
|
||||
pub total: usize,
|
||||
}
|
||||
|
||||
impl ScrollbarV {
|
||||
const ICON_DEC: &[char] = &['▲'];
|
||||
const ICON_INC: &[char] = &['▼'];
|
||||
}
|
||||
|
||||
impl ScrollbarH {
|
||||
const ICON_DEC: &[char] = &[' ', '🞀', ' '];
|
||||
const ICON_INC: &[char] = &[' ', '🞂', ' '];
|
||||
}
|
||||
|
||||
impl Content<TuiOut> for ScrollbarV {
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
let [x, y1, _w, h] = to.area().xywh();
|
||||
let y2 = y1 + h;
|
||||
for (i, y) in (y1..=y2).enumerate() {
|
||||
if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) {
|
||||
if (i as usize) < (Self::ICON_DEC.len()) {
|
||||
cell.set_fg(Rgb(255, 255, 255));
|
||||
cell.set_bg(Rgb(0, 0, 0));
|
||||
cell.set_char(Self::ICON_DEC[i as usize]);
|
||||
} else if (i as usize) > (h as usize - Self::ICON_INC.len()) {
|
||||
cell.set_fg(Rgb(255, 255, 255));
|
||||
cell.set_bg(Rgb(0, 0, 0));
|
||||
cell.set_char(Self::ICON_INC[h as usize - i]);
|
||||
} else if false {
|
||||
cell.set_fg(Rgb(255, 255, 255));
|
||||
cell.set_bg(Reset);
|
||||
cell.set_char('‖'); // ━
|
||||
} else {
|
||||
cell.set_fg(Rgb(0, 0, 0));
|
||||
cell.set_bg(Reset);
|
||||
cell.set_char('╎'); // ━
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Content<TuiOut> for ScrollbarH {
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
let [x1, y, w, _h] = to.area().xywh();
|
||||
let x2 = x1 + w;
|
||||
for (i, x) in (x1..=x2).enumerate() {
|
||||
if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) {
|
||||
if i < (Self::ICON_DEC.len()) {
|
||||
cell.set_fg(Rgb(255, 255, 255));
|
||||
cell.set_bg(Rgb(0, 0, 0));
|
||||
cell.set_char(Self::ICON_DEC[i as usize]);
|
||||
} else if i > (w as usize - Self::ICON_INC.len()) {
|
||||
cell.set_fg(Rgb(255, 255, 255));
|
||||
cell.set_bg(Rgb(0, 0, 0));
|
||||
cell.set_char(Self::ICON_INC[w as usize - i]);
|
||||
} else if false {
|
||||
cell.set_fg(Rgb(255, 255, 255));
|
||||
cell.set_bg(Reset);
|
||||
cell.set_char('━');
|
||||
} else {
|
||||
cell.set_fg(Rgb(0, 0, 0));
|
||||
cell.set_bg(Reset);
|
||||
cell.set_char('╌');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue