Rename on_link_click to on_link
This commit is contained in:
parent
54500e61ed
commit
7072c696a0
2 changed files with 12 additions and 15 deletions
|
|
@ -278,7 +278,7 @@ pub fn parse(
|
||||||
/// You can obtain the items with [`parse`].
|
/// You can obtain the items with [`parse`].
|
||||||
pub fn view<'a, Message, Renderer>(
|
pub fn view<'a, Message, Renderer>(
|
||||||
items: impl IntoIterator<Item = &'a Item>,
|
items: impl IntoIterator<Item = &'a Item>,
|
||||||
on_link_click: impl Fn(String) -> Message + Copy + 'a,
|
on_link: impl Fn(String) -> Message + Copy + 'a,
|
||||||
) -> Element<'a, Message, Theme, Renderer>
|
) -> Element<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
Message: 'a,
|
Message: 'a,
|
||||||
|
|
@ -286,16 +286,16 @@ where
|
||||||
{
|
{
|
||||||
let blocks = items.into_iter().enumerate().map(|(i, item)| match item {
|
let blocks = items.into_iter().enumerate().map(|(i, item)| match item {
|
||||||
Item::Heading(heading) => {
|
Item::Heading(heading) => {
|
||||||
container(rich_text(heading).on_link_click(on_link_click))
|
container(rich_text(heading).on_link(on_link))
|
||||||
.padding(padding::top(if i > 0 { 8 } else { 0 }))
|
.padding(padding::top(if i > 0 { 8 } else { 0 }))
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
Item::Paragraph(paragraph) => {
|
Item::Paragraph(paragraph) => {
|
||||||
rich_text(paragraph).on_link_click(on_link_click).into()
|
rich_text(paragraph).on_link(on_link).into()
|
||||||
}
|
}
|
||||||
Item::List { start: None, items } => {
|
Item::List { start: None, items } => {
|
||||||
column(items.iter().map(|items| {
|
column(items.iter().map(|items| {
|
||||||
row!["•", view(items, on_link_click)].spacing(10).into()
|
row!["•", view(items, on_link)].spacing(10).into()
|
||||||
}))
|
}))
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.into()
|
.into()
|
||||||
|
|
@ -304,7 +304,7 @@ where
|
||||||
start: Some(start),
|
start: Some(start),
|
||||||
items,
|
items,
|
||||||
} => column(items.iter().enumerate().map(|(i, items)| {
|
} => column(items.iter().enumerate().map(|(i, items)| {
|
||||||
row![text!("{}.", i as u64 + *start), view(items, on_link_click)]
|
row![text!("{}.", i as u64 + *start), view(items, on_link)]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.into()
|
.into()
|
||||||
}))
|
}))
|
||||||
|
|
@ -314,7 +314,7 @@ where
|
||||||
rich_text(code)
|
rich_text(code)
|
||||||
.font(Font::MONOSPACE)
|
.font(Font::MONOSPACE)
|
||||||
.size(12)
|
.size(12)
|
||||||
.on_link_click(on_link_click),
|
.on_link(on_link),
|
||||||
)
|
)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.padding(10)
|
.padding(10)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ pub struct Rich<
|
||||||
align_x: alignment::Horizontal,
|
align_x: alignment::Horizontal,
|
||||||
align_y: alignment::Vertical,
|
align_y: alignment::Vertical,
|
||||||
class: Theme::Class<'a>,
|
class: Theme::Class<'a>,
|
||||||
on_link_click: Option<Box<dyn Fn(Link) -> Message + 'a>>,
|
on_link: Option<Box<dyn Fn(Link) -> Message + 'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Link, Theme, Renderer>
|
impl<'a, Message, Link, Theme, Renderer>
|
||||||
|
|
@ -59,7 +59,7 @@ where
|
||||||
align_x: alignment::Horizontal::Left,
|
align_x: alignment::Horizontal::Left,
|
||||||
align_y: alignment::Vertical::Top,
|
align_y: alignment::Vertical::Top,
|
||||||
class: Theme::default(),
|
class: Theme::default(),
|
||||||
on_link_click: None,
|
on_link: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,11 +156,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the message handler for link clicks on the [`Rich`] text.
|
/// Sets the message handler for link clicks on the [`Rich`] text.
|
||||||
pub fn on_link_click(
|
pub fn on_link(mut self, on_link: impl Fn(Link) -> Message + 'a) -> Self {
|
||||||
mut self,
|
self.on_link = Some(Box::new(on_link));
|
||||||
on_link_click: impl Fn(Link) -> Message + 'a,
|
|
||||||
) -> Self {
|
|
||||||
self.on_link_click = Some(Box::new(on_link_click));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,7 +282,7 @@ where
|
||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
_viewport: &Rectangle,
|
_viewport: &Rectangle,
|
||||||
) -> event::Status {
|
) -> event::Status {
|
||||||
let Some(on_link_click) = self.on_link_click.as_ref() else {
|
let Some(on_link_click) = self.on_link.as_ref() else {
|
||||||
return event::Status::Ignored;
|
return event::Status::Ignored;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -342,7 +339,7 @@ where
|
||||||
_viewport: &Rectangle,
|
_viewport: &Rectangle,
|
||||||
_renderer: &Renderer,
|
_renderer: &Renderer,
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
if self.on_link_click.is_none() {
|
if self.on_link.is_none() {
|
||||||
return mouse::Interaction::None;
|
return mouse::Interaction::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue