Skip to content

Commit

Permalink
Fix broken doc links in the demo app widget gallery (#3441)
Browse files Browse the repository at this point in the history
* Closes <#3439>
  • Loading branch information
YgorSouza authored Nov 10, 2023
1 parent 5f4046d commit 59b4eff
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions crates/egui_demo_lib/src/demo/widget_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl WidgetGallery {
date,
} = self;

ui.add(doc_link_label("Label", "label,heading"));
ui.add(doc_link_label("Label", "label"));
ui.label("Welcome to the widget gallery!");
ui.end_row();

Expand All @@ -121,7 +121,7 @@ impl WidgetGallery {
);
ui.end_row();

ui.add(doc_link_label("TextEdit", "TextEdit,text_edit"));
ui.add(doc_link_label("TextEdit", "TextEdit"));
ui.add(egui::TextEdit::singleline(string).hint_text("Write something here"));
ui.end_row();

Expand Down Expand Up @@ -149,10 +149,7 @@ impl WidgetGallery {
});
ui.end_row();

ui.add(doc_link_label(
"SelectableLabel",
"selectable_value,SelectableLabel",
));
ui.add(doc_link_label("SelectableLabel", "SelectableLabel"));
ui.horizontal(|ui| {
ui.selectable_value(radio, Enum::First, "First");
ui.selectable_value(radio, Enum::Second, "Second");
Expand Down Expand Up @@ -216,7 +213,11 @@ impl WidgetGallery {
#[cfg(feature = "chrono")]
{
let date = date.get_or_insert_with(|| chrono::offset::Utc::now().date_naive());
ui.add(doc_link_label("DatePickerButton", "DatePickerButton"));
ui.add(doc_link_label_with_crate(
"egui_extras",
"DatePickerButton",
"DatePickerButton",
));
ui.add(egui_extras::DatePickerButton::new(date));
ui.end_row();
}
Expand All @@ -237,7 +238,7 @@ impl WidgetGallery {
});
ui.end_row();

ui.add(doc_link_label("Plot", "plot"));
ui.add(doc_link_label_with_crate("egui_plot", "Plot", "plot"));
example_plot(ui);
ui.end_row();

Expand Down Expand Up @@ -273,8 +274,16 @@ fn example_plot(ui: &mut egui::Ui) -> egui::Response {
}

fn doc_link_label<'a>(title: &'a str, search_term: &'a str) -> impl egui::Widget + 'a {
doc_link_label_with_crate("egui", title, search_term)
}

fn doc_link_label_with_crate<'a>(
crate_name: &'a str,
title: &'a str,
search_term: &'a str,
) -> impl egui::Widget + 'a {
let label = format!("{title}:");
let url = format!("https://docs.rs/egui?search={search_term}");
let url = format!("https://docs.rs/{crate_name}?search={search_term}");
move |ui: &mut egui::Ui| {
ui.hyperlink_to(label, url).on_hover_ui(|ui| {
ui.horizontal_wrapped(|ui| {
Expand Down

0 comments on commit 59b4eff

Please sign in to comment.