Skip to content

Commit

Permalink
Rename on_link_clicked to on_link_click
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Feb 4, 2025
1 parent e8020f3 commit f8c71a2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/changelog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl Generator {
..Font::default()
}),
]
.on_link_clicked(Message::OpenPullRequest)
.on_link_click(Message::OpenPullRequest)
.font(Font::MONOSPACE);

let description =
Expand Down
2 changes: 1 addition & 1 deletion examples/markdown/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ struct CustomViewer<'a> {
}

impl<'a> markdown::Viewer<'a, Message> for CustomViewer<'a> {
fn on_link_clicked(url: markdown::Url) -> Message {
fn on_link_click(url: markdown::Url) -> Message {
Message::LinkClicked(url)
}

Expand Down
6 changes: 3 additions & 3 deletions widget/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ macro_rules! text {
/// span(" "),
/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
/// ]
/// .on_link_clicked(never)
/// .on_link_click(never)
/// .size(20)
/// .into()
/// }
Expand Down Expand Up @@ -1153,7 +1153,7 @@ where
/// span(" "),
/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
/// ])
/// .on_link_clicked(never)
/// .on_link_click(never)
/// .size(20)
/// .into()
/// }
Expand Down Expand Up @@ -1197,7 +1197,7 @@ where
/// " ",
/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
/// ]
/// .on_link_clicked(never)
/// .on_link_click(never)
/// .size(20)
/// .into()
/// }
Expand Down
24 changes: 12 additions & 12 deletions widget/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ pub fn heading<'a, Message, Theme, Renderer>(
level: &'a HeadingLevel,
text: &'a Text,
index: usize,
on_link_clicked: impl Fn(Url) -> Message + 'a,
on_link_click: impl Fn(Url) -> Message + 'a,
) -> Element<'a, Message, Theme, Renderer>
where
Message: 'a,
Expand All @@ -1068,7 +1068,7 @@ where

container(
rich_text(text.spans(settings.style))
.on_link_clicked(on_link_clicked)
.on_link_click(on_link_click)
.size(match level {
pulldown_cmark::HeadingLevel::H1 => h1_size,
pulldown_cmark::HeadingLevel::H2 => h2_size,
Expand All @@ -1090,7 +1090,7 @@ where
pub fn paragraph<'a, Message, Theme, Renderer>(
settings: Settings,
text: &'a Text,
on_link_clicked: impl Fn(Url) -> Message + 'a,
on_link_click: impl Fn(Url) -> Message + 'a,
) -> Element<'a, Message, Theme, Renderer>
where
Message: 'a,
Expand All @@ -1099,7 +1099,7 @@ where
{
rich_text(text.spans(settings.style))
.size(settings.text_size)
.on_link_clicked(on_link_clicked)
.on_link_click(on_link_click)
.into()
}

Expand Down Expand Up @@ -1173,7 +1173,7 @@ pub fn code_block<'a, Message, Theme, Renderer>(
settings: Settings,
_code: &'a str,
lines: &'a [Text],
on_link_clicked: impl Fn(Url) -> Message + Clone + 'a,
on_link_click: impl Fn(Url) -> Message + Clone + 'a,
) -> Element<'a, Message, Theme, Renderer>
where
Message: 'a,
Expand All @@ -1184,7 +1184,7 @@ where
scrollable(
container(column(lines.iter().map(|line| {
rich_text(line.spans(settings.style))
.on_link_clicked(on_link_clicked.clone())
.on_link_click(on_link_click.clone())
.font(Font::MONOSPACE)
.size(settings.code_size)
.into()
Expand Down Expand Up @@ -1212,7 +1212,7 @@ where
Renderer: core::text::Renderer<Font = Font> + 'a,
{
/// Produces a message when a link is clicked with the given [`Url`].
fn on_link_clicked(url: Url) -> Message;
fn on_link_click(url: Url) -> Message;

/// Displays an image.
///
Expand All @@ -1229,7 +1229,7 @@ where

container(
rich_text(alt.spans(settings.style))
.on_link_clicked(Self::on_link_clicked),
.on_link_click(Self::on_link_click),
)
.padding(settings.spacing.0)
.class(Theme::code_block())
Expand All @@ -1246,7 +1246,7 @@ where
text: &'a Text,
index: usize,
) -> Element<'a, Message, Theme, Renderer> {
heading(settings, level, text, index, Self::on_link_clicked)
heading(settings, level, text, index, Self::on_link_click)
}

/// Displays a paragraph.
Expand All @@ -1257,7 +1257,7 @@ where
settings: Settings,
text: &'a Text,
) -> Element<'a, Message, Theme, Renderer> {
paragraph(settings, text, Self::on_link_clicked)
paragraph(settings, text, Self::on_link_click)
}

/// Displays a code block.
Expand All @@ -1269,7 +1269,7 @@ where
code: &'a str,
lines: &'a [Text],
) -> Element<'a, Message, Theme, Renderer> {
code_block(settings, code, lines, Self::on_link_clicked)
code_block(settings, code, lines, Self::on_link_click)
}

/// Displays an unordered list.
Expand Down Expand Up @@ -1304,7 +1304,7 @@ where
Theme: Catalog + 'a,
Renderer: core::text::Renderer<Font = Font> + 'a,
{
fn on_link_clicked(url: Url) -> Url {
fn on_link_click(url: Url) -> Url {
url
}
}
Expand Down
12 changes: 6 additions & 6 deletions widget/src/text/rich.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Rich<
wrapping: Wrapping,
class: Theme::Class<'a>,
hovered_link: Option<usize>,
on_link_clicked: Option<Box<dyn Fn(Link) -> Message + 'a>>,
on_link_click: Option<Box<dyn Fn(Link) -> Message + 'a>>,
}

impl<'a, Link, Message, Theme, Renderer>
Expand All @@ -61,7 +61,7 @@ where
wrapping: Wrapping::default(),
class: Theme::default(),
hovered_link: None,
on_link_clicked: None,
on_link_click: None,
}
}

Expand Down Expand Up @@ -137,11 +137,11 @@ where

/// Sets the message that will be produced when a link of the [`Rich`] text
/// is clicked.
pub fn on_link_clicked(
pub fn on_link_click(
mut self,
on_link_clicked: impl Fn(Link) -> Message + 'a,
) -> Self {
self.on_link_clicked = Some(Box::new(on_link_clicked));
self.on_link_click = Some(Box::new(on_link_clicked));
self
}

Expand Down Expand Up @@ -271,7 +271,7 @@ where
let style = theme.style(&self.class);

for (index, span) in self.spans.as_ref().as_ref().iter().enumerate() {
let is_hovered_link = self.on_link_clicked.is_some()
let is_hovered_link = self.on_link_click.is_some()
&& Some(index) == self.hovered_link;

if span.highlight.is_some()
Expand Down Expand Up @@ -386,7 +386,7 @@ where
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) {
let Some(on_link_clicked) = &self.on_link_clicked else {
let Some(on_link_clicked) = &self.on_link_click else {
return;
};

Expand Down

0 comments on commit f8c71a2

Please sign in to comment.