Skip to content

Commit

Permalink
Merge pull request #77 from podusowski/response-in-plugins
Browse files Browse the repository at this point in the history
Plugins now have access to Response
  • Loading branch information
podusowski authored Nov 25, 2023
2 parents 06bc2a3 + f41da33 commit 9e901b9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
* Allow structs implementing `Provider` to use larger tile sizes.
* Add optional logos to `Attribution` struct.
* Add `Mapbox` provider.
* `Plugin::draw` now has a `Response` parameter, allowing plugins to be interactive.

## 0.12.0

Expand Down
4 changes: 2 additions & 2 deletions demo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::{Color32, Context, Painter};
use egui::{Color32, Context, Painter, Response};
use walkers::{
extras::{Image, Images, Place, Places, Style, Texture},
Map, MapMemory, Plugin, Projector, Tiles,
Expand Down Expand Up @@ -191,7 +191,7 @@ mod places {
struct CustomShapes {}

impl Plugin for CustomShapes {
fn draw(&self, painter: Painter, projector: &Projector) {
fn draw(&self, _response: &Response, painter: Painter, projector: &Projector) {
// Position of the point we want to put our shapes.
let position = places::capitol();

Expand Down
4 changes: 2 additions & 2 deletions walkers/src/extras/images.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::tiles::Texture;
use crate::{Plugin, Position};
use egui::epaint::emath::Rot2;
use egui::{Rect, Vec2};
use egui::{Painter, Rect, Response, Vec2};

/// An image to be drawn on the map.
pub struct Image {
Expand Down Expand Up @@ -47,7 +47,7 @@ impl Images {
}

impl Plugin for Images {
fn draw(&self, painter: egui::Painter, projector: &crate::Projector) {
fn draw(&self, _response: &Response, painter: Painter, projector: &crate::Projector) {
for image in &self.images {
let rect = Rect::from_center_size(
projector.project(image.position).to_pos2(),
Expand Down
4 changes: 2 additions & 2 deletions walkers/src/extras/places.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::{vec2, Align2, Color32, FontId, Stroke};
use egui::{vec2, Align2, Color32, FontId, Painter, Response, Stroke};

use crate::{Plugin, Position};

Expand Down Expand Up @@ -56,7 +56,7 @@ impl Places {
}

impl Plugin for Places {
fn draw(&self, painter: egui::Painter, projector: &crate::Projector) {
fn draw(&self, _response: &Response, painter: Painter, projector: &crate::Projector) {
for place in &self.places {
let screen_position = projector.project(place.position);

Expand Down
4 changes: 2 additions & 2 deletions walkers/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// you can add it to the map with [`Map::with_plugin`]
pub trait Plugin {
/// Function called at each frame.
fn draw(&self, painter: Painter, projector: &Projector);
fn draw(&self, response: &Response, painter: Painter, projector: &Projector);
}

/// The actual map widget. Instances are to be created on each frame, as all necessary state is
Expand Down Expand Up @@ -171,7 +171,7 @@ impl Widget for Map<'_, '_> {
my_position: self.my_position,
};

plugin.draw(painter.to_owned(), &projector);
plugin.draw(&response, painter.to_owned(), &projector);
}

response
Expand Down

0 comments on commit 9e901b9

Please sign in to comment.