Show text doc examples in multiple places
This commit is contained in:
parent
9773631354
commit
6ad7c7d308
3 changed files with 98 additions and 16 deletions
|
|
@ -1,4 +1,25 @@
|
||||||
//! Write some text for your users to read.
|
//! Text widgets display information through writing.
|
||||||
|
//!
|
||||||
|
//! # Example
|
||||||
|
//! ```no_run
|
||||||
|
//! # mod iced { pub mod widget { pub fn text<T>(t: T) -> iced_core::widget::Text<'static, iced_core::Theme, ()> { unimplemented!() } }
|
||||||
|
//! # pub use iced_core::color; }
|
||||||
|
//! # pub type State = ();
|
||||||
|
//! # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, ()>;
|
||||||
|
//! use iced::widget::text;
|
||||||
|
//! use iced::color;
|
||||||
|
//!
|
||||||
|
//! enum Message {
|
||||||
|
//! // ...
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
//! text("Hello, this is iced!")
|
||||||
|
//! .size(20)
|
||||||
|
//! .color(color!(0x0000ff))
|
||||||
|
//! .into()
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
use crate::alignment;
|
use crate::alignment;
|
||||||
use crate::layout;
|
use crate::layout;
|
||||||
use crate::mouse;
|
use crate::mouse;
|
||||||
|
|
@ -13,7 +34,28 @@ use crate::{
|
||||||
|
|
||||||
pub use text::{LineHeight, Shaping, Wrapping};
|
pub use text::{LineHeight, Shaping, Wrapping};
|
||||||
|
|
||||||
/// A paragraph of text.
|
/// A bunch of text.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```no_run
|
||||||
|
/// # mod iced { pub mod widget { pub fn text<T>(t: T) -> iced_core::widget::Text<'static, iced_core::Theme, ()> { unimplemented!() } }
|
||||||
|
/// # pub use iced_core::color; }
|
||||||
|
/// # pub type State = ();
|
||||||
|
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, ()>;
|
||||||
|
/// use iced::widget::text;
|
||||||
|
/// use iced::color;
|
||||||
|
///
|
||||||
|
/// enum Message {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
/// text("Hello, this is iced!")
|
||||||
|
/// .size(20)
|
||||||
|
/// .color(color!(0x0000ff))
|
||||||
|
/// .into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Text<'a, Theme, Renderer>
|
pub struct Text<'a, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ macro_rules! stack {
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # mod iced {
|
/// # mod iced {
|
||||||
/// # pub struct Element<Message>(pub std::marker::PhantomData<Message>);
|
|
||||||
/// # pub mod widget {
|
/// # pub mod widget {
|
||||||
/// # macro_rules! text {
|
/// # macro_rules! text {
|
||||||
/// # ($($arg:tt)*) => {unimplemented!()}
|
/// # ($($arg:tt)*) => {unimplemented!()}
|
||||||
|
|
@ -89,22 +88,23 @@ macro_rules! stack {
|
||||||
/// # pub(crate) use text;
|
/// # pub(crate) use text;
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// # struct Example;
|
/// # pub type State = ();
|
||||||
/// # enum Message {}
|
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::core::Theme, ()>;
|
||||||
/// use iced::Element;
|
|
||||||
/// use iced::widget::text;
|
/// use iced::widget::text;
|
||||||
///
|
///
|
||||||
/// impl Example {
|
/// enum Message {
|
||||||
/// fn view(&self) -> Element<Message> {
|
/// // ...
|
||||||
/// let simple = text!("Hello, world!");
|
/// }
|
||||||
///
|
///
|
||||||
/// let keyword = text!("Hello, {}", "world!");
|
/// fn view(_state: &State) -> Element<Message> {
|
||||||
|
/// let simple = text!("Hello, world!");
|
||||||
///
|
///
|
||||||
/// let planet = "Earth";
|
/// let keyword = text!("Hello, {}", "world!");
|
||||||
/// let local_variable = text!("Hello, {planet}!");
|
///
|
||||||
/// // ...
|
/// let planet = "Earth";
|
||||||
/// # iced::Element(std::marker::PhantomData)
|
/// let local_variable = text!("Hello, {planet}!");
|
||||||
/// }
|
/// // ...
|
||||||
|
/// # unimplemented!()
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
@ -758,6 +758,26 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`Text`] widget with the provided content.
|
/// Creates a new [`Text`] widget with the provided content.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```no_run
|
||||||
|
/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; }
|
||||||
|
/// # pub type State = ();
|
||||||
|
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::core::Theme, ()>;
|
||||||
|
/// use iced::widget::text;
|
||||||
|
/// use iced::color;
|
||||||
|
///
|
||||||
|
/// enum Message {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
/// text("Hello, this is iced!")
|
||||||
|
/// .size(20)
|
||||||
|
/// .color(color!(0x0000ff))
|
||||||
|
/// .into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
pub fn text<'a, Theme, Renderer>(
|
pub fn text<'a, Theme, Renderer>(
|
||||||
text: impl text::IntoFragment<'a>,
|
text: impl text::IntoFragment<'a>,
|
||||||
) -> Text<'a, Theme, Renderer>
|
) -> Text<'a, Theme, Renderer>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,26 @@ pub use crate::core::text::{Fragment, Highlighter, IntoFragment, Span};
|
||||||
pub use crate::core::widget::text::*;
|
pub use crate::core::widget::text::*;
|
||||||
pub use rich::Rich;
|
pub use rich::Rich;
|
||||||
|
|
||||||
/// A paragraph.
|
/// A bunch of text.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```no_run
|
||||||
|
/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; }
|
||||||
|
/// # pub type State = ();
|
||||||
|
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
|
||||||
|
/// use iced::widget::text;
|
||||||
|
/// use iced::color;
|
||||||
|
///
|
||||||
|
/// enum Message {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
/// text("Hello, this is iced!")
|
||||||
|
/// .size(20)
|
||||||
|
/// .color(color!(0x0000ff))
|
||||||
|
/// .into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
pub type Text<'a, Theme = crate::Theme, Renderer = crate::Renderer> =
|
pub type Text<'a, Theme = crate::Theme, Renderer = crate::Renderer> =
|
||||||
crate::core::widget::Text<'a, Theme, Renderer>;
|
crate::core::widget::Text<'a, Theme, Renderer>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue