mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
cleanup: sub 4k again
This commit is contained in:
parent
214061a419
commit
d8c9abf744
13 changed files with 101 additions and 505 deletions
|
|
@ -128,3 +128,36 @@ pub fn lozenge_right (buf: &mut Buffer, x: u16, y1: u16, h: u16, style: Option<S
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw_box (buffer: &mut Buffer, area: Rect) -> Rect {
|
||||
draw_box_styled(buffer, area, Some(Style::default().gray().dim()))
|
||||
}
|
||||
|
||||
pub fn draw_box_styled (buffer: &mut Buffer, area: Rect, style: Option<Style>) -> Rect {
|
||||
if area.width < 1 || area.height < 1 {
|
||||
return area
|
||||
}
|
||||
format!("╭{}╮", "─".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y, style);
|
||||
for y in (area.y + 1)..(area.y + area.height - 1) {
|
||||
"│".blit(buffer, area.x, y, style);
|
||||
"│".blit(buffer, area.x + area.width - 1, y, style);
|
||||
}
|
||||
format!("╰{}╯", "─".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y + area.height - 1, style);
|
||||
area
|
||||
}
|
||||
|
||||
pub fn draw_box_styled_dotted (buffer: &mut Buffer, area: Rect, style: Option<Style>) -> Rect {
|
||||
if area.width < 1 || area.height < 1 {
|
||||
return area
|
||||
}
|
||||
format!("╭{}╮", "┅".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y, style);
|
||||
for y in (area.y + 1)..(area.y + area.height - 1) {
|
||||
"┇".blit(buffer, area.x, y, style);
|
||||
"┇".blit(buffer, area.x + area.width - 1, y, style);
|
||||
}
|
||||
format!("╰{}╯", "┅".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y + area.height - 1, style);
|
||||
area
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,20 @@ pub struct ChainView<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ChainView<'a> {
|
||||
pub fn horizontal (app: &'a App) -> Self {
|
||||
Self::new(app, false)
|
||||
}
|
||||
pub fn vertical (app: &'a App) -> Self {
|
||||
Self::new(app, true)
|
||||
}
|
||||
pub fn new (app: &'a App, vertical: bool) -> Self {
|
||||
Self {
|
||||
vertical,
|
||||
focused: app.section == AppSection::Chain,
|
||||
track: app.tracks.get(app.track_cursor - 1),
|
||||
vertical
|
||||
track: match app.track_cursor {
|
||||
0 => None,
|
||||
_ => app.tracks.get(app.track_cursor - 1)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
use crate::core::*;
|
||||
mod container; pub use self::container::*;
|
||||
mod scroll; pub use self::scroll::*;
|
||||
|
||||
pub mod table;
|
||||
|
||||
pub trait Modal<T>: Device {
|
||||
fn handle_with_state (&self, state: &mut T, event: &AppEvent) -> Usually<bool>;
|
||||
|
|
@ -16,40 +12,48 @@ pub trait MaxHeight: Device {
|
|||
|
||||
impl<T: Device> MaxHeight for T {}
|
||||
|
||||
pub fn draw_box (buffer: &mut Buffer, area: Rect) -> Rect {
|
||||
draw_box_styled(buffer, area, Some(Style::default().gray().dim()))
|
||||
pub enum Collected<'a> {
|
||||
Box(Box<dyn Render + Sync + 'a>),
|
||||
Ref(&'a (dyn Render + Sync + 'a)),
|
||||
None
|
||||
}
|
||||
|
||||
pub fn draw_box_styled (buffer: &mut Buffer, area: Rect, style: Option<Style>) -> Rect {
|
||||
if area.width < 1 || area.height < 1 {
|
||||
return area
|
||||
impl<'a> Render for Collected<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
match self {
|
||||
Self::Box(item) => (*item).render(buf, area),
|
||||
Self::Ref(item) => (*item).render(buf, area),
|
||||
Self::None => Ok(area),
|
||||
}
|
||||
}
|
||||
format!("╭{}╮", "─".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y, style);
|
||||
for y in (area.y + 1)..(area.y + area.height - 1) {
|
||||
"│".blit(buffer, area.x, y, style);
|
||||
"│".blit(buffer, area.x + area.width - 1, y, style);
|
||||
}
|
||||
format!("╰{}╯", "─".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y + area.height - 1, style);
|
||||
area
|
||||
}
|
||||
|
||||
pub fn draw_box_styled_dotted (buffer: &mut Buffer, area: Rect, style: Option<Style>) -> Rect {
|
||||
if area.width < 1 || area.height < 1 {
|
||||
return area
|
||||
pub struct Collector<'a>(pub Vec<Collected<'a>>);
|
||||
|
||||
//impl<'a, R: Render + 'a> FnOnce<(R,)> for Collector<'a> {
|
||||
//type Output = ();
|
||||
//extern "rust-call" fn call_once (self, (device, ): (R,)) -> Self::Output {
|
||||
//self.add(widget.into_collected());
|
||||
//}
|
||||
//}
|
||||
|
||||
impl<'a> Collector<'a> {
|
||||
pub fn collect (collect: impl Fn(&mut Collector<'a>)) -> Self {
|
||||
let mut items = Self(vec![]);
|
||||
collect(&mut items);
|
||||
items
|
||||
}
|
||||
format!("╭{}╮", "┅".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y, style);
|
||||
for y in (area.y + 1)..(area.y + area.height - 1) {
|
||||
"┇".blit(buffer, area.x, y, style);
|
||||
"┇".blit(buffer, area.x + area.width - 1, y, style);
|
||||
fn add (mut self, widget: Collected<'a>) -> Self {
|
||||
self.0.push(widget);
|
||||
self
|
||||
}
|
||||
format!("╰{}╯", "┅".repeat((area.width - 2).into()))
|
||||
.blit(buffer, area.x, area.y + area.height - 1, style);
|
||||
area
|
||||
}
|
||||
|
||||
pub trait Collection<'a, T, U> {
|
||||
fn add (self, widget: impl Render + 'a) -> Self;
|
||||
}
|
||||
|
||||
|
||||
//struct AppLayout {
|
||||
//focus: usize,
|
||||
//track_focus: usize,
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
|
||||
pub enum Collected<'a> {
|
||||
Box(Box<dyn Render + 'a>),
|
||||
Ref(&'a (dyn Render + 'a)),
|
||||
None
|
||||
}
|
||||
|
||||
impl<'a> Render for Collected<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
match self {
|
||||
Self::Box(item) => (*item).render(buf, area),
|
||||
Self::Ref(item) => (*item).render(buf, area),
|
||||
Self::None => Ok(area),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Collector<'a>(pub Vec<Collected<'a>>);
|
||||
|
||||
impl<'a, R: Render + 'a> FnOnce<(R)> for Collector<'a> {
|
||||
type Output = ();
|
||||
extern "rust-call" fn call_once (self, (device, ): (R,)) -> Self::Output {
|
||||
self.add(widget.into_collected());
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Collector<'a> {
|
||||
pub fn collect (collect: impl Fn(&mut Collector<'a>)) -> Self {
|
||||
let mut items = Self(vec![]);
|
||||
collect(&mut items);
|
||||
items
|
||||
}
|
||||
fn add (mut self, widget: Collected<'a>) -> Self {
|
||||
self.0.push(widget);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Collection<'a, T, U> {
|
||||
fn add (self, widget: impl Render + 'a) -> Self;
|
||||
}
|
||||
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
use crate::core::*;
|
||||
|
||||
pub struct Stack<'a>(pub &'a[Box<dyn Render + Sync>]);
|
||||
|
||||
impl<'a> Render for Stack<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let mut area2 = area.clone();
|
||||
for layer in self.0.iter() {
|
||||
area2 = layer.render(buf, area2)?;
|
||||
}
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Column(pub Vec<Box<dyn Device>>);
|
||||
|
||||
pub struct Row(pub Vec<Box<dyn Device>>);
|
||||
|
||||
impl Column {
|
||||
pub fn new (items: Vec<Box<dyn Device>>) -> Self {
|
||||
Self(items)
|
||||
}
|
||||
pub fn draw (buf: &mut Buffer, area: Rect, items: &[impl Render], gap: i16)
|
||||
-> Usually<(Rect, Vec<Rect>)>
|
||||
{
|
||||
let mut w = 0u16;
|
||||
let mut h = 0u16;
|
||||
let mut rects = vec![];
|
||||
for (_i, device) in items.iter().enumerate() {
|
||||
let y = area.y + h;
|
||||
let rect = Rect { x: area.x, y, width: area.width, height: area.height - h };
|
||||
let result = device.render(buf, rect)?;
|
||||
rects.push(result);
|
||||
w = w.max(result.width);
|
||||
h = ((h + result.height) as i16 + gap).max(0) as u16;
|
||||
}
|
||||
Ok((Rect { x: area.x, y: area.y, width: w, height: h }, rects))
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Column {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
Ok(Column::draw(buf, area, &self.0, 0)?.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Row {
|
||||
pub fn new (items: Vec<Box<dyn Device>>) -> Self {
|
||||
Self(items)
|
||||
}
|
||||
pub fn draw (buf: &mut Buffer, area: Rect, items: &[impl Render], gap: i16)
|
||||
-> Usually<(Rect, Vec<Rect>)>
|
||||
{
|
||||
let mut w = 0u16;
|
||||
let mut h = 0u16;
|
||||
let mut rects = vec![];
|
||||
for (_i, device) in items.iter().enumerate() {
|
||||
let x = area.x + w;
|
||||
let rect = Rect { x, y: area.y, width: area.width - w, height: area.height };
|
||||
let result = device.render(buf, rect)?;
|
||||
rects.push(result);
|
||||
w = ((w + result.width) as i16 + gap).max(0) as u16;
|
||||
h = h.max(result.height);
|
||||
}
|
||||
Ok((Rect { x: area.x, y: area.y, width: w, height: h }, rects))
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Row {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
Ok(Row::draw(buf, area, &self.0, 0)?.0)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
use crate::core::*;
|
||||
|
||||
pub trait BorderStyle {
|
||||
const NW: &'static str = "";
|
||||
const N: &'static str = "";
|
||||
const NE: &'static str = "";
|
||||
const E: &'static str = "";
|
||||
const SE: &'static str = "";
|
||||
const S: &'static str = "";
|
||||
const SW: &'static str = "";
|
||||
const W: &'static str = "";
|
||||
|
||||
fn draw (&self, buf: &mut Buffer, area: Rect) {
|
||||
let style = self.style();
|
||||
for x in area.x+1..(area.x+area.width).saturating_sub(2) {
|
||||
Self::N.blit(buf, x, area.y, style);
|
||||
Self::S.blit(buf, x, area.y + area.height - 1, style);
|
||||
}
|
||||
for y in area.y+1..(area.y+area.height).saturating_sub(2) {
|
||||
Self::W.blit(buf, area.x, y, style);
|
||||
Self::E.blit(buf, area.x + area.width - 1, y, style);
|
||||
}
|
||||
Self::NW.blit(buf, area.x, area.y, style);
|
||||
Self::NE.blit(buf, area.x + area.width - 1, area.y, style);
|
||||
Self::SW.blit(buf, area.x, area.y + area.height - 1, style);
|
||||
Self::SE.blit(buf, area.x + area.width - 1, area.y + area.height - 1, style);
|
||||
}
|
||||
|
||||
fn style (&self) -> Option<Style> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Lozenge(pub Style);
|
||||
|
||||
impl BorderStyle for Lozenge {
|
||||
const N: &'static str = "─";
|
||||
const S: &'static str = "─";
|
||||
const NW: &'static str = "╭";
|
||||
const W: &'static str = "│";
|
||||
const SW: &'static str = "╰";
|
||||
const NE: &'static str = "╮";
|
||||
const E: &'static str = "│";
|
||||
const SE: &'static str = "╯";
|
||||
|
||||
fn style (&self) -> Option<Style> {
|
||||
Some(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RailV(pub Style);
|
||||
|
||||
impl BorderStyle for RailV {
|
||||
const NW: &'static str = "▌";
|
||||
const W: &'static str = "▌";
|
||||
const SW: &'static str = "▌";
|
||||
const NE: &'static str = "▐";
|
||||
const E: &'static str = "▐";
|
||||
const SE: &'static str = "▐";
|
||||
|
||||
fn style (&self) -> Option<Style> {
|
||||
Some(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
const LOZENGE: [[&'static str;3];3] = [
|
||||
["╭", "─", "╮"],
|
||||
["│", " ", "│"],
|
||||
["╰", "─", "╯"],
|
||||
];
|
||||
|
||||
pub fn lozenge_left (buf: &mut Buffer, x: u16, y1: u16, h: u16, style: Option<Style>) {
|
||||
let y2 = y1 + h;
|
||||
let y3 = y2.saturating_sub(1);
|
||||
for y in y1..y2 {
|
||||
if y == y1 {
|
||||
LOZENGE[0][0]
|
||||
} else if y == y3 {
|
||||
LOZENGE[2][0]
|
||||
} else {
|
||||
LOZENGE[1][0]
|
||||
}.blit(buf, x, y, style)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lozenge_right (buf: &mut Buffer, x: u16, y1: u16, h: u16, style: Option<Style>) {
|
||||
let y2 = y1 + h;
|
||||
let y3 = y2.saturating_sub(1);
|
||||
for y in y1..y2 {
|
||||
if y == y1 {
|
||||
LOZENGE[0][2]
|
||||
} else if y == y3 {
|
||||
LOZENGE[2][2]
|
||||
} else {
|
||||
LOZENGE[1][2]
|
||||
}.blit(buf, x, y, style)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
pub struct ScrollY;
|
||||
|
||||
pub struct ScrollX;
|
||||
|
||||
pub struct ScrollXY;
|
||||
|
|
@ -30,7 +30,10 @@ pub struct SequencerView<'a> {
|
|||
|
||||
impl<'a> SequencerView<'a> {
|
||||
pub fn new (app: &'a App) -> Self {
|
||||
let track = app.tracks.get(app.track_cursor - 1);
|
||||
let track = match app.track_cursor {
|
||||
0 => None,
|
||||
_ => app.tracks.get(app.track_cursor - 1)
|
||||
};
|
||||
let phrase = app.phrase();
|
||||
Self {
|
||||
phrase,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
use crate::core::*;
|
||||
|
||||
pub struct If<'a>(pub bool, pub &'a (dyn Render + Sync));
|
||||
|
||||
impl<'a> Render for If<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
if self.0 {
|
||||
self.1.render(buf, area)
|
||||
} else {
|
||||
().render(buf, area)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Direction {
|
||||
Down,
|
||||
Right,
|
||||
|
|
@ -11,6 +23,9 @@ impl<'a, const N: usize> Split<'a, N> {
|
|||
pub fn down (items: [&'a (dyn Render + Sync);N]) -> Self {
|
||||
Self(Direction::Down, items)
|
||||
}
|
||||
pub fn right (items: [&'a (dyn Render + Sync);N]) -> Self {
|
||||
Self(Direction::Right, items)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, const N: usize> Render for Split<'a, N> {
|
||||
|
|
@ -35,63 +50,3 @@ impl<'a, const N: usize> Render for Split<'a, N> {
|
|||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
//pub struct Split<'a> {
|
||||
//a: &'a (dyn Render + Sync),
|
||||
//b: &'a (dyn Render + Sync),
|
||||
//direction: Direction,
|
||||
//reverse: bool
|
||||
//}
|
||||
|
||||
//impl<'a> Split<'a> {
|
||||
//pub fn lr (a: &'a (dyn Render + Sync), b: &'a (dyn Render + Sync)) -> Self {
|
||||
//Self { a, b, direction: Direction::X, reverse: false }
|
||||
//}
|
||||
//pub fn rl (a: &'a (dyn Render + Sync), b: &'a (dyn Render + Sync)) -> Self {
|
||||
//Self { a, b, direction: Direction::X, reverse: true }
|
||||
//}
|
||||
//pub fn tb (a: &'a (dyn Render + Sync), b: &'a (dyn Render + Sync)) -> Self {
|
||||
//Self { a, b, direction: Direction::Y, reverse: false }
|
||||
//}
|
||||
//pub fn bt (a: &'a (dyn Render + Sync), b: &'a (dyn Render + Sync)) -> Self {
|
||||
//Self { a, b, direction: Direction::Y, reverse: true }
|
||||
//}
|
||||
|
||||
//fn split (&self, length: u16) -> (u16, u16) {
|
||||
//let l1 = (length as f64 * self.proportion).round() as u16;
|
||||
//let l2 = length.saturating_sub(l1);
|
||||
//(l1, l2)
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl<'a> Render for Split<'a> {
|
||||
//fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
//let Rect { x, y, width, height } = area;
|
||||
//let area1 = if self.reverse { self.b } else { self.a }
|
||||
//.render(buf, area)?;
|
||||
//let area2 = if self.reverse { self.a } else { self.b }
|
||||
//.render(buf, match (self.direction, self.reverse)Rect {
|
||||
//})?;
|
||||
//let (area1, area2) = match self.direction {
|
||||
//Direction::X => {
|
||||
//let (w1, w2) = self.split(width);
|
||||
//(Rect { x, y, width: w1, height }, Rect { x: x + w1, y, width: w2, height })
|
||||
//},
|
||||
//Direction::Y => {
|
||||
//let (h1, h2) = self.split(height);
|
||||
//(Rect { x, y, width, height: h1 }, Rect { x, y: y + h1, width, height: h2 })
|
||||
//},
|
||||
//};
|
||||
//match self.reverse {
|
||||
//true => {
|
||||
//self.b.render(buf, area1)?;
|
||||
//self.a.render(buf, area2)?;
|
||||
//},
|
||||
//false => {
|
||||
//self.a.render(buf, area1)?;
|
||||
//self.b.render(buf, area2)?;
|
||||
//},
|
||||
//};
|
||||
//Ok(area)
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -31,3 +31,4 @@ impl<T> Table<T> {
|
|||
self.columns[col][row] = cell;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue