summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 05:45:40 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 05:45:40 +0200
commit9773631354aa1af354647fbdbdd8111da2816afb (patch)
treefab240cea4a218a64c5a0fe12a0db611505441f7
parent10fa40a85f09921c015fb2632aa34b9ef26d13cd (diff)
downloadiced-9773631354aa1af354647fbdbdd8111da2816afb.tar.gz
iced-9773631354aa1af354647fbdbdd8111da2816afb.tar.bz2
iced-9773631354aa1af354647fbdbdd8111da2816afb.zip
Show `svg` doc example in multiple places
-rw-r--r--widget/src/helpers.rs18
-rw-r--r--widget/src/svg.rs34
2 files changed, 51 insertions, 1 deletions
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index a8da2a32..146393dc 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -1341,8 +1341,26 @@ pub fn image<Handle>(handle: impl Into<Handle>) -> crate::Image<Handle> {
/// Creates a new [`Svg`] widget from the given [`Handle`].
///
+/// Svg widgets display vector graphics in your application.
+///
/// [`Svg`]: crate::Svg
/// [`Handle`]: crate::svg::Handle
+///
+/// # Example
+/// ```no_run
+/// # mod iced { pub mod widget { pub use iced_widget::*; } }
+/// # pub type State = ();
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+/// use iced::widget::svg;
+///
+/// enum Message {
+/// // ...
+/// }
+///
+/// fn view(state: &State) -> Element<'_, Message> {
+/// svg("tiger.svg").into()
+/// }
+/// ```
#[cfg(feature = "svg")]
pub fn svg<'a, Theme>(
handle: impl Into<core::svg::Handle>,
diff --git a/widget/src/svg.rs b/widget/src/svg.rs
index bec0090f..8d57265a 100644
--- a/widget/src/svg.rs
+++ b/widget/src/svg.rs
@@ -1,4 +1,20 @@
-//! Display vector graphics in your application.
+//! Svg widgets display vector graphics in your application.
+//!
+//! # Example
+//! ```no_run
+//! # mod iced { pub mod widget { pub use iced_widget::*; } }
+//! # pub type State = ();
+//! # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+//! use iced::widget::svg;
+//!
+//! enum Message {
+//! // ...
+//! }
+//!
+//! fn view(state: &State) -> Element<'_, Message> {
+//! svg("tiger.svg").into()
+//! }
+//! ```
use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
@@ -19,6 +35,22 @@ pub use crate::core::svg::Handle;
///
/// [`Svg`] images can have a considerable rendering cost when resized,
/// specially when they are complex.
+///
+/// # Example
+/// ```no_run
+/// # mod iced { pub mod widget { pub use iced_widget::*; } }
+/// # pub type State = ();
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+/// use iced::widget::svg;
+///
+/// enum Message {
+/// // ...
+/// }
+///
+/// fn view(state: &State) -> Element<'_, Message> {
+/// svg("tiger.svg").into()
+/// }
+/// ```
#[allow(missing_debug_implementations)]
pub struct Svg<'a, Theme = crate::Theme>
where