mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
make label into a macro
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use emigui::{math::*, types::*, widgets::*, Align, Region, TextStyle};
|
||||
use emigui::{label, math::*, types::*, widgets::*, Align, Region, TextStyle};
|
||||
|
||||
pub struct App {
|
||||
checked: bool,
|
||||
@@ -25,62 +25,46 @@ impl Default for App {
|
||||
|
||||
impl App {
|
||||
pub fn show_gui(&mut self, gui: &mut Region) {
|
||||
gui.add(label("Emigui").text_style(TextStyle::Heading));
|
||||
gui.add(label("Emigui is an Immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL."));
|
||||
gui.add(label!("Emigui").text_style(TextStyle::Heading));
|
||||
gui.add(label!("Emigui is an Immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL."));
|
||||
gui.add(Separator::new());
|
||||
|
||||
gui.add(label(format!(
|
||||
"Screen size: {} x {}, pixels_per_point: {}",
|
||||
gui.input().screen_size.x,
|
||||
gui.input().screen_size.y,
|
||||
gui.input().pixels_per_point,
|
||||
)));
|
||||
gui.add(label(format!(
|
||||
"mouse_pos: {} x {}",
|
||||
gui.input().mouse_pos.x,
|
||||
gui.input().mouse_pos.y,
|
||||
)));
|
||||
gui.add(label(format!(
|
||||
"gui cursor: {} x {}",
|
||||
gui.cursor().x,
|
||||
gui.cursor().y,
|
||||
)));
|
||||
gui.foldable("Widget examples", |gui| {
|
||||
gui.horizontal(Align::Min, |gui| {
|
||||
gui.add(label!("Text can have").text_color(srgba(110, 255, 110, 255)));
|
||||
gui.add(label!("color").text_color(srgba(128, 140, 255, 255)));
|
||||
gui.add(label!("and tooltips (hover me)")).tooltip_text(
|
||||
"This is a multiline tooltip that demonstrates that you can easily add tooltips to any element.\nThis is the second line.\nThis is the third.",
|
||||
);
|
||||
});
|
||||
|
||||
gui.horizontal(Align::Min, |gui| {
|
||||
gui.add(label("Text can have").text_color(srgba(110, 255, 110, 255)));
|
||||
gui.add(label("color").text_color(srgba(128, 140, 255, 255)));
|
||||
});
|
||||
gui.add(Checkbox::new(&mut self.checked, "checkbox"));
|
||||
|
||||
gui.add(label("Hover me")).tooltip_text(
|
||||
"This is a multiline tooltip that demonstrates that you can easily add tooltips to any element.\nThis is the second line.\nThis is the third.",
|
||||
);
|
||||
gui.horizontal(Align::Min, |gui| {
|
||||
if gui.add(radio(self.radio == 0, "First")).clicked {
|
||||
self.radio = 0;
|
||||
}
|
||||
if gui.add(radio(self.radio == 1, "Second")).clicked {
|
||||
self.radio = 1;
|
||||
}
|
||||
if gui.add(radio(self.radio == 2, "Final")).clicked {
|
||||
self.radio = 2;
|
||||
}
|
||||
});
|
||||
|
||||
gui.add(Checkbox::new(&mut self.checked, "checkbox"));
|
||||
|
||||
gui.horizontal(Align::Min, |gui| {
|
||||
if gui.add(radio(self.radio == 0, "First")).clicked {
|
||||
self.radio = 0;
|
||||
}
|
||||
if gui.add(radio(self.radio == 1, "Second")).clicked {
|
||||
self.radio = 1;
|
||||
}
|
||||
if gui.add(radio(self.radio == 2, "Final")).clicked {
|
||||
self.radio = 2;
|
||||
}
|
||||
});
|
||||
|
||||
gui.horizontal(Align::Min, |gui| {
|
||||
if gui
|
||||
.add(Button::new("Click me"))
|
||||
.tooltip_text("This will just increase a counter.")
|
||||
.clicked
|
||||
{
|
||||
self.count += 1;
|
||||
}
|
||||
gui.add(label(format!(
|
||||
"The button have been clicked {} times",
|
||||
self.count
|
||||
)));
|
||||
gui.horizontal(Align::Min, |gui| {
|
||||
if gui
|
||||
.add(Button::new("Click me"))
|
||||
.tooltip_text("This will just increase a counter.")
|
||||
.clicked
|
||||
{
|
||||
self.count += 1;
|
||||
}
|
||||
gui.add(label!(
|
||||
"The button have been clicked {} times",
|
||||
self.count
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
gui.foldable("Test box rendering", |gui| {
|
||||
|
||||
@@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
||||
|
||||
extern crate emigui;
|
||||
|
||||
use emigui::{widgets::label, Align, Emigui, RawInput};
|
||||
use emigui::{label, widgets::Label, Align, Emigui, RawInput};
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -48,12 +48,12 @@ impl State {
|
||||
self.app.show_gui(&mut region);
|
||||
self.emigui.example(&mut region);
|
||||
|
||||
region.add(label("WebGl painter info:"));
|
||||
region.add(label!("WebGl painter info:"));
|
||||
region.indent(|region| {
|
||||
region.add(label(self.webgl_painter.debug_info()));
|
||||
region.add(label!(self.webgl_painter.debug_info()));
|
||||
});
|
||||
|
||||
region.add(label(format!("Everything: {:.1} ms", self.everything_ms)));
|
||||
region.add(label!("Everything: {:.1} ms", self.everything_ms));
|
||||
|
||||
let frame = self.emigui.paint();
|
||||
let result =
|
||||
|
||||
@@ -49,8 +49,8 @@ impl Painter {
|
||||
gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture));
|
||||
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32);
|
||||
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32);
|
||||
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::NEAREST as i32);
|
||||
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::NEAREST as i32);
|
||||
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32);
|
||||
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user