diff --git a/walkers/src/extras/images.rs b/walkers/src/extras/images.rs index c3f2a44..dd34432 100644 --- a/walkers/src/extras/images.rs +++ b/walkers/src/extras/images.rs @@ -14,6 +14,7 @@ pub struct Image { } impl Image { + /// Create a new image. pub fn new(texture: Texture, position: Position) -> Self { Self { position, @@ -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(), @@ -54,6 +56,7 @@ pub struct Images { } impl Images { + /// Create a new [`Images`] plugin. pub fn new(images: Vec) -> Self { Self { images } } diff --git a/walkers/src/extras/places.rs b/walkers/src/extras/places.rs index b735917..728c72d 100644 --- a/walkers/src/extras/places.rs +++ b/walkers/src/extras/places.rs @@ -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, } @@ -96,6 +103,7 @@ pub struct Places { } impl Places { + /// Create a new [`Places`] plugin. pub fn new(places: Vec) -> Self { Self { places } } diff --git a/walkers/src/lib.rs b/walkers/src/lib.rs index 19c639c..3443780 100644 --- a/walkers/src/lib.rs +++ b/walkers/src/lib.rs @@ -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; diff --git a/walkers/src/map.rs b/walkers/src/map.rs index 528b85f..1d265d4 100644 --- a/walkers/src/map.rs +++ b/walkers/src/map.rs @@ -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, @@ -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 ctrl key on native @@ -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, diff --git a/walkers/src/mercator.rs b/walkers/src/mercator.rs index 632585d..0397c8e 100644 --- a/walkers/src/mercator.rs +++ b/walkers/src/mercator.rs @@ -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() } @@ -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 { Some(TileId { x: self.x + 1, @@ -134,6 +137,7 @@ impl TileId { }) } + /// Move to west pub fn west(&self) -> Option { Some(TileId { x: self.x.checked_sub(1)?, @@ -142,6 +146,7 @@ impl TileId { }) } + /// Move to north pub fn north(&self) -> Option { Some(TileId { x: self.x, @@ -150,6 +155,7 @@ impl TileId { }) } + /// Move to south pub fn south(&self) -> Option { Some(TileId { x: self.x, diff --git a/walkers/src/sources/mapbox.rs b/walkers/src/sources/mapbox.rs index ee6a9eb..5f135fd 100644 --- a/walkers/src/sources/mapbox.rs +++ b/walkers/src/sources/mapbox.rs @@ -6,14 +6,22 @@ use super::{Attribution, TileSource}; /// #[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, } diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index c0e5f6c..76a3cf2 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -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>, + /// Dark version of the logo. pub logo_dark: Option>, } /// 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. diff --git a/walkers/src/tiles.rs b/walkers/src/tiles.rs index 7b5625b..2247a60 100644 --- a/walkers/src/tiles.rs +++ b/walkers/src/tiles.rs @@ -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 { let image = image::load_from_memory(image)?.to_rgba8(); let pixels = image.as_flat_samples(); @@ -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; + + /// Attribution of the source this tile cache pulls images from fn attribution(&self) -> Attribution; + + /// Size of each tile fn tile_size(&self) -> u32; } diff --git a/walkers/src/zoom.rs b/walkers/src/zoom.rs index 830e24f..de84b77 100644 --- a/walkers/src/zoom.rs +++ b/walkers/src/zoom.rs @@ -1,3 +1,4 @@ +/// Invalid Zoom. #[derive(thiserror::Error, Debug, PartialEq, Eq)] #[error("invalid zoom level")] pub struct InvalidZoom;