egui/eframe/examples/hello_world.rs
Emil Ernerfeldt 247026149c
Multiple mouse button support (#135)
Add support for primary, secondary and middle mouse buttons. Also improve ability to click things in low FPS situations.

This introduces a lot of breaking changes:

    Backends/integrations now pass mouse events via the even stream.
    Response has an interface of mostly methods instead of public members.
    input.mouse is now input.pointer and has new interface.


* Rename 'mouse' to 'pointer' everywhere (pointer = mouse or touch)

* Make Response::clicked and Response::double_clicked into methods

* Remove Response::active and add dragged() and interact_pointer_pos()

* Support multiple mouse buttons

* Make PointerState interface all methods

* Make most members of Response private
2021-01-25 18:50:19 +01:00

45 lines
1.1 KiB
Rust

use eframe::{egui, epi};
struct MyApp {
name: String,
age: u32,
}
impl Default for MyApp {
fn default() -> Self {
Self {
name: "Arthur".to_owned(),
age: 42,
}
}
}
impl epi::App for MyApp {
fn name(&self) -> &str {
"My egui App"
}
fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
let Self { name, age } = self;
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("My egui Application");
ui.horizontal(|ui| {
ui.label("Your name: ");
ui.text_edit_singleline(name);
});
ui.add(egui::Slider::u32(age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
*age += 1;
}
ui.label(format!("Hello '{}', age {}", name, age));
});
// Resize the native window to be just the size we need it to be:
frame.set_window_size(ctx.used_size());
}
}
fn main() {
eframe::run_native(Box::new(MyApp::default()));
}