Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom + docs #161

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions walkers/src/extras/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Image {
}

impl Image {
/// Create a new image.
pub fn new(texture: Texture, position: Position) -> Self {
Self {
position,
Expand All @@ -34,6 +35,7 @@ impl Image {
self.angle = Rot2::from_angle(angle);
}

/// Draw the image.
pub fn draw(&self, _response: &Response, painter: Painter, projector: &crate::Projector) {
let rect = Rect::from_center_size(
projector.project(self.position).to_pos2(),
Expand All @@ -54,6 +56,7 @@ pub struct Images {
}

impl Images {
/// Create a new [`Images`] plugin.
pub fn new(images: Vec<Image>) -> Self {
Self { images }
}
Expand Down
8 changes: 8 additions & 0 deletions walkers/src/extras/places.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ use crate::{Plugin, Position};
/// Visual style of the place.
#[derive(Clone)]
pub struct Style {
/// Font used for the label.
pub label_font: FontId,
/// Color of the label.
pub label_color: Color32,
/// Background color of the label.
pub label_background: Color32,
/// Font used for the symbol.
pub symbol_font: FontId,
/// Color of the symbol.
pub symbol_color: Color32,
/// Background color of the symbol.
pub symbol_background: Color32,
/// Stroke of the symbol.
pub symbol_stroke: Stroke,
}

Expand Down Expand Up @@ -96,6 +103,7 @@ pub struct Places {
}

impl Places {
/// Create a new [`Places`] plugin.
pub fn new(places: Vec<Place>) -> Self {
Self { places }
}
Expand Down
2 changes: 1 addition & 1 deletion walkers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![doc = include_str!("../README.md")]
#![deny(clippy::unwrap_used, rustdoc::broken_intra_doc_links)]
#![deny(missing_docs, clippy::unwrap_used, rustdoc::broken_intra_doc_links)]

mod center;
mod download;
Expand Down
8 changes: 8 additions & 0 deletions walkers/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Map<'a, 'b, 'c> {
}

impl<'a, 'b, 'c> Map<'a, 'b, 'c> {
/// Create a new map widget.
pub fn new(
tiles: Option<&'b mut dyn Tiles>,
memory: &'a mut MapMemory,
Expand All @@ -65,6 +66,12 @@ impl<'a, 'b, 'c> Map<'a, 'b, 'c> {
self
}

/// Set tiles manager to be used by the map.
pub fn with_tiles_manager(mut self, tiles: &'b mut dyn Tiles) -> Self {
self.tiles = Some(tiles);
self
}

/// Set whether map should perform zoom gesture.
///
/// Zoom is typically triggered by the mouse wheel while holding <kbd>ctrl</kbd> key on native
Expand All @@ -90,6 +97,7 @@ pub struct Projector {
}

impl Projector {
/// Create a new projector.
pub fn new(clip_rect: Rect, map_memory: &MapMemory, my_position: Position) -> Self {
Self {
clip_rect,
Expand Down
6 changes: 6 additions & 0 deletions walkers/src/mercator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ impl Position {
Self(geo_types::Point::new(lon, lat))
}

/// Latitude
pub fn lat(&self) -> f64 {
self.0.y()
}

/// Longitude
pub fn lon(&self) -> f64 {
self.0.x()
}
Expand Down Expand Up @@ -126,6 +128,7 @@ impl TileId {
Pixels::new(self.x as f64 * tile_size, self.y as f64 * tile_size)
}

/// Move to east
pub fn east(&self) -> Option<TileId> {
Some(TileId {
x: self.x + 1,
Expand All @@ -134,6 +137,7 @@ impl TileId {
})
}

/// Move to west
pub fn west(&self) -> Option<TileId> {
Some(TileId {
x: self.x.checked_sub(1)?,
Expand All @@ -142,6 +146,7 @@ impl TileId {
})
}

/// Move to north
pub fn north(&self) -> Option<TileId> {
Some(TileId {
x: self.x,
Expand All @@ -150,6 +155,7 @@ impl TileId {
})
}

/// Move to south
pub fn south(&self) -> Option<TileId> {
Some(TileId {
x: self.x,
Expand Down
8 changes: 8 additions & 0 deletions walkers/src/sources/mapbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ use super::{Attribution, TileSource};
/// <https://docs.mapbox.com/api/maps/styles/#classic-mapbox-styles>
#[derive(Clone, Copy, Default)]
pub enum MapboxStyle {
/// Streets Style (default)
#[default]
Streets,
/// Outdoors Style
Outdoors,
/// Light Style
Light,
/// Dark Style
Dark,
/// Satellite Style
Satellite,
/// Satellite Streets Style
SatelliteStreets,
/// Navigation Day Style
NavigationDay,
/// Navigation Night Style
NavigationNight,
}

Expand Down
7 changes: 7 additions & 0 deletions walkers/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ pub use mapbox::{Mapbox, MapboxStyle};
pub use openstreetmap::OpenStreetMap;

#[derive(Clone)]
/// Attribution information for the tile source.
pub struct Attribution {
/// Attribution text.
pub text: &'static str,
/// URL to the attribution source.
pub url: &'static str,
/// Logo for the attribution.
pub logo_light: Option<egui::ImageSource<'static>>,
/// Dark version of the logo.
pub logo_dark: Option<egui::ImageSource<'static>>,
}

/// Remote tile server definition, source for the [`crate::HttpTiles`].
pub trait TileSource {
/// URL for the tile with the given id.
fn tile_url(&self, tile_id: TileId) -> String;
/// Attribution information for the tile source.
fn attribution(&self) -> Attribution;

/// Size of each tile, should be a multiple of 256.
Expand Down
8 changes: 8 additions & 0 deletions walkers/src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ pub(crate) fn rect(screen_position: Vec2, tile_size: f64) -> Rect {
Rect::from_min_size(screen_position.to_pos2(), Vec2::splat(tile_size as f32))
}

/// Texture handle with a size.
#[derive(Clone)]
pub struct Texture(TextureHandle);

impl Texture {
/// Load the texture from the image bytes.
pub fn new(image: &[u8], ctx: &Context) -> Result<Self, ImageError> {
let image = image::load_from_memory(image)?.to_rgba8();
let pixels = image.as_flat_samples();
Expand Down Expand Up @@ -51,9 +53,15 @@ impl Texture {
}
}

/// Manages the tiles cache and downloads the missing ones.
pub trait Tiles {
/// Get the tile at the given `TileId`
fn at(&mut self, tile_id: TileId) -> Option<Texture>;

/// Attribution of the source this tile cache pulls images from
fn attribution(&self) -> Attribution;

/// Size of each tile
fn tile_size(&self) -> u32;
}

Expand Down
1 change: 1 addition & 0 deletions walkers/src/zoom.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Invalid Zoom.
#[derive(thiserror::Error, Debug, PartialEq, Eq)]
#[error("invalid zoom level")]
pub struct InvalidZoom;
Expand Down
Loading