pill.rs (1390B)
1 /// Pill-style UI components for displaying labeled values. 2 /// 3 /// Pills are compact, rounded UI elements used to display key-value pairs 4 /// in a visually distinct way, commonly used in query displays. 5 use egui::Ui; 6 7 /// Render a pill label with a text value 8 pub fn pill_label(name: &str, value: &str, ui: &mut Ui) { 9 pill_label_ui( 10 name, 11 move |ui| { 12 ui.label(value); 13 }, 14 ui, 15 ); 16 } 17 18 /// Render a pill label with a custom UI closure for the value 19 pub fn pill_label_ui(name: &str, mut value: impl FnMut(&mut Ui), ui: &mut Ui) { 20 egui::Frame::new() 21 .fill(ui.visuals().noninteractive().bg_fill) 22 .inner_margin(egui::Margin::same(4)) 23 .corner_radius(egui::CornerRadius::same(10)) 24 .stroke(egui::Stroke::new( 25 1.0, 26 ui.visuals().noninteractive().bg_stroke.color, 27 )) 28 .show(ui, |ui| { 29 egui::Frame::new() 30 .fill(ui.visuals().noninteractive().weak_bg_fill) 31 .inner_margin(egui::Margin::same(4)) 32 .corner_radius(egui::CornerRadius::same(10)) 33 .stroke(egui::Stroke::new( 34 1.0, 35 ui.visuals().noninteractive().bg_stroke.color, 36 )) 37 .show(ui, |ui| { 38 ui.label(name); 39 }); 40 41 value(ui); 42 }); 43 }