From 7b568c55b8f961f014b9c58405a9eafb5fca7b51 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 20 Jun 2024 21:56:54 +0300 Subject: [PATCH] focus is weird --- src/device/sequencer.rs | 4 ++-- src/device/transport.rs | 10 ++++------ src/layout.rs | 35 +++++++++++++++++------------------ src/main.rs | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/device/sequencer.rs b/src/device/sequencer.rs index d4511587..431a0053 100644 --- a/src/device/sequencer.rs +++ b/src/device/sequencer.rs @@ -249,7 +249,7 @@ fn draw_vertical (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) -> U let Rect { x, y, .. } = area; let (time0, time1) = s.time_axis; let (note0, note1) = s.note_axis; - let _bw = Style::default().dim(); + let bw = Style::default().dim().on_black(); let bg = Style::default().on_black(); for key in note0..note1 { let x = x + 5 + key - note0; @@ -295,7 +295,7 @@ fn draw_vertical (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) -> U (true, true) => ("█", bg), (true, false) => ("▀", bg), (false, true) => ("▄", bg), - (false, false) => (" ", bg), + (false, false) => ("·", bw), }; buf.set_string(x + 5 + k - note0, y, character, style); } diff --git a/src/device/transport.rs b/src/device/transport.rs index 2981ef27..e0a50cbe 100644 --- a/src/device/transport.rs +++ b/src/device/transport.rs @@ -62,8 +62,8 @@ pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect) { //area.x = area.width.saturating_sub(80) / 2; //area.width = area.width.min(80); - area.height = 5; - //draw_box(buf, area); + area.height = 3; + draw_box(buf, area); let label = Style::default().white().not_dim(); let border = Style::default().gray().dim(); let mut x = 2; @@ -79,13 +79,12 @@ pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect) state.timebase.tempo() % 1000, ) ].iter() { - buf.set_string(area.x + x, area.y + 2, button, label); + buf.set_string(area.x + x, area.y + 1, button, label); x = x + button.len() as u16 + 1; buf.set_string(area.x + x, area.y + 1, "│", border); - buf.set_string(area.x + x, area.y + 2, "│", border); - buf.set_string(area.x + x, area.y + 3, "│", border); x = x + 2; } + Ok(area) //buf.set_string(area.x, area.y + 5, "Witty Gerbil - Sha Na Na", label.bold()); //&format!(" │ 00:00.00 / 00:00.00"), style); //draw_leaf(buf, area, 1, 0, "REC"); @@ -171,7 +170,6 @@ pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect) //None => String::from("(none)") //}).render(area.clone().offset(Offset { x: 50, y: 2 }), buf); //} - Ok(area) } //pub fn render ( diff --git a/src/layout.rs b/src/layout.rs index 98303869..88f0c89e 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -18,11 +18,12 @@ fn handle_focus ( event: &AppEvent, keymap: &[KeyBinding] ) -> Usually { - return Ok(if let Some(focused) = state.focused_mut() { + let handled = if let Some(focused) = state.focused_mut() { focused.handle(event) } else { Ok(false) - }? || handle_keymap( + }; + return Ok(handled? || handle_keymap( state, event, keymap )?) } @@ -154,18 +155,17 @@ impl Device for Rows { width: area.width, height: area.height - h })?; - if !self.focused && i == self.focus { - draw_box_styled(buf, result, Some(Style::default().green().dim().bold())); + if i == self.focus { + draw_box_styled(buf, result, Some(if true || self.focused { + Style::default().green() + } else { + Style::default() + })); } w = w.max(result.width); h = h + result.height; } - Ok(Rect { - x: area.x, - y: area.y, - width: w, - height: h - }) + Ok(Rect { x: area.x, y: area.y, width: w, height: h }) } } @@ -193,17 +193,16 @@ impl Device for Columns { width: area.width - w, height: area.height })?; - if !self.focused && i == self.focus { - draw_box_styled(buf, result, Some(Style::default().green())); + if i == self.focus { + draw_box_styled(buf, result, Some(if true || self.focused { + Style::default().green() + } else { + Style::default() + })); } w = w + result.width; h = h.max(result.height); } - Ok(Rect { - x: area.x, - y: area.y, - width: w, - height: h - }) + Ok(Rect { x: area.x, y: area.y, width: w, height: h }) } } diff --git a/src/main.rs b/src/main.rs index 10d744b8..5bf6d392 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ fn main () -> Result<(), Box> { //crate::device::run(Sequencer::new("Rhythm#000")?) let transport = Transport::new("Transport")?; let timebase = transport.state.lock().unwrap().timebase(); - crate::device::run(Rows::new(false, vec![ + crate::device::run(Rows::new(true, vec![ Box::new(transport), Box::new(Columns::new(false, vec![ Box::new(Chain::new("Chain#0000", vec![