[demo] Add helper macros for linking to the source code on GitHub
This commit is contained in:
parent
496fdb52b4
commit
82d55cb67e
3 changed files with 48 additions and 4 deletions
|
@ -43,3 +43,49 @@ pub fn warn_if_debug_build(ui: &mut crate::Ui) {
|
||||||
.on_hover_text("Egui has detect that debug assertions are enabled.");
|
.on_hover_text("Egui has detect that debug assertions are enabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Create a `Hyperlink` to this file (and line) on Github
|
||||||
|
/// Example: `ui.add(github_link_file_line!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));`
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! github_link_file_line {
|
||||||
|
($github_url:expr, $label:expr) => {{
|
||||||
|
let url = format!("{}{}#L{}", $github_url, file!(), line!());
|
||||||
|
Hyperlink::new(url).text($label)
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a `Hyperlink` to this file on github.
|
||||||
|
/// Example: `ui.add(github_link_file!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));`
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! github_link_file {
|
||||||
|
($github_url:expr, $label:expr) => {{
|
||||||
|
let url = format!("{}{}", $github_url, file!());
|
||||||
|
Hyperlink::new(url).text($label)
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a `Hyperlink` to this egui source code file on github.
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! __egui_github_link_file {
|
||||||
|
() => {
|
||||||
|
__egui_github_link_file!("(source code)")
|
||||||
|
};
|
||||||
|
($label:expr) => {
|
||||||
|
github_link_file!("https://github.com/emilk/egui/blob/master/", $label).small()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a `Hyperlink` to this egui source code file and line on github.
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! __egui_github_link_file_line {
|
||||||
|
() => {
|
||||||
|
__egui_github_link_file_line!("(source code)")
|
||||||
|
};
|
||||||
|
($label:expr) => {
|
||||||
|
github_link_file_line!("https://github.com/emilk/egui/blob/master/", $label).small()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -90,10 +90,9 @@ fn toggle_compact(ui: &mut Ui, on: &mut bool) -> Response {
|
||||||
|
|
||||||
pub fn demo(ui: &mut Ui, on: &mut bool) {
|
pub fn demo(ui: &mut Ui, on: &mut bool) {
|
||||||
ui.label("It's easy to create your own widgets!");
|
ui.label("It's easy to create your own widgets!");
|
||||||
let url = format!("https://github.com/emilk/egui/blob/master/{}", file!());
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Like this toggle switch:");
|
ui.label("Like this toggle switch:");
|
||||||
toggle(ui, on).on_hover_text("Click to toggle");
|
toggle(ui, on).on_hover_text("Click to toggle");
|
||||||
ui.add(Hyperlink::new(url).text("(source code)"));
|
ui.add(__egui_github_link_file!());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,7 @@ impl Default for Widgets {
|
||||||
|
|
||||||
impl Widgets {
|
impl Widgets {
|
||||||
pub fn ui(&mut self, ui: &mut Ui) {
|
pub fn ui(&mut self, ui: &mut Ui) {
|
||||||
let url = format!("https://github.com/emilk/egui/blob/master/{}", file!());
|
ui.add(crate::__egui_github_link_file_line!());
|
||||||
ui.add(Hyperlink::new(url).text("Click here to read the source code for this section"));
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.style_mut().spacing.item_spacing.x = 0.0;
|
ui.style_mut().spacing.item_spacing.x = 0.0;
|
||||||
|
|
Loading…
Reference in a new issue