Skip to content

Commit

Permalink
Fix documentation of markdown and rich_text
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Feb 4, 2025
1 parent 5655998 commit 24cf355
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 51 deletions.
9 changes: 9 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ pub use vector::Vector;
pub use widget::Widget;

pub use smol_str::SmolStr;

/// A function that can _never_ be called.
///
/// This is useful to turn generic types into anything
/// you want by coercing them into a type with no possible
/// values.
pub fn never<T>(never: std::convert::Infallible) -> T {
match never {}
}
8 changes: 4 additions & 4 deletions examples/changelog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Generator {
.font(Font::MONOSPACE);

let description =
markdown::view(&self.theme(), description)
markdown(description, self.theme())
.map(Message::UrlClicked);

let labels =
Expand Down Expand Up @@ -344,12 +344,12 @@ impl Generator {
} else {
container(
scrollable(
markdown::view(
markdown(
preview,
markdown::Settings::with_text_size(
12,
&self.theme(),
self.theme(),
),
preview,
)
.map(Message::UrlClicked),
)
Expand Down
4 changes: 2 additions & 2 deletions examples/markdown/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ impl Markdown {
};

let preview = markdown::view_with(
items,
&self.theme,
&MarkdownViewer {
images: &self.images,
},
&self.theme,
items,
);

row![
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ pub use crate::core::gradient;
pub use crate::core::padding;
pub use crate::core::theme;
pub use crate::core::{
Alignment, Animation, Background, Border, Color, ContentFit, Degrees,
Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Rotation,
Settings, Shadow, Size, Theme, Transformation, Vector,
never, Alignment, Animation, Background, Border, Color, ContentFit,
Degrees, Gradient, Length, Padding, Pixels, Point, Radians, Rectangle,
Rotation, Settings, Shadow, Size, Theme, Transformation, Vector,
};
pub use crate::runtime::exit;
pub use iced_futures::Subscription;
Expand Down
12 changes: 8 additions & 4 deletions widget/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ macro_rules! text {
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// use iced::font;
/// use iced::widget::{rich_text, span};
/// use iced::{color, Font};
/// use iced::{color, never, Font};
///
/// #[derive(Debug, Clone)]
/// enum Message {
Expand All @@ -177,9 +177,10 @@ macro_rules! text {
/// fn view(state: &State) -> Element<'_, Message> {
/// rich_text![
/// span("I am red!").color(color!(0xff0000)),
/// " ",
/// span(" "),
/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
/// ]
/// .on_link_clicked(never)
/// .size(20)
/// .into()
/// }
Expand Down Expand Up @@ -1138,10 +1139,11 @@ where
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// use iced::font;
/// use iced::widget::{rich_text, span};
/// use iced::{color, Font};
/// use iced::{color, never, Font};
///
/// #[derive(Debug, Clone)]
/// enum Message {
/// LinkClicked(&'static str),
/// // ...
/// }
///
Expand All @@ -1151,6 +1153,7 @@ where
/// span(" "),
/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
/// ])
/// .on_link_clicked(never)
/// .size(20)
/// .into()
/// }
Expand Down Expand Up @@ -1181,7 +1184,7 @@ where
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// use iced::font;
/// use iced::widget::{rich_text, span};
/// use iced::{color, Font};
/// use iced::{color, never, Font};
///
/// #[derive(Debug, Clone)]
/// enum Message {
Expand All @@ -1194,6 +1197,7 @@ where
/// " ",
/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
/// ]
/// .on_link_clicked(never)
/// .size(20)
/// .into()
/// }
Expand Down
Loading

0 comments on commit 24cf355

Please sign in to comment.