mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
docs: use Frame::area()
instead of size()
in examples (#1361)
`Frame::size()` is deprecated
This commit is contained in:
parent
da821b431e
commit
870bc6a64a
10 changed files with 26 additions and 22 deletions
18
README.md
18
README.md
|
@ -4,14 +4,18 @@
|
||||||
- [Ratatui](#ratatui)
|
- [Ratatui](#ratatui)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Introduction](#introduction)
|
- [Introduction](#introduction)
|
||||||
- [Other Documentation](#other-documentation)
|
- [Other documentation](#other-documentation)
|
||||||
- [Quickstart](#quickstart)
|
- [Quickstart](#quickstart)
|
||||||
|
- [Initialize and restore the terminal](#initialize-and-restore-the-terminal)
|
||||||
|
- [Drawing the UI](#drawing-the-ui)
|
||||||
|
- [Handling events](#handling-events)
|
||||||
|
- [Example](#example)
|
||||||
|
- [Layout](#layout)
|
||||||
|
- [Text and styling](#text-and-styling)
|
||||||
- [Status of this fork](#status-of-this-fork)
|
- [Status of this fork](#status-of-this-fork)
|
||||||
- [Rust version requirements](#rust-version-requirements)
|
|
||||||
- [Widgets](#widgets)
|
- [Widgets](#widgets)
|
||||||
- [Built in](#built-in)
|
- [Built in](#built-in)
|
||||||
- [Third\-party libraries, bootstrapping templates and
|
- [Third-party libraries, bootstrapping templates and widgets](#third-party-libraries-bootstrapping-templates-and-widgets)
|
||||||
widgets](#third-party-libraries-bootstrapping-templates-and-widgets)
|
|
||||||
- [Apps](#apps)
|
- [Apps](#apps)
|
||||||
- [Alternatives](#alternatives)
|
- [Alternatives](#alternatives)
|
||||||
- [Acknowledgments](#acknowledgments)
|
- [Acknowledgments](#acknowledgments)
|
||||||
|
@ -170,7 +174,7 @@ fn handle_events() -> io::Result<bool> {
|
||||||
fn ui(frame: &mut Frame) {
|
fn ui(frame: &mut Frame) {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new("Hello World!").block(Block::bordered().title("Greeting")),
|
Paragraph::new("Hello World!").block(Block::bordered().title("Greeting")),
|
||||||
frame.size(),
|
frame.area(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -199,7 +203,7 @@ fn ui(frame: &mut Frame) {
|
||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
])
|
])
|
||||||
.areas(frame.size());
|
.areas(frame.area());
|
||||||
let [left_area, right_area] =
|
let [left_area, right_area] =
|
||||||
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
.areas(main_area);
|
.areas(main_area);
|
||||||
|
@ -237,7 +241,7 @@ use ratatui::{
|
||||||
};
|
};
|
||||||
|
|
||||||
fn ui(frame: &mut Frame) {
|
fn ui(frame: &mut Frame) {
|
||||||
let areas = Layout::vertical([Constraint::Length(1); 4]).split(frame.size());
|
let areas = Layout::vertical([Constraint::Length(1); 4]).split(frame.area());
|
||||||
|
|
||||||
let line = Line::from(vec![
|
let line = Line::from(vec![
|
||||||
Span::raw("Hello "),
|
Span::raw("Hello "),
|
||||||
|
|
|
@ -428,7 +428,7 @@ impl Layout {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use ratatui::prelude::*;
|
/// # use ratatui::prelude::*;
|
||||||
/// # fn render(frame: &mut Frame) {
|
/// # fn render(frame: &mut Frame) {
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// let layout = Layout::vertical([Constraint::Length(1), Constraint::Min(0)]);
|
/// let layout = Layout::vertical([Constraint::Length(1), Constraint::Min(0)]);
|
||||||
/// let [top, main] = layout.areas(area);
|
/// let [top, main] = layout.areas(area);
|
||||||
///
|
///
|
||||||
|
@ -460,7 +460,7 @@ impl Layout {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use ratatui::prelude::*;
|
/// # use ratatui::prelude::*;
|
||||||
/// # fn render(frame: &mut Frame) {
|
/// # fn render(frame: &mut Frame) {
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// let layout = Layout::vertical([Constraint::Length(1), Constraint::Min(0)]);
|
/// let layout = Layout::vertical([Constraint::Length(1), Constraint::Min(0)]);
|
||||||
/// let [top, main] = layout.areas(area);
|
/// let [top, main] = layout.areas(area);
|
||||||
/// let [before, inbetween, after] = layout.spacers(area);
|
/// let [before, inbetween, after] = layout.spacers(area);
|
||||||
|
|
|
@ -236,7 +236,7 @@ impl Rect {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use ratatui::prelude::*;
|
/// # use ratatui::prelude::*;
|
||||||
/// # fn render(frame: &mut Frame) {
|
/// # fn render(frame: &mut Frame) {
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// let rect = Rect::new(0, 0, 100, 100).clamp(area);
|
/// let rect = Rect::new(0, 0, 100, 100).clamp(area);
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -151,7 +151,7 @@
|
||||||
//! Constraint::Min(0),
|
//! Constraint::Min(0),
|
||||||
//! Constraint::Length(1),
|
//! Constraint::Length(1),
|
||||||
//! ])
|
//! ])
|
||||||
//! .areas(frame.size());
|
//! .areas(frame.area());
|
||||||
//! let [left_area, right_area] =
|
//! let [left_area, right_area] =
|
||||||
//! Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
//! Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
//! .areas(main_area);
|
//! .areas(main_area);
|
||||||
|
@ -189,7 +189,7 @@
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! fn draw(frame: &mut Frame) {
|
//! fn draw(frame: &mut Frame) {
|
||||||
//! let areas = Layout::vertical([Constraint::Length(1); 4]).split(frame.size());
|
//! let areas = Layout::vertical([Constraint::Length(1); 4]).split(frame.area());
|
||||||
//!
|
//!
|
||||||
//! let line = Line::from(vec![
|
//! let line = Line::from(vec![
|
||||||
//! Span::raw("Hello "),
|
//! Span::raw("Hello "),
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
//! let backend = CrosstermBackend::new(stdout());
|
//! let backend = CrosstermBackend::new(stdout());
|
||||||
//! let mut terminal = Terminal::new(backend)?;
|
//! let mut terminal = Terminal::new(backend)?;
|
||||||
//! terminal.draw(|frame| {
|
//! terminal.draw(|frame| {
|
||||||
//! let area = frame.size();
|
//! let area = frame.area();
|
||||||
//! frame.render_widget(Paragraph::new("Hello world!"), area);
|
//! frame.render_widget(Paragraph::new("Hello world!"), area);
|
||||||
//! })?;
|
//! })?;
|
||||||
//! # std::io::Result::Ok(())
|
//! # std::io::Result::Ok(())
|
||||||
|
|
|
@ -38,7 +38,7 @@ use crate::{
|
||||||
/// let backend = CrosstermBackend::new(stdout());
|
/// let backend = CrosstermBackend::new(stdout());
|
||||||
/// let mut terminal = Terminal::new(backend)?;
|
/// let mut terminal = Terminal::new(backend)?;
|
||||||
/// terminal.draw(|frame| {
|
/// terminal.draw(|frame| {
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// frame.render_widget(Paragraph::new("Hello World!"), area);
|
/// frame.render_widget(Paragraph::new("Hello World!"), area);
|
||||||
/// })?;
|
/// })?;
|
||||||
/// # std::io::Result::Ok(())
|
/// # std::io::Result::Ok(())
|
||||||
|
@ -283,7 +283,7 @@ where
|
||||||
///
|
///
|
||||||
/// // with a closure
|
/// // with a closure
|
||||||
/// terminal.draw(|frame| {
|
/// terminal.draw(|frame| {
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// frame.render_widget(Paragraph::new("Hello World!"), area);
|
/// frame.render_widget(Paragraph::new("Hello World!"), area);
|
||||||
/// frame.set_cursor_position(Position { x: 0, y: 0 });
|
/// frame.set_cursor_position(Position { x: 0, y: 0 });
|
||||||
/// })?;
|
/// })?;
|
||||||
|
@ -292,7 +292,7 @@ where
|
||||||
/// terminal.draw(render)?;
|
/// terminal.draw(render)?;
|
||||||
///
|
///
|
||||||
/// fn render(frame: &mut ratatui::Frame) {
|
/// fn render(frame: &mut ratatui::Frame) {
|
||||||
/// frame.render_widget(Paragraph::new("Hello World!"), frame.size());
|
/// frame.render_widget(Paragraph::new("Hello World!"), frame.area());
|
||||||
/// }
|
/// }
|
||||||
/// # std::io::Result::Ok(())
|
/// # std::io::Result::Ok(())
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -355,7 +355,7 @@ where
|
||||||
/// // with a closure
|
/// // with a closure
|
||||||
/// terminal.try_draw(|frame| {
|
/// terminal.try_draw(|frame| {
|
||||||
/// let value: u8 = "not a number".parse().map_err(io::Error::other)?;
|
/// let value: u8 = "not a number".parse().map_err(io::Error::other)?;
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// frame.render_widget(Paragraph::new("Hello World!"), area);
|
/// frame.render_widget(Paragraph::new("Hello World!"), area);
|
||||||
/// frame.set_cursor_position(Position { x: 0, y: 0 });
|
/// frame.set_cursor_position(Position { x: 0, y: 0 });
|
||||||
/// io::Result::Ok(())
|
/// io::Result::Ok(())
|
||||||
|
@ -366,7 +366,7 @@ where
|
||||||
///
|
///
|
||||||
/// fn render(frame: &mut ratatui::Frame) -> io::Result<()> {
|
/// fn render(frame: &mut ratatui::Frame) -> io::Result<()> {
|
||||||
/// let value: u8 = "not a number".parse().map_err(io::Error::other)?;
|
/// let value: u8 = "not a number".parse().map_err(io::Error::other)?;
|
||||||
/// frame.render_widget(Paragraph::new("Hello World!"), frame.size());
|
/// frame.render_widget(Paragraph::new("Hello World!"), frame.area());
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// # io::Result::Ok(())
|
/// # io::Result::Ok(())
|
||||||
|
|
|
@ -81,7 +81,7 @@ use crate::{prelude::*, style::Styled, text::StyledGrapheme};
|
||||||
/// use ratatui::prelude::*;
|
/// use ratatui::prelude::*;
|
||||||
///
|
///
|
||||||
/// # fn render_frame(frame: &mut Frame) {
|
/// # fn render_frame(frame: &mut Frame) {
|
||||||
/// frame.render_widget("test content".green().on_yellow().italic(), frame.size());
|
/// frame.render_widget("test content".green().on_yellow().italic(), frame.area());
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
/// [`Line`]: crate::text::Line
|
/// [`Line`]: crate::text::Line
|
||||||
|
|
|
@ -88,7 +88,7 @@ use crate::{buffer::Buffer, layout::Rect, style::Style};
|
||||||
/// # let mut terminal = Terminal::new(backend).unwrap();
|
/// # let mut terminal = Terminal::new(backend).unwrap();
|
||||||
///
|
///
|
||||||
/// terminal.draw(|frame| {
|
/// terminal.draw(|frame| {
|
||||||
/// frame.render_widget(Clear, frame.size());
|
/// frame.render_widget(Clear, frame.area());
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
|
|
@ -595,7 +595,7 @@ impl<'a> Block<'a> {
|
||||||
/// let outer_block = Block::bordered().title("Outer");
|
/// let outer_block = Block::bordered().title("Outer");
|
||||||
/// let inner_block = Block::bordered().title("Inner");
|
/// let inner_block = Block::bordered().title("Inner");
|
||||||
///
|
///
|
||||||
/// let outer_area = frame.size();
|
/// let outer_area = frame.area();
|
||||||
/// let inner_area = outer_block.inner(outer_area);
|
/// let inner_area = outer_block.inner(outer_area);
|
||||||
///
|
///
|
||||||
/// frame.render_widget(outer_block, outer_area);
|
/// frame.render_widget(outer_block, outer_area);
|
||||||
|
|
|
@ -59,7 +59,7 @@ use crate::{
|
||||||
///
|
///
|
||||||
/// let mut scrollbar_state = ScrollbarState::new(items.len()).position(vertical_scroll);
|
/// let mut scrollbar_state = ScrollbarState::new(items.len()).position(vertical_scroll);
|
||||||
///
|
///
|
||||||
/// let area = frame.size();
|
/// let area = frame.area();
|
||||||
/// // Note we render the paragraph
|
/// // Note we render the paragraph
|
||||||
/// frame.render_widget(paragraph, area);
|
/// frame.render_widget(paragraph, area);
|
||||||
/// // and the scrollbar, those are separate widgets
|
/// // and the scrollbar, those are separate widgets
|
||||||
|
|
Loading…
Reference in a new issue