mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-21 20:23:11 +00:00
perf: clippy::missing_const_for_fn (#974)
This commit is contained in:
parent
27680c05ce
commit
3834374652
25 changed files with 71 additions and 65 deletions
|
@ -65,6 +65,7 @@ serde_json = "1.0.109"
|
||||||
unsafe_code = "forbid"
|
unsafe_code = "forbid"
|
||||||
[lints.clippy]
|
[lints.clippy]
|
||||||
explicit_iter_loop = "warn"
|
explicit_iter_loop = "warn"
|
||||||
|
missing_const_for_fn = "warn"
|
||||||
needless_for_each = "warn"
|
needless_for_each = "warn"
|
||||||
semicolon_if_nothing_returned = "warn"
|
semicolon_if_nothing_returned = "warn"
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ where
|
||||||
/// # use ratatui::prelude::*;
|
/// # use ratatui::prelude::*;
|
||||||
/// let backend = CrosstermBackend::new(stdout());
|
/// let backend = CrosstermBackend::new(stdout());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(writer: W) -> CrosstermBackend<W> {
|
pub const fn new(writer: W) -> CrosstermBackend<W> {
|
||||||
CrosstermBackend { writer }
|
CrosstermBackend { writer }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ where
|
||||||
/// # use ratatui::prelude::*;
|
/// # use ratatui::prelude::*;
|
||||||
/// let backend = TermionBackend::new(stdout());
|
/// let backend = TermionBackend::new(stdout());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(writer: W) -> TermionBackend<W> {
|
pub const fn new(writer: W) -> TermionBackend<W> {
|
||||||
TermionBackend { writer }
|
TermionBackend { writer }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,14 +93,16 @@ impl TermwizBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new Termwiz backend instance with the given buffered terminal.
|
/// Creates a new Termwiz backend instance with the given buffered terminal.
|
||||||
pub fn with_buffered_terminal(instance: BufferedTerminal<SystemTerminal>) -> TermwizBackend {
|
pub const fn with_buffered_terminal(
|
||||||
|
instance: BufferedTerminal<SystemTerminal>,
|
||||||
|
) -> TermwizBackend {
|
||||||
TermwizBackend {
|
TermwizBackend {
|
||||||
buffered_terminal: instance,
|
buffered_terminal: instance,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to the buffered terminal used by the backend.
|
/// Returns a reference to the buffered terminal used by the backend.
|
||||||
pub fn buffered_terminal(&self) -> &BufferedTerminal<SystemTerminal> {
|
pub const fn buffered_terminal(&self) -> &BufferedTerminal<SystemTerminal> {
|
||||||
&self.buffered_terminal
|
&self.buffered_terminal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl TestBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to the internal buffer of the TestBackend.
|
/// Returns a reference to the internal buffer of the TestBackend.
|
||||||
pub fn buffer(&self) -> &Buffer {
|
pub const fn buffer(&self) -> &Buffer {
|
||||||
&self.buffer
|
&self.buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the area covered by this buffer
|
/// Returns the area covered by this buffer
|
||||||
pub fn area(&self) -> &Rect {
|
pub const fn area(&self) -> &Rect {
|
||||||
&self.area
|
&self.area
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl Frame<'_> {
|
||||||
/// If your app listens for a resize event from the backend, it should ignore the values from
|
/// If your app listens for a resize event from the backend, it should ignore the values from
|
||||||
/// the event for any calculations that are used to render the current frame and use this value
|
/// the event for any calculations that are used to render the current frame and use this value
|
||||||
/// instead as this is the size of the buffer that is used to render the current frame.
|
/// instead as this is the size of the buffer that is used to render the current frame.
|
||||||
pub fn size(&self) -> Rect {
|
pub const fn size(&self) -> Rect {
|
||||||
self.viewport_area
|
self.viewport_area
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ impl Frame<'_> {
|
||||||
/// let current_count = frame.count();
|
/// let current_count = frame.count();
|
||||||
/// println!("Current frame count: {}", current_count);
|
/// println!("Current frame count: {}", current_count);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn count(&self) -> usize {
|
pub const fn count(&self) -> usize {
|
||||||
self.count
|
self.count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the backend
|
/// Gets the backend
|
||||||
pub fn backend(&self) -> &B {
|
pub const fn backend(&self) -> &B {
|
||||||
&self.backend
|
&self.backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl<'a> Masked<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The character to use for masking.
|
/// The character to use for masking.
|
||||||
pub fn mask_char(&self) -> char {
|
pub const fn mask_char(&self) -> char {
|
||||||
self.mask_char
|
self.mask_char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ impl<'a> BarChart<'a> {
|
||||||
/// // f b b
|
/// // f b b
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn max(mut self, max: u64) -> BarChart<'a> {
|
pub const fn max(mut self, max: u64) -> BarChart<'a> {
|
||||||
self.max = Some(max);
|
self.max = Some(max);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ impl<'a> BarChart<'a> {
|
||||||
/// // f b
|
/// // f b
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn bar_gap(mut self, gap: u16) -> BarChart<'a> {
|
pub const fn bar_gap(mut self, gap: u16) -> BarChart<'a> {
|
||||||
self.bar_gap = gap;
|
self.bar_gap = gap;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ impl<'a> BarChart<'a> {
|
||||||
///
|
///
|
||||||
/// If not set, the default is [`bar::NINE_LEVELS`](crate::symbols::bar::NINE_LEVELS).
|
/// If not set, the default is [`bar::NINE_LEVELS`](crate::symbols::bar::NINE_LEVELS).
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn bar_set(mut self, bar_set: symbols::bar::Set) -> BarChart<'a> {
|
pub const fn bar_set(mut self, bar_set: symbols::bar::Set) -> BarChart<'a> {
|
||||||
self.bar_set = bar_set;
|
self.bar_set = bar_set;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ impl<'a> BarChart<'a> {
|
||||||
|
|
||||||
/// Set the gap between [`BarGroup`].
|
/// Set the gap between [`BarGroup`].
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn group_gap(mut self, gap: u16) -> BarChart<'a> {
|
pub const fn group_gap(mut self, gap: u16) -> BarChart<'a> {
|
||||||
self.group_gap = gap;
|
self.group_gap = gap;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ impl<'a> BarChart<'a> {
|
||||||
/// █bar██
|
/// █bar██
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn direction(mut self, direction: Direction) -> BarChart<'a> {
|
pub const fn direction(mut self, direction: Direction) -> BarChart<'a> {
|
||||||
self.direction = direction;
|
self.direction = direction;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl<'a> Bar<'a> {
|
||||||
/// [`Bar::value_style`] to style the value.
|
/// [`Bar::value_style`] to style the value.
|
||||||
/// [`Bar::text_value`] to set the displayed value.
|
/// [`Bar::text_value`] to set the displayed value.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn value(mut self, value: u64) -> Bar<'a> {
|
pub const fn value(mut self, value: u64) -> Bar<'a> {
|
||||||
self.value = value;
|
self.value = value;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -1107,7 +1107,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn border_type_can_be_const() {
|
const fn border_type_can_be_const() {
|
||||||
const _PLAIN: border::Set = BorderType::border_symbols(BorderType::Plain);
|
const _PLAIN: border::Set = BorderType::border_symbols(BorderType::Plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1130,7 +1130,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_can_be_const() {
|
const fn block_can_be_const() {
|
||||||
const _DEFAULT_STYLE: Style = Style::new();
|
const _DEFAULT_STYLE: Style = Style::new();
|
||||||
const _DEFAULT_PADDING: Padding = Padding::uniform(1);
|
const _DEFAULT_PADDING: Padding = Padding::uniform(1);
|
||||||
const _DEFAULT_BLOCK: Block = Block::new()
|
const _DEFAULT_BLOCK: Block = Block::new()
|
||||||
|
|
|
@ -186,7 +186,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_be_const() {
|
const fn can_be_const() {
|
||||||
const _PADDING: Padding = Padding::new(1, 1, 1, 1);
|
const _PADDING: Padding = Padding::new(1, 1, 1, 1);
|
||||||
const _UNI_PADDING: Padding = Padding::uniform(1);
|
const _UNI_PADDING: Padding = Padding::uniform(1);
|
||||||
const _NO_PADDING: Padding = Padding::zero();
|
const _NO_PADDING: Padding = Padding::zero();
|
||||||
|
|
|
@ -97,14 +97,14 @@ impl<'a> Title<'a> {
|
||||||
|
|
||||||
/// Set the title alignment.
|
/// Set the title alignment.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn alignment(mut self, alignment: Alignment) -> Title<'a> {
|
pub const fn alignment(mut self, alignment: Alignment) -> Title<'a> {
|
||||||
self.alignment = Some(alignment);
|
self.alignment = Some(alignment);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the title position.
|
/// Set the title position.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn position(mut self, position: Position) -> Title<'a> {
|
pub const fn position(mut self, position: Position) -> Title<'a> {
|
||||||
self.position = Some(position);
|
self.position = Some(position);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,7 +671,7 @@ where
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn x_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> {
|
pub const fn x_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> {
|
||||||
self.x_bounds = bounds;
|
self.x_bounds = bounds;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -683,7 +683,7 @@ where
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn y_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> {
|
pub const fn y_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> {
|
||||||
self.y_bounds = bounds;
|
self.y_bounds = bounds;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -701,7 +701,7 @@ where
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn background_color(mut self, color: Color) -> Canvas<'a, F> {
|
pub const fn background_color(mut self, color: Color) -> Canvas<'a, F> {
|
||||||
self.background_color = color;
|
self.background_color = color;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -744,7 +744,7 @@ where
|
||||||
/// .marker(symbols::Marker::Block)
|
/// .marker(symbols::Marker::Block)
|
||||||
/// .paint(|ctx| {});
|
/// .paint(|ctx| {});
|
||||||
/// ```
|
/// ```
|
||||||
pub fn marker(mut self, marker: symbols::Marker) -> Canvas<'a, F> {
|
pub const fn marker(mut self, marker: symbols::Marker) -> Canvas<'a, F> {
|
||||||
self.marker = marker;
|
self.marker = marker;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl<'a> Axis<'a> {
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn bounds(mut self, bounds: [f64; 2]) -> Axis<'a> {
|
pub const fn bounds(mut self, bounds: [f64; 2]) -> Axis<'a> {
|
||||||
self.bounds = bounds;
|
self.bounds = bounds;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ impl<'a> Axis<'a> {
|
||||||
///
|
///
|
||||||
/// On the X axis, this parameter only affects the first label.
|
/// On the X axis, this parameter only affects the first label.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn labels_alignment(mut self, alignment: Alignment) -> Axis<'a> {
|
pub const fn labels_alignment(mut self, alignment: Alignment) -> Axis<'a> {
|
||||||
self.labels_alignment = alignment;
|
self.labels_alignment = alignment;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ impl<'a> Dataset<'a> {
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn data(mut self, data: &'a [(f64, f64)]) -> Dataset<'a> {
|
pub const fn data(mut self, data: &'a [(f64, f64)]) -> Dataset<'a> {
|
||||||
self.data = data;
|
self.data = data;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ impl<'a> Dataset<'a> {
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn marker(mut self, marker: symbols::Marker) -> Dataset<'a> {
|
pub const fn marker(mut self, marker: symbols::Marker) -> Dataset<'a> {
|
||||||
self.marker = marker;
|
self.marker = marker;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ impl<'a> Dataset<'a> {
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn graph_type(mut self, graph_type: GraphType) -> Dataset<'a> {
|
pub const fn graph_type(mut self, graph_type: GraphType) -> Dataset<'a> {
|
||||||
self.graph_type = graph_type;
|
self.graph_type = graph_type;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,10 @@ impl<'a> Chart<'a> {
|
||||||
/// let chart = Chart::new(vec![]).hidden_legend_constraints(constraints);
|
/// let chart = Chart::new(vec![]).hidden_legend_constraints(constraints);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn hidden_legend_constraints(mut self, constraints: (Constraint, Constraint)) -> Chart<'a> {
|
pub const fn hidden_legend_constraints(
|
||||||
|
mut self,
|
||||||
|
constraints: (Constraint, Constraint),
|
||||||
|
) -> Chart<'a> {
|
||||||
self.hidden_legend_constraints = constraints;
|
self.hidden_legend_constraints = constraints;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -683,7 +686,7 @@ impl<'a> Chart<'a> {
|
||||||
/// let chart = Chart::new(vec![]).legend_position(None);
|
/// let chart = Chart::new(vec![]).legend_position(None);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn legend_position(mut self, position: Option<LegendPosition>) -> Chart<'a> {
|
pub const fn legend_position(mut self, position: Option<LegendPosition>) -> Chart<'a> {
|
||||||
self.legend_position = position;
|
self.legend_position = position;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl<'a> Gauge<'a> {
|
||||||
/// [unicode block characters](https://en.wikipedia.org/wiki/Block_Elements).
|
/// [unicode block characters](https://en.wikipedia.org/wiki/Block_Elements).
|
||||||
/// This is useful to display a higher precision bar (8 extra fractional parts per cell).
|
/// This is useful to display a higher precision bar (8 extra fractional parts per cell).
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn use_unicode(mut self, unicode: bool) -> Gauge<'a> {
|
pub const fn use_unicode(mut self, unicode: bool) -> Gauge<'a> {
|
||||||
self.use_unicode = unicode;
|
self.use_unicode = unicode;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ impl<'a> LineGauge<'a> {
|
||||||
/// [`NORMAL`](symbols::line::NORMAL), [`DOUBLE`](symbols::line::DOUBLE) and
|
/// [`NORMAL`](symbols::line::NORMAL), [`DOUBLE`](symbols::line::DOUBLE) and
|
||||||
/// [`THICK`](symbols::line::THICK).
|
/// [`THICK`](symbols::line::THICK).
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn line_set(mut self, set: symbols::line::Set) -> Self {
|
pub const fn line_set(mut self, set: symbols::line::Set) -> Self {
|
||||||
self.line_set = set;
|
self.line_set = set;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl ListState {
|
||||||
/// let state = ListState::default().with_offset(1);
|
/// let state = ListState::default().with_offset(1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn with_offset(mut self, offset: usize) -> Self {
|
pub const fn with_offset(mut self, offset: usize) -> Self {
|
||||||
self.offset = offset;
|
self.offset = offset;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ impl ListState {
|
||||||
/// let state = ListState::default().with_selected(Some(1));
|
/// let state = ListState::default().with_selected(Some(1));
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn with_selected(mut self, selected: Option<usize>) -> Self {
|
pub const fn with_selected(mut self, selected: Option<usize>) -> Self {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ impl ListState {
|
||||||
/// let state = ListState::default();
|
/// let state = ListState::default();
|
||||||
/// assert_eq!(state.offset(), 0);
|
/// assert_eq!(state.offset(), 0);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn offset(&self) -> usize {
|
pub const fn offset(&self) -> usize {
|
||||||
self.offset
|
self.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ impl ListState {
|
||||||
/// let state = TableState::default();
|
/// let state = TableState::default();
|
||||||
/// assert_eq!(state.selected(), None);
|
/// assert_eq!(state.selected(), None);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn selected(&self) -> Option<usize> {
|
pub const fn selected(&self) -> Option<usize> {
|
||||||
self.selected
|
self.selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ impl<'a> List<'a> {
|
||||||
/// let list = List::new(items).highlight_symbol(">>");
|
/// let list = List::new(items).highlight_symbol(">>");
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn highlight_symbol(mut self, highlight_symbol: &'a str) -> List<'a> {
|
pub const fn highlight_symbol(mut self, highlight_symbol: &'a str) -> List<'a> {
|
||||||
self.highlight_symbol = Some(highlight_symbol);
|
self.highlight_symbol = Some(highlight_symbol);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,7 @@ impl<'a> List<'a> {
|
||||||
///
|
///
|
||||||
/// This is a fluent setter method which must be chained or used as it consumes self
|
/// This is a fluent setter method which must be chained or used as it consumes self
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn repeat_highlight_symbol(mut self, repeat: bool) -> List<'a> {
|
pub const fn repeat_highlight_symbol(mut self, repeat: bool) -> List<'a> {
|
||||||
self.repeat_highlight_symbol = repeat;
|
self.repeat_highlight_symbol = repeat;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -660,7 +660,7 @@ impl<'a> List<'a> {
|
||||||
/// let list = List::new(items).highlight_spacing(HighlightSpacing::Always);
|
/// let list = List::new(items).highlight_spacing(HighlightSpacing::Always);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn highlight_spacing(mut self, value: HighlightSpacing) -> Self {
|
pub const fn highlight_spacing(mut self, value: HighlightSpacing) -> Self {
|
||||||
self.highlight_spacing = value;
|
self.highlight_spacing = value;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -682,7 +682,7 @@ impl<'a> List<'a> {
|
||||||
/// let list = List::new(items).direction(ListDirection::BottomToTop);
|
/// let list = List::new(items).direction(ListDirection::BottomToTop);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn direction(mut self, direction: ListDirection) -> List<'a> {
|
pub const fn direction(mut self, direction: ListDirection) -> List<'a> {
|
||||||
self.direction = direction;
|
self.direction = direction;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -701,7 +701,7 @@ impl<'a> List<'a> {
|
||||||
/// let list = List::new(items).scroll_padding(1);
|
/// let list = List::new(items).scroll_padding(1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn scroll_padding(mut self, padding: usize) -> List<'a> {
|
pub const fn scroll_padding(mut self, padding: usize) -> List<'a> {
|
||||||
self.scroll_padding = padding;
|
self.scroll_padding = padding;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
widgets::{reflow::*, Block},
|
widgets::{reflow::*, Block},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) -> u16 {
|
const fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) -> u16 {
|
||||||
match alignment {
|
match alignment {
|
||||||
Alignment::Center => (text_area_width / 2).saturating_sub(line_width / 2),
|
Alignment::Center => (text_area_width / 2).saturating_sub(line_width / 2),
|
||||||
Alignment::Right => text_area_width.saturating_sub(line_width),
|
Alignment::Right => text_area_width.saturating_sub(line_width),
|
||||||
|
@ -167,7 +167,7 @@ impl<'a> Paragraph<'a> {
|
||||||
/// let paragraph = Paragraph::new("Hello, world!").wrap(Wrap { trim: true });
|
/// let paragraph = Paragraph::new("Hello, world!").wrap(Wrap { trim: true });
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn wrap(mut self, wrap: Wrap) -> Paragraph<'a> {
|
pub const fn wrap(mut self, wrap: Wrap) -> Paragraph<'a> {
|
||||||
self.wrap = Some(wrap);
|
self.wrap = Some(wrap);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ impl<'a> Paragraph<'a> {
|
||||||
/// For more information about future scrolling design and concerns, see [RFC: Design of
|
/// For more information about future scrolling design and concerns, see [RFC: Design of
|
||||||
/// Scrollable Widgets](https://github.com/ratatui-org/ratatui/issues/174) on GitHub.
|
/// Scrollable Widgets](https://github.com/ratatui-org/ratatui/issues/174) on GitHub.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn scroll(mut self, offset: (Vertical, Horizontal)) -> Paragraph<'a> {
|
pub const fn scroll(mut self, offset: (Vertical, Horizontal)) -> Paragraph<'a> {
|
||||||
self.scroll = offset;
|
self.scroll = offset;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ impl<'a> Paragraph<'a> {
|
||||||
/// let paragraph = Paragraph::new("Hello World").alignment(Alignment::Center);
|
/// let paragraph = Paragraph::new("Hello World").alignment(Alignment::Center);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn alignment(mut self, alignment: Alignment) -> Paragraph<'a> {
|
pub const fn alignment(mut self, alignment: Alignment) -> Paragraph<'a> {
|
||||||
self.alignment = alignment;
|
self.alignment = alignment;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ impl<'a> Paragraph<'a> {
|
||||||
/// let paragraph = Paragraph::new("Hello World").left_aligned();
|
/// let paragraph = Paragraph::new("Hello World").left_aligned();
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn left_aligned(self) -> Self {
|
pub const fn left_aligned(self) -> Self {
|
||||||
self.alignment(Alignment::Left)
|
self.alignment(Alignment::Left)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ impl<'a> Paragraph<'a> {
|
||||||
/// let paragraph = Paragraph::new("Hello World").centered();
|
/// let paragraph = Paragraph::new("Hello World").centered();
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn centered(self) -> Self {
|
pub const fn centered(self) -> Self {
|
||||||
self.alignment(Alignment::Center)
|
self.alignment(Alignment::Center)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ impl<'a> Paragraph<'a> {
|
||||||
/// let paragraph = Paragraph::new("Hello World").right_aligned();
|
/// let paragraph = Paragraph::new("Hello World").right_aligned();
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn right_aligned(self) -> Self {
|
pub const fn right_aligned(self) -> Self {
|
||||||
self.alignment(Alignment::Right)
|
self.alignment(Alignment::Right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl<'a> Sparkline<'a> {
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn data(mut self, data: &'a [u64]) -> Sparkline<'a> {
|
pub const fn data(mut self, data: &'a [u64]) -> Sparkline<'a> {
|
||||||
self.data = data;
|
self.data = data;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ impl<'a> Sparkline<'a> {
|
||||||
/// Every bar will be scaled accordingly. If no max is given, this will be the max in the
|
/// Every bar will be scaled accordingly. If no max is given, this will be the max in the
|
||||||
/// dataset.
|
/// dataset.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn max(mut self, max: u64) -> Sparkline<'a> {
|
pub const fn max(mut self, max: u64) -> Sparkline<'a> {
|
||||||
self.max = Some(max);
|
self.max = Some(max);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ impl<'a> Sparkline<'a> {
|
||||||
/// Can be [`symbols::bar::THREE_LEVELS`], [`symbols::bar::NINE_LEVELS`] (default) or a custom
|
/// Can be [`symbols::bar::THREE_LEVELS`], [`symbols::bar::NINE_LEVELS`] (default) or a custom
|
||||||
/// [`Set`](symbols::bar::Set).
|
/// [`Set`](symbols::bar::Set).
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn bar_set(mut self, bar_set: symbols::bar::Set) -> Sparkline<'a> {
|
pub const fn bar_set(mut self, bar_set: symbols::bar::Set) -> Sparkline<'a> {
|
||||||
self.bar_set = bar_set;
|
self.bar_set = bar_set;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ impl<'a> Sparkline<'a> {
|
||||||
///
|
///
|
||||||
/// [`RenderDirection::LeftToRight`] by default.
|
/// [`RenderDirection::LeftToRight`] by default.
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn direction(mut self, direction: RenderDirection) -> Sparkline<'a> {
|
pub const fn direction(mut self, direction: RenderDirection) -> Sparkline<'a> {
|
||||||
self.direction = direction;
|
self.direction = direction;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl HighlightSpacing {
|
||||||
/// has_selection: true if a row is selected in the table
|
/// has_selection: true if a row is selected in the table
|
||||||
///
|
///
|
||||||
/// Returns true if a selection column should be displayed
|
/// Returns true if a selection column should be displayed
|
||||||
pub(crate) fn should_add(&self, has_selection: bool) -> bool {
|
pub(crate) const fn should_add(&self, has_selection: bool) -> bool {
|
||||||
match self {
|
match self {
|
||||||
HighlightSpacing::Always => true,
|
HighlightSpacing::Always => true,
|
||||||
HighlightSpacing::WhenSelected => has_selection,
|
HighlightSpacing::WhenSelected => has_selection,
|
||||||
|
|
|
@ -145,7 +145,7 @@ impl<'a> Row<'a> {
|
||||||
/// let row = Row::new(cells).height(2);
|
/// let row = Row::new(cells).height(2);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn height(mut self, height: u16) -> Self {
|
pub const fn height(mut self, height: u16) -> Self {
|
||||||
self.height = height;
|
self.height = height;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ impl<'a> Row<'a> {
|
||||||
/// let row = Row::default().top_margin(1);
|
/// let row = Row::default().top_margin(1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn top_margin(mut self, margin: u16) -> Self {
|
pub const fn top_margin(mut self, margin: u16) -> Self {
|
||||||
self.top_margin = margin;
|
self.top_margin = margin;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ impl<'a> Row<'a> {
|
||||||
/// let row = Row::default().bottom_margin(1);
|
/// let row = Row::default().bottom_margin(1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn bottom_margin(mut self, margin: u16) -> Self {
|
pub const fn bottom_margin(mut self, margin: u16) -> Self {
|
||||||
self.bottom_margin = margin;
|
self.bottom_margin = margin;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ impl<'a> Row<'a> {
|
||||||
// private methods for rendering
|
// private methods for rendering
|
||||||
impl Row<'_> {
|
impl Row<'_> {
|
||||||
/// Returns the total height of the row.
|
/// Returns the total height of the row.
|
||||||
pub(crate) fn height_with_margin(&self) -> u16 {
|
pub(crate) const fn height_with_margin(&self) -> u16 {
|
||||||
self.height
|
self.height
|
||||||
.saturating_add(self.top_margin)
|
.saturating_add(self.top_margin)
|
||||||
.saturating_add(self.bottom_margin)
|
.saturating_add(self.bottom_margin)
|
||||||
|
|
|
@ -400,7 +400,7 @@ impl<'a> Table<'a> {
|
||||||
/// let table = Table::new(rows, widths).column_spacing(1);
|
/// let table = Table::new(rows, widths).column_spacing(1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn column_spacing(mut self, spacing: u16) -> Self {
|
pub const fn column_spacing(mut self, spacing: u16) -> Self {
|
||||||
self.column_spacing = spacing;
|
self.column_spacing = spacing;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ impl<'a> Table<'a> {
|
||||||
/// let table = Table::new(rows, widths).highlight_spacing(HighlightSpacing::Always);
|
/// let table = Table::new(rows, widths).highlight_spacing(HighlightSpacing::Always);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn highlight_spacing(mut self, value: HighlightSpacing) -> Self {
|
pub const fn highlight_spacing(mut self, value: HighlightSpacing) -> Self {
|
||||||
self.highlight_spacing = value;
|
self.highlight_spacing = value;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl TableState {
|
||||||
/// let state = TableState::new().with_offset(1);
|
/// let state = TableState::new().with_offset(1);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn with_offset(mut self, offset: usize) -> Self {
|
pub const fn with_offset(mut self, offset: usize) -> Self {
|
||||||
self.offset = offset;
|
self.offset = offset;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ impl TableState {
|
||||||
/// let state = TableState::new();
|
/// let state = TableState::new();
|
||||||
/// assert_eq!(state.offset(), 0);
|
/// assert_eq!(state.offset(), 0);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn offset(&self) -> usize {
|
pub const fn offset(&self) -> usize {
|
||||||
self.offset
|
self.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ impl TableState {
|
||||||
/// let state = TableState::new();
|
/// let state = TableState::new();
|
||||||
/// assert_eq!(state.selected(), None);
|
/// assert_eq!(state.selected(), None);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn selected(&self) -> Option<usize> {
|
pub const fn selected(&self) -> Option<usize> {
|
||||||
self.selected
|
self.selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ impl<'a> Tabs<'a> {
|
||||||
/// The first tab has index 0 (this is also the default index).
|
/// The first tab has index 0 (this is also the default index).
|
||||||
/// The selected tab can have a different style with [`Tabs::highlight_style`].
|
/// The selected tab can have a different style with [`Tabs::highlight_style`].
|
||||||
#[must_use = "method moves the value of self and returns the modified value"]
|
#[must_use = "method moves the value of self and returns the modified value"]
|
||||||
pub fn select(mut self, selected: usize) -> Tabs<'a> {
|
pub const fn select(mut self, selected: usize) -> Tabs<'a> {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue