Skip to content

Commit 9df1a40

Browse files
committed
docs: more fixes
1 parent 5336704 commit 9df1a40

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

examples/demo/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
let terminal = ratatui::init();
2+
let _ = ratatui::init();
33

44
ratatui::restore();
55
}

src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ use crate::wgpu_context::WgpuContext;
4242
///
4343
/// ```rust,no_run
4444
/// let mut terminal = ratatui::init();
45-
/// let mut state = tui_shader::ShaderCanvasState:default();
45+
/// let mut state = tui_shader::ShaderCanvasState::default();
4646
/// terminal.draw(|frame| {
47-
/// frame.render_stateful_widget(ShaderCanvas, frame.area(), &mut state);
48-
/// }
47+
/// frame.render_stateful_widget(tui_shader::ShaderCanvas, frame.area(), &mut state);
48+
/// }).unwrap();
4949
/// ratatui::restore();
5050
/// ```
5151
pub struct ShaderCanvas;
@@ -61,17 +61,18 @@ impl StatefulWidget for ShaderCanvas {
6161
for y in 0..height {
6262
for x in 0..width {
6363
let index = (y * (width + WgpuContext::row_padding(width)) + x) as usize;
64-
let pixel = raw_buffer[index];
64+
let value = raw_buffer[index];
65+
let position = (x, y);
6566
let character = match state.options.character_rule {
6667
CharacterRule::Always(character) => character,
67-
CharacterRule::Map(map) => map(pixel.into()),
68+
CharacterRule::Map(map) => map(Sample::new(value, position)),
6869
};
69-
let color = Color::Rgb(pixel[0], pixel[1], pixel[2]);
70+
let color = Color::Rgb(value[0], value[1], value[2]);
7071
let style = match state.options.style_rule {
7172
StyleRule::ColorFg => Style::new().fg(color),
7273
StyleRule::ColorBg => Style::new().bg(color),
7374
StyleRule::ColorFgAndBg => Style::new().fg(color).bg(color),
74-
StyleRule::Map(map) => map(pixel.into()),
75+
StyleRule::Map(map) => map(Sample::new(value, position)),
7576
};
7677
let cell = buf.cell_mut(Position::new(x, y)).unwrap();
7778
cell.set_style(style);
@@ -104,8 +105,8 @@ impl ShaderCanvasState {
104105
/// ```rust,no_run
105106
/// let state = tui_shader::ShaderCanvasState::new_with_options("path/to/shader.wgsl",
106107
/// tui_shader::ShaderCanvasOptions {
107-
/// style_rule: StyleRule::Fg,
108-
/// entry_point: "fragment",
108+
/// style_rule: tui_shader::StyleRule::ColorFg,
109+
/// entry_point: String::from("fragment"),
109110
/// ..Default::default()
110111
/// }
111112
/// );
@@ -169,6 +170,10 @@ pub struct Sample {
169170
}
170171

171172
impl Sample {
173+
fn new(value: [u8; 4], position: (u16, u16)) -> Self {
174+
Self { value, position }
175+
}
176+
172177
pub fn r(&self) -> u8 {
173178
self.value[0]
174179
}

0 commit comments

Comments
 (0)