Skip to content

Commit

Permalink
docs: fix scrollbar ascii illustrations and calendar doc paths (ratat…
Browse files Browse the repository at this point in the history
…ui#272)

* docs(src\widgets\scrollbar.rs): wrap scrollbar's visualisation in text block

'cargo doc' and 'rust-analyzer' removes many whitespaces thus making those parts render improperly

* docs(src/widgets/calendar.rs): fix `no item named ...` for calendar.rs

* style(src/widgets/block.rs): format `block.rs`
  • Loading branch information
SLASHLogin authored Jun 21, 2023
1 parent a04b190 commit b808305
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/widgets/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[path = "../title.rs"]
pub mod title;

use self::title::{Position, Title};
use crate::{
buffer::Buffer,
layout::{Alignment, Rect},
Expand All @@ -9,8 +10,6 @@ use crate::{
widgets::{Borders, Widget},
};

use self::title::{Position, Title};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BorderType {
Plain,
Expand Down Expand Up @@ -113,7 +112,6 @@ impl Padding {
/// .border_type(BorderType::Rounded)
/// .style(Style::default().bg(Color::Black));
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Block<'a> {
/// List of titles
Expand All @@ -129,7 +127,8 @@ pub struct Block<'a> {
borders: Borders,
/// Border style
border_style: Style,
/// Type of the border. The default is plain lines but one can choose to have rounded or doubled lines instead.
/// Type of the border. The default is plain lines but one can choose to have rounded or
/// doubled lines instead.
border_type: BorderType,

/// Widget style
Expand Down Expand Up @@ -166,18 +165,24 @@ impl<'a> Block<'a> {
/// Title::from("Center")
/// .alignment(Alignment::Center),
/// );
///```
/// ```
/// Adds a title to the block.
///
/// The `title` function allows you to add a title to the block. You can call this function multiple times to add multiple titles.
/// The `title` function allows you to add a title to the block. You can call this function
/// multiple times to add multiple titles.
///
/// Each title will be rendered with a single space separating titles that are in the same position or alignment. When both centered and non-centered titles are rendered, the centered space is calculated based on the full width of the block, rather than the leftover width.
/// Each title will be rendered with a single space separating titles that are in the same
/// position or alignment. When both centered and non-centered titles are rendered, the centered
/// space is calculated based on the full width of the block, rather than the leftover width.
///
/// You can provide various types as the title, including strings, string slices, borrowed strings (`Cow<str>`), spans, or vectors of spans (`Vec<Span>`).
/// You can provide various types as the title, including strings, string slices, borrowed
/// strings (`Cow<str>`), spans, or vectors of spans (`Vec<Span>`).
///
/// By default, the titles will avoid being rendered in the corners of the block but will align against the left or right edge of the block if there is no border on that edge.
/// By default, the titles will avoid being rendered in the corners of the block but will align
/// against the left or right edge of the block if there is no border on that edge.
///
/// Note: If the block is too small and multiple titles overlap, the border might get cut off at a corner.
/// Note: If the block is too small and multiple titles overlap, the border might get cut off at
/// a corner.
pub fn title<T>(mut self, title: T) -> Block<'a>
where
T: Into<Title<'a>>,
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a, S: DateStyler> Monthly<'a, S> {
self
}

/// Render the calendar within a [Block](ratatui::widgets::Block)
/// Render the calendar within a [Block](crate::widgets::Block)
pub fn block(mut self, b: Block<'a>) -> Self {
self.block = Some(b);
self
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<'a, S: DateStyler> Widget for Monthly<'a, S> {
}
}

/// Provides a method for styling a given date. [Month] is generic on this trait, so any type
/// Provides a method for styling a given date. [Monthly] is generic on this trait, so any type
/// that implements this trait can be used.
pub trait DateStyler {
/// Given a date, return a style for that date
Expand Down
10 changes: 10 additions & 0 deletions src/widgets/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use crate::{
};

/// Scrollbar Set
/// ```text
/// <--▮------->
/// ^ ^ ^ ^
/// │ │ │ └ end
/// │ │ └──── track
/// │ └──────── thumb
/// └─────────── begin
/// ```
#[derive(Debug, Clone)]
pub struct Set {
pub track: &'static str,
Expand Down Expand Up @@ -67,12 +69,14 @@ pub enum ScrollDirection {
/// - the `content_length` is 4
/// - the `viewport_content_length` is 2
///
/// ```text
/// ┌───────────────┐
/// │1. this is a █
/// │ single item █
/// │2. this is a ║
/// │ second item ║
/// └───────────────┘
/// ```
///
/// If you don't have multi-line content, you can leave the `viewport_content_length` set to the
/// default of 0 and it'll use the track size as a `viewport_content_length`.
Expand Down Expand Up @@ -156,12 +160,14 @@ pub enum ScrollbarOrientation {
/// This widget can be used to display a scrollbar in a terminal user interface.
/// The following components of the scrollbar are customizable in symbol and style.
///
/// ```text
/// <--▮------->
/// ^ ^ ^ ^
/// │ │ │ └ end
/// │ │ └──── track
/// │ └──────── thumb
/// └─────────── begin
/// ```
#[derive(Debug, Clone)]
pub struct Scrollbar<'a> {
orientation: ScrollbarOrientation,
Expand Down Expand Up @@ -264,12 +270,14 @@ impl<'a> Scrollbar<'a> {

/// Sets the symbols used for the various parts of the scrollbar from a [`Set`].
///
/// ```text
/// <--▮------->
/// ^ ^ ^ ^
/// │ │ │ └ end
/// │ │ └──── track
/// │ └──────── thumb
/// └─────────── begin
/// ```
///
/// Only sets begin_symbol and end_symbol if they already contain a value.
/// If begin_symbol and/or end_symbol were set to `None` explicitly, this function will respect
Expand All @@ -287,12 +295,14 @@ impl<'a> Scrollbar<'a> {
}

/// Sets the style used for the various parts of the scrollbar from a [`Style`].
/// ```text
/// <--▮------->
/// ^ ^ ^ ^
/// │ │ │ └ end
/// │ │ └──── track
/// │ └──────── thumb
/// └─────────── begin
/// ```
pub fn style(mut self, style: Style) -> Self {
self.track_style = style;
self.thumb_style = style;
Expand Down

0 comments on commit b808305

Please sign in to comment.