Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed Aug 8, 2023
1 parent 1148f85 commit b7470ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
37 changes: 30 additions & 7 deletions examples/myapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,41 @@ impl eframe::App for MyApp {
let ctx_clone = ctx.clone();

// Draw the actual map.
let response = ui.add(
ui.add(
Map::new(Some(&mut self.tiles), &mut self.map_memory, my_position).with_drawer(
move |painter, map_memory, position, project| {
draw_custom_shapes(ctx_clone.clone(), painter, map_memory, my_position);
move |painter, project| {
//draw_custom_shapes(ctx_clone.clone(), painter, map_memory, my_position);
let ctx = ctx_clone.clone();

// Position of the point we want to put our shapes.
let position = places::dworcowa_bus_stop();
let screen_position = project(position);

// Now we can just use Painter to draw stuff.
let background = |text: &Shape| {
Shape::rect_filled(
text.visual_bounding_rect().expand(5.),
5.,
ctx.style().visuals.extreme_bg_color,
)
};

let text = ctx.fonts(|fonts| {
Shape::text(
fonts,
screen_position.to_pos2(),
Align2::LEFT_CENTER,
"⬉ Here you can board the 106 line\nwhich goes to the airport.",
Default::default(),
ctx.style().visuals.text_color(),
)
});
painter.add(background(&text));
painter.add(text);
},
),
);

// Draw custom shapes.
//let painter = ui.painter().with_clip_rect(response.rect);
//draw_custom_shapes(ui, painter, &self.map_memory, my_position);

// Draw utility windows.
{
use windows::*;
Expand Down
6 changes: 3 additions & 3 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Map<'a, 'b> {
tiles: Option<&'b mut Tiles>,
memory: &'a mut MapMemory,
my_position: Position,
drawer: Option<Box<dyn Fn(Painter, &MapMemory, Position, &dyn Fn(Position) -> Vec2)>>,
drawer: Option<Box<dyn Fn(Painter, &dyn Fn(Position) -> Vec2)>>,
}

impl<'a, 'b> Map<'a, 'b> {
Expand All @@ -46,7 +46,7 @@ impl<'a, 'b> Map<'a, 'b> {

pub fn with_drawer<D>(mut self, drawer: D) -> Self
where
D: Fn(Painter, &MapMemory, Position, &dyn Fn(Position) -> Vec2) + 'static,
D: Fn(Painter, &dyn Fn(Position) -> Vec2) + 'static,
{
self.drawer = Some(Box::new(drawer));
self
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Widget for Map<'_, '_> {

if let Some(drawer) = self.drawer {
let painter = ui.painter().with_clip_rect(response.rect);
drawer(painter, &self.memory, self.my_position, &|position| {
drawer(painter, &|position| {
screen_position(
position,
&ui.painter().with_clip_rect(response.rect),
Expand Down

0 comments on commit b7470ed

Please sign in to comment.