forked from Maximkaaa/galileo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add egui example * Add interactions of map with egui --------- Co-authored-by: Maxim <maxim@gritsenko.biz>
- Loading branch information
Showing
15 changed files
with
815 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"galileo", | ||
"galileo-mvt", | ||
"galileo-types", | ||
] | ||
resolver = "2" | ||
|
||
exclude = [ | ||
"galileo/examples/with_egui", | ||
"wasm_examples/raster_tiles", | ||
"wasm_examples/vector_tiles", | ||
"wasm_examples/feature_layers", | ||
"wasm_examples/many_points", | ||
"wasm_examples/lambert", | ||
"wasm_examples/with_egui", | ||
] | ||
|
||
[workspace.package] | ||
version = "0.1.0-alpha.0" | ||
authors = ["Maxim Gritsenko <maxim@gritsenko.biz>"] | ||
categories = ["science::geo"] | ||
edition = "2021" | ||
repository = "https://github.com/Maximkaaa/galileo" | ||
license = "MIT OR Apache-2.0" | ||
keywords = ["gis", "map", "rendering"] | ||
categories = ["science::geo"] | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/Maximkaaa/galileo" | ||
version = "0.1.0-alpha.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
edition = "2021" | ||
name = "with_egui" | ||
version = "0.1.0" | ||
|
||
[workspace] | ||
|
||
[[bin]] | ||
name = "with_egui" | ||
|
||
[dependencies] | ||
egui = "0.25.0" | ||
egui-wgpu = "0.25.0" | ||
egui-winit = { version = "0.25.0", default-features = false } | ||
env_logger = { version = "0.11", default-features = false } | ||
galileo = { path = "../../../galileo" } | ||
galileo-types = { path = "../../../galileo-types" } | ||
wgpu = { version = "0.18", default-features = false } | ||
winit = { version = "0.29", default-features = false } | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
tokio = { version = "1.0", default-features = false, features = ["full"] } | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.egui-winit] | ||
features = ["clipboard", "links", "wayland", "x11"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::sync::Arc; | ||
|
||
use winit::{ | ||
event::{Event, KeyEvent, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
window::Window, | ||
}; | ||
|
||
mod run_ui; | ||
mod state; | ||
|
||
pub async fn run(window: Window, event_loop: EventLoop<()>) { | ||
let window = Arc::new(window); | ||
|
||
let mut state = state::State::new(Arc::clone(&window)).await; | ||
|
||
let _ = event_loop.run(move |event, ewlt| { | ||
ewlt.set_control_flow(ControlFlow::Wait); | ||
|
||
match event { | ||
Event::AboutToWait => { | ||
state.about_to_wait(); | ||
} | ||
Event::WindowEvent { | ||
ref event, | ||
window_id, | ||
} if window_id == state.window().id() => { | ||
match event { | ||
WindowEvent::CloseRequested | ||
| WindowEvent::KeyboardInput { | ||
event: | ||
KeyEvent { | ||
logical_key: | ||
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape), | ||
.. | ||
}, | ||
.. | ||
} => ewlt.exit(), | ||
WindowEvent::Resized(physical_size) => { | ||
state.resize(*physical_size); | ||
} | ||
WindowEvent::RedrawRequested => match state.render() { | ||
Ok(_) => {} | ||
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => { | ||
state.resize(state.size) | ||
} | ||
Err(wgpu::SurfaceError::OutOfMemory) => ewlt.exit(), | ||
Err(wgpu::SurfaceError::Timeout) => { | ||
// Ignore timeouts. | ||
} | ||
}, | ||
other => { | ||
state.handle_event(other); | ||
window.request_redraw(); | ||
return; | ||
} | ||
}; | ||
state.handle_event(event); | ||
window.request_redraw(); | ||
} | ||
_ => {} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
mod run_ui; | ||
mod state; | ||
|
||
use with_egui::run; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); | ||
|
||
let event_loop = winit::event_loop::EventLoop::new().unwrap(); | ||
let window = winit::window::WindowBuilder::new() | ||
.with_title("egui + galileo") | ||
.build(&event_loop) | ||
.unwrap(); | ||
|
||
run(window, event_loop).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use egui::Context; | ||
use galileo_types::geo::impls::point::GeoPoint2d; | ||
use galileo_types::geo::traits::point::GeoPoint; | ||
|
||
#[derive(Clone, Default, Debug)] | ||
pub struct UiState { | ||
pub positions: Positions, | ||
} | ||
|
||
#[derive(Clone, Default, Debug)] | ||
pub struct Positions { | ||
pub pointer_position: Option<GeoPoint2d>, | ||
pub map_center_position: Option<GeoPoint2d>, | ||
} | ||
|
||
pub fn run_ui(state: &mut UiState, ui: &Context) { | ||
egui::Window::new("Galileo map").show(ui, |ui| { | ||
ui.label("Pointer position:"); | ||
if let Some(pointer_position) = state.positions.pointer_position { | ||
ui.label(format!( | ||
"Lat: {:.4} Lon: {:.4}", | ||
pointer_position.lat(), | ||
pointer_position.lon() | ||
)); | ||
} else { | ||
ui.label("<unavaliable>"); | ||
} | ||
|
||
ui.separator(); | ||
|
||
ui.label("Map center position:"); | ||
if let Some(map_center_position) = state.positions.map_center_position { | ||
ui.label(format!( | ||
"Lat: {:.4} Lon: {:.4}", | ||
map_center_position.lat(), | ||
map_center_position.lon() | ||
)); | ||
} else { | ||
ui.label("<unavaliable>"); | ||
} | ||
}); | ||
} |
Oops, something went wrong.