pub struct Bind<'a, B: BindTarget> { /* private fields */ }Expand description
Widget for showing the bind itself
Implementations§
source§impl<'a, B: BindTarget> Bind<'a, B>
impl<'a, B: BindTarget> Bind<'a, B>
sourcepub fn new(id_source: impl Hash, value: &'a mut B) -> Self
pub fn new(id_source: impl Hash, value: &'a mut B) -> Self
Creates a new bind widget
Examples found in repository?
src/lib.rs (line 125)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
pub fn show_bind_popup(
ui: &mut Ui,
bind: &mut impl BindTarget,
popup_id_source: impl Hash,
widget_response: &Response,
) {
let popup_id = Id::new(popup_id_source);
if widget_response.secondary_clicked() {
ui.memory().toggle_popup(popup_id);
}
let mut should_close = false;
let was_opened = ui.memory().is_popup_open(popup_id);
let mut styles = ui.ctx().style().as_ref().clone();
let saved_margin = styles.spacing.window_margin;
styles.spacing.window_margin = Margin::same(0.);
ui.ctx().set_style(styles.clone());
egui::popup_below_widget(ui, popup_id, widget_response, |ui| {
let r = ui.add(Bind::new(popup_id.with("_bind"), bind));
if r.changed() || ui.input().key_down(Key::Escape) {
ui.memory().close_popup();
should_close = true;
}
});
styles.spacing.window_margin = saved_margin;
ui.ctx().set_style(styles);
if !should_close && was_opened {
ui.memory().open_popup(popup_id);
}
}