summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 06:10:44 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 06:10:44 +0200
commit6ad7c7d3080816d37b17f1f6f5af5d8761983fdc (patch)
treebfaa5375c6908c4121db067f6d33cefa4876d8b8
parent9773631354aa1af354647fbdbdd8111da2816afb (diff)
downloadiced-6ad7c7d3080816d37b17f1f6f5af5d8761983fdc.tar.gz
iced-6ad7c7d3080816d37b17f1f6f5af5d8761983fdc.tar.bz2
iced-6ad7c7d3080816d37b17f1f6f5af5d8761983fdc.zip
Show `text` doc examples in multiple places
-rw-r--r--core/src/widget/text.rs46
-rw-r--r--widget/src/helpers.rs46
-rw-r--r--widget/src/text.rs22
3 files changed, 98 insertions, 16 deletions
diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs
index d8d6e4c6..8b02f8c2 100644
--- a/core/src/widget/text.rs
+++ b/core/src/widget/text.rs
@@ -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::layout;
use crate::mouse;
@@ -13,7 +34,28 @@ use crate::{
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)]
pub struct Text<'a, Theme, Renderer>
where
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index 146393dc..142d64d6 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -81,7 +81,6 @@ macro_rules! stack {
///
/// ```no_run
/// # mod iced {
-/// # pub struct Element<Message>(pub std::marker::PhantomData<Message>);
/// # pub mod widget {
/// # macro_rules! text {
/// # ($($arg:tt)*) => {unimplemented!()}
@@ -89,22 +88,23 @@ macro_rules! stack {
/// # pub(crate) use text;
/// # }
/// # }
-/// # struct Example;
-/// # enum Message {}
-/// use iced::Element;
+/// # pub type State = ();
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::core::Theme, ()>;
/// use iced::widget::text;
///
-/// impl Example {
-/// fn view(&self) -> Element<Message> {
-/// let simple = text!("Hello, world!");
+/// enum Message {
+/// // ...
+/// }
+///
+/// fn view(_state: &State) -> Element<Message> {
+/// let simple = text!("Hello, world!");
///
-/// let keyword = text!("Hello, {}", "world!");
+/// let keyword = text!("Hello, {}", "world!");
///
-/// let planet = "Earth";
-/// let local_variable = text!("Hello, {planet}!");
-/// // ...
-/// # iced::Element(std::marker::PhantomData)
-/// }
+/// let planet = "Earth";
+/// let local_variable = text!("Hello, {planet}!");
+/// // ...
+/// # unimplemented!()
/// }
/// ```
#[macro_export]
@@ -758,6 +758,26 @@ where
}
/// 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>(
text: impl text::IntoFragment<'a>,
) -> Text<'a, Theme, Renderer>
diff --git a/widget/src/text.rs b/widget/src/text.rs
index 9bf7fce4..c2243434 100644
--- a/widget/src/text.rs
+++ b/widget/src/text.rs
@@ -5,6 +5,26 @@ pub use crate::core::text::{Fragment, Highlighter, IntoFragment, Span};
pub use crate::core::widget::text::*;
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> =
crate::core::widget::Text<'a, Theme, Renderer>;