Skip to content

Commit

Permalink
Bump Ratatui to 0.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun authored and junkdog committed Aug 15, 2024
1 parent bcae156 commit b4f7ec4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
6 changes: 3 additions & 3 deletions examples/basic-effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ fn ui(
let screen_bg: Color = Dark0Hard.into();
let bg: Color = Dark0Soft.into();

Clear.render(f.size(), f.buffer_mut());
Clear.render(f.area(), f.buffer_mut());
Block::default()
.style(Style::default().bg(screen_bg))
.render(f.size(), f.buffer_mut());
.render(f.area(), f.buffer_mut());

let content_area = f.size().inner_centered(80, 17);
let content_area = f.area().inner_centered(80, 17);
Block::default()
.style(Style::default().bg(bg))
.render(content_area, f.buffer_mut());
Expand Down
6 changes: 3 additions & 3 deletions examples/open-window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ fn ui(
f: &mut Frame,
app: &mut App,
) {
if f.size().height == 0 { return; }
if f.area().height == 0 { return; }

Clear.render(f.size(), f.buffer_mut());
Clear.render(f.area(), f.buffer_mut());

let area = Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
.split(f.size());
.split(f.area());

let mut popup_area_l = area[0].inner_centered(45, 7);
popup_area_l.y = area[0].height / 2;
Expand Down
28 changes: 15 additions & 13 deletions examples/tweens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ fn ui(
f: &mut Frame,
app: &mut App,
) {
if f.size().height == 0 { return; }
if f.area().height == 0 { return; }

Clear.render(f.size(), f.buffer_mut());
Clear.render(f.area(), f.buffer_mut());
Block::default()
.style(Style::default().fg(Light2.into()).bg(Dark0.into()))
.render(f.size(), f.buffer_mut());
.render(f.area(), f.buffer_mut());

let layout = Layout::vertical(
vec![
Constraint::Min(2),
Constraint::Percentage(100),
]
).split(f.size());
).split(f.area());

render_shortcuts(app, f, layout[0]);

Expand Down Expand Up @@ -359,14 +359,16 @@ impl StatefulWidget for InterpolationWidget {
]
).split(area);

let axis_x = Axis::default()
.title("x")
.bounds([0.0, 1.0])
.labels(vec!["0.0".into(), "0.5".into(), "1.0".into()]);
let axis_y = Axis::default()
.title("y")
.bounds([-0.2, 1.2])
.labels(vec!["-0.2".into(), "0.5".into(), "1.2".into()]);
let axis_x = Axis::default().title("x").bounds([0.0, 1.0]).labels([
Line::from("0.0"),
Line::from("0.5"),
Line::from("1.0"),
]);
let axis_y = Axis::default().title("y").bounds([-0.2, 1.2]).labels([
Line::from("-0.2"),
Line::from("0.5"),
Line::from("1.2"),
]);

let chart = Chart::new(state.dataset())
.x_axis(axis_x)
Expand Down Expand Up @@ -425,4 +427,4 @@ fn idx_to_tween(idx: usize) -> Interpolation {
}

const TWEENS: usize = 32;
const LAST_TWEEN_IDX: usize = TWEENS -1;
const LAST_TWEEN_IDX: usize = TWEENS -1;
17 changes: 12 additions & 5 deletions src/buffer_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ratatui::buffer::Buffer;
use ratatui::layout::{Offset, Position};
use std::cell::RefCell;
use std::rc::Rc;
use ratatui::buffer::Buffer;
use ratatui::layout::Offset;

/// A trait for rendering the contents of one buffer onto another.
///
Expand Down Expand Up @@ -77,10 +77,17 @@ pub fn blit_buffer(
return;
}

for y in l_clip_y..(aux_area.height - r_clip_y) {
for y in l_clip_y..(aux_area.height - r_clip_y) {
for x in l_clip_x..(aux_area.width - r_clip_x) {
let c = dst.get_mut(x + aux_area.x - l_clip_x, y + aux_area.y - l_clip_y);
*c = src.get(x, y).clone();
if let (Some(c), Some(new_c)) = (
dst.cell_mut(Position::new(
x + aux_area.x - l_clip_x,
y + aux_area.y - l_clip_y,
)),
src.cell(Position::new(x, y)),
) {
*c = new_c.clone();
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/cell_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ impl<'a> CellIterator<'a> {
) -> Self {
Self { current: 0, area, buf, filter }
}
fn cell_mut(&mut self) -> (Position, &mut Cell) {

fn cell_mut(&mut self) -> Option<(Position, &mut Cell)> {
let x = self.current % self.area.width;
let y = self.current / self.area.width;

let pos = Position::new(self.area.x + x, self.area.y + y);
let cell = self.buf.get_mut(pos.x, pos.y);
(pos, cell)
let cell = self.buf.cell_mut(Position::new(pos.x, pos.y))?;
Some((pos, cell))
}
}

Expand All @@ -34,7 +34,7 @@ impl<'a> Iterator for CellIterator<'a> {
fn next(&mut self) -> Option<Self::Item> {
let selector = self.filter.as_ref().map(|f| f.selector(self.area));
while self.current < self.area.area() {
let (pos, cell) = self.cell_mut();
let (pos, cell) = self.cell_mut()?;
// enforce cell's lifetime. this is safe because `buf` is guaranteed to outlive `'a`
let cell: &'a mut Cell = unsafe { std::mem::transmute(cell) };
self.current += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/fx/ansi256.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::layout::{Position, Rect};

use crate::CellIterator;
use crate::color_ext::AsIndexedColor;
Expand All @@ -26,7 +26,7 @@ impl Shader for Ansi256 {

for y in area.top()..area.bottom() {
for x in area.left()..area.right() {
let cell = buf.get_mut(x, y);
let cell = buf.cell_mut(Position::new(x, y))?;
let fg = fg_mapper.map(cell.fg, 0.0, |c| c.as_indexed_color());
let bg = bg_mapper.map(cell.bg, 0.0, |c| c.as_indexed_color());

Expand Down
2 changes: 1 addition & 1 deletion src/fx/glitch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Shader for Glitch {
let x = cell.cell_idx % area.width as usize;
let y = cell.cell_idx / area.width as usize;
let pos = Position::new(area.x + x as u16, area.y + y as u16);
let c = buf.get_mut(area.x + x as u16, area.y + y as u16);
let c = buf.cell_mut(Position::new(area.x + x as u16, area.y + y as u16)).unwrap();

if !selector.is_valid(pos, c) {
return;
Expand Down

0 comments on commit b4f7ec4

Please sign in to comment.