mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 12:50:04 -04:00
make label into a macro
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
layout,
|
||||
label, layout,
|
||||
layout::{show_popup, LayoutOptions, Region},
|
||||
math::{clamp, remap_clamp, vec2},
|
||||
mesher::Vertex,
|
||||
@@ -47,10 +47,11 @@ fn show_font_sizes(font_sizes: &mut FontSizes, gui: &mut Region) {
|
||||
}
|
||||
|
||||
fn show_font_texture(texture: &Texture, gui: &mut Region) {
|
||||
gui.add(label(format!(
|
||||
gui.add(label!(
|
||||
"Font texture size: {} x {} (hover to zoom)",
|
||||
texture.width, texture.height
|
||||
)));
|
||||
texture.width,
|
||||
texture.height
|
||||
));
|
||||
let mut size = vec2(texture.width as f32, texture.height as f32);
|
||||
if size.x > gui.width() {
|
||||
size *= gui.width() / size.x;
|
||||
@@ -192,11 +193,24 @@ impl Emigui {
|
||||
});
|
||||
|
||||
region.foldable("Stats", |gui| {
|
||||
gui.add(label(format!("num_vertices: {}", self.stats.num_vertices)));
|
||||
gui.add(label(format!(
|
||||
"num_triangles: {}",
|
||||
self.stats.num_triangles
|
||||
)));
|
||||
gui.add(label!(
|
||||
"Screen size: {} x {} points, pixels_per_point: {}",
|
||||
gui.input().screen_size.x,
|
||||
gui.input().screen_size.y,
|
||||
gui.input().pixels_per_point,
|
||||
));
|
||||
gui.add(label!(
|
||||
"mouse_pos: {} x {}",
|
||||
gui.input().mouse_pos.x,
|
||||
gui.input().mouse_pos.y,
|
||||
));
|
||||
gui.add(label!(
|
||||
"gui cursor: {} x {}",
|
||||
gui.cursor().x,
|
||||
gui.cursor().y,
|
||||
));
|
||||
gui.add(label!("num_vertices: {}", self.stats.num_vertices));
|
||||
gui.add(label!("num_triangles: {}", self.stats.num_triangles));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
fonts::{Fonts, TextStyle},
|
||||
math::*,
|
||||
types::*,
|
||||
widgets::{label, Widget},
|
||||
widgets::{Label, Widget},
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -85,7 +85,7 @@ impl GuiResponse {
|
||||
/// Show this text if the item was hovered
|
||||
pub fn tooltip_text<S: Into<String>>(&mut self, text: S) -> &mut Self {
|
||||
self.tooltip(|popup| {
|
||||
popup.add(label(text));
|
||||
popup.add(Label::new(text));
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -437,8 +437,8 @@ impl Region {
|
||||
/// Temporarily split split a vertical layout into several columns.
|
||||
///
|
||||
/// region.columns(2, |columns| {
|
||||
/// columns[0].add(emigui::widgets::label("First column"));
|
||||
/// columns[1].add(emigui::widgets::label("Second column"));
|
||||
/// columns[0].add(emigui::widgets::label!("First column"));
|
||||
/// columns[1].add(emigui::widgets::label!("Second column"));
|
||||
/// });
|
||||
pub fn columns<F, R>(&mut self, num_columns: usize, add_contents: F) -> R
|
||||
where
|
||||
|
||||
@@ -40,8 +40,11 @@ impl Label {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn label<S: Into<String>>(text: S) -> Label {
|
||||
Label::new(text)
|
||||
/// Usage: label!("Foo: {}", bar)
|
||||
#[macro_export]
|
||||
macro_rules! label {
|
||||
($fmt:expr) => (Label::new($fmt));
|
||||
($fmt:expr, $($arg:tt)*) => (Label::new(format!($fmt, $($arg)*)));
|
||||
}
|
||||
|
||||
impl Widget for Label {
|
||||
@@ -264,7 +267,7 @@ impl<'a> Widget for Slider<'a> {
|
||||
|
||||
columns[1].available_space.y = response.rect.size().y;
|
||||
columns[1].horizontal(Align::Center, |region| {
|
||||
region.add(label(full_text));
|
||||
region.add(Label::new(full_text));
|
||||
});
|
||||
|
||||
response
|
||||
|
||||
Reference in New Issue
Block a user