mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Simplify window traits
This commit is contained in:
parent
1e63718dfc
commit
355977e3b7
@ -33,16 +33,9 @@ impl MapWindowConfig for HeadlessMapWindowConfig {
|
|||||||
pub struct HeadlessMapWindow;
|
pub struct HeadlessMapWindow;
|
||||||
|
|
||||||
impl MapWindow for HeadlessMapWindow {
|
impl MapWindow for HeadlessMapWindow {
|
||||||
type EventLoop = ();
|
|
||||||
type RawWindow = ();
|
|
||||||
|
|
||||||
fn size(&self) -> WindowSize {
|
fn size(&self) -> WindowSize {
|
||||||
WindowSize::new(1920, 1080).unwrap()
|
WindowSize::new(1920, 1080).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inner(&self) -> &Self::RawWindow {
|
|
||||||
&()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MWC, SM, HC> Runnable<MWC, SM, HC> for HeadlessMapWindow
|
impl<MWC, SM, HC> Runnable<MWC, SM, HC> for HeadlessMapWindow
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use winit::event_loop::ControlFlow;
|
|||||||
|
|
||||||
use crate::input::{InputController, UpdateState};
|
use crate::input::{InputController, UpdateState};
|
||||||
use maplibre::map_schedule::MapSchedule;
|
use maplibre::map_schedule::MapSchedule;
|
||||||
use maplibre::window::{MapWindow, MapWindowConfig, Runnable};
|
use maplibre::window::{HeadedMapWindow, MapWindow, MapWindowConfig, Runnable};
|
||||||
use winit::event::Event;
|
use winit::event::Event;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
|||||||
@ -10,12 +10,9 @@ use super::WinitMapWindow;
|
|||||||
use super::WinitWindow;
|
use super::WinitWindow;
|
||||||
|
|
||||||
use super::WinitMapWindowConfig;
|
use super::WinitMapWindowConfig;
|
||||||
use maplibre::window::{MapWindow, MapWindowConfig, WindowSize};
|
use maplibre::window::{HeadedMapWindow, MapWindow, MapWindowConfig, WindowSize};
|
||||||
|
|
||||||
impl MapWindow for WinitMapWindow {
|
impl MapWindow for WinitMapWindow {
|
||||||
type EventLoop = WinitEventLoop;
|
|
||||||
type RawWindow = WinitWindow;
|
|
||||||
|
|
||||||
fn size(&self) -> WindowSize {
|
fn size(&self) -> WindowSize {
|
||||||
let size = self.window.inner_size();
|
let size = self.window.inner_size();
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
@ -29,6 +26,10 @@ impl MapWindow for WinitMapWindow {
|
|||||||
WindowSize::new(size.width, size.height).expect("failed to get window dimensions.");
|
WindowSize::new(size.width, size.height).expect("failed to get window dimensions.");
|
||||||
window_size
|
window_size
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
impl HeadedMapWindow for WinitMapWindow {
|
||||||
|
type EventLoop = WinitEventLoop;
|
||||||
|
type RawWindow = WinitWindow;
|
||||||
|
|
||||||
fn inner(&self) -> &Self::RawWindow {
|
fn inner(&self) -> &Self::RawWindow {
|
||||||
&self.window
|
&self.window
|
||||||
|
|||||||
@ -22,7 +22,7 @@ use crate::map_schedule::MapSchedule;
|
|||||||
use crate::render::settings::{RendererSettings, WgpuSettings};
|
use crate::render::settings::{RendererSettings, WgpuSettings};
|
||||||
use crate::render::{RenderState, Renderer};
|
use crate::render::{RenderState, Renderer};
|
||||||
use crate::style::Style;
|
use crate::style::Style;
|
||||||
use crate::window::{HasRawWindow, MapWindow, MapWindowConfig, Runnable, WindowSize};
|
use crate::window::{HeadedMapWindow, MapWindow, MapWindowConfig, Runnable, WindowSize};
|
||||||
|
|
||||||
pub mod context;
|
pub mod context;
|
||||||
pub mod coords;
|
pub mod coords;
|
||||||
|
|||||||
@ -27,7 +27,7 @@ use crate::render::shaders::{ShaderFeatureStyle, ShaderLayerMetadata};
|
|||||||
use crate::render::tile_view_pattern::{TileInView, TileShape, TileViewPattern};
|
use crate::render::tile_view_pattern::{TileInView, TileShape, TileViewPattern};
|
||||||
use crate::render::util::Eventually;
|
use crate::render::util::Eventually;
|
||||||
use crate::tessellation::IndexDataType;
|
use crate::tessellation::IndexDataType;
|
||||||
use crate::{HasRawWindow, MapWindow, MapWindowConfig};
|
use crate::{HeadedMapWindow, MapWindow, MapWindowConfig};
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -122,10 +122,8 @@ impl Renderer {
|
|||||||
settings: RendererSettings,
|
settings: RendererSettings,
|
||||||
) -> Result<Self, wgpu::RequestDeviceError>
|
) -> Result<Self, wgpu::RequestDeviceError>
|
||||||
where
|
where
|
||||||
MWC::MapWindow: HasRawWindow,
|
|
||||||
MWC: MapWindowConfig,
|
MWC: MapWindowConfig,
|
||||||
/* <<MWC as MapWindowConfig>::MapWindow as MapWindow>::Window:
|
<MWC as MapWindowConfig>::MapWindow: HeadedMapWindow,
|
||||||
raw_window_handle::HasRawWindowHandle,*/
|
|
||||||
{
|
{
|
||||||
let instance = wgpu::Instance::new(wgpu_settings.backends.unwrap_or(wgpu::Backends::all()));
|
let instance = wgpu::Instance::new(wgpu_settings.backends.unwrap_or(wgpu::Backends::all()));
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,8 @@
|
|||||||
use crate::render::resource::texture::TextureView;
|
use crate::render::resource::texture::TextureView;
|
||||||
use crate::render::settings::RendererSettings;
|
use crate::render::settings::RendererSettings;
|
||||||
use crate::render::util::HasChanged;
|
use crate::render::util::HasChanged;
|
||||||
use crate::{HasRawWindow, MapWindow, MapWindowConfig, WindowSize};
|
use crate::window::HeadedMapWindow;
|
||||||
|
use crate::{MapWindow, MapWindowConfig, WindowSize};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
@ -46,8 +47,7 @@ impl WindowHead {
|
|||||||
pub fn recreate_surface<MWC>(&mut self, window: &MWC::MapWindow, instance: &wgpu::Instance)
|
pub fn recreate_surface<MWC>(&mut self, window: &MWC::MapWindow, instance: &wgpu::Instance)
|
||||||
where
|
where
|
||||||
MWC: MapWindowConfig,
|
MWC: MapWindowConfig,
|
||||||
<<MWC as MapWindowConfig>::MapWindow as MapWindow>::RawWindow:
|
<MWC as MapWindowConfig>::MapWindow: HeadedMapWindow,
|
||||||
raw_window_handle::HasRawWindowHandle,
|
|
||||||
{
|
{
|
||||||
self.surface = unsafe { instance.create_surface(window.inner()) };
|
self.surface = unsafe { instance.create_surface(window.inner()) };
|
||||||
}
|
}
|
||||||
@ -127,9 +127,7 @@ impl Surface {
|
|||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
MWC: MapWindowConfig,
|
MWC: MapWindowConfig,
|
||||||
MWC::MapWindow: HasRawWindow,
|
<MWC as MapWindowConfig>::MapWindow: HeadedMapWindow,
|
||||||
/* <<MWC as MapWindowConfig>::MapWindow as MapWindow>::Window:
|
|
||||||
raw_window_handle::HasRawWindowHandle,*/
|
|
||||||
{
|
{
|
||||||
let size = window.size();
|
let size = window.size();
|
||||||
let surface_config = wgpu::SurfaceConfiguration {
|
let surface_config = wgpu::SurfaceConfiguration {
|
||||||
@ -141,7 +139,7 @@ impl Surface {
|
|||||||
present_mode: wgpu::PresentMode::Fifo, // VSync
|
present_mode: wgpu::PresentMode::Fifo, // VSync
|
||||||
};
|
};
|
||||||
|
|
||||||
let surface = unsafe { instance.create_surface(window.raw_window()) };
|
let surface = unsafe { instance.create_surface(window.inner()) };
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
size,
|
size,
|
||||||
@ -254,8 +252,7 @@ impl Surface {
|
|||||||
pub fn recreate<MWC>(&mut self, window: &MWC::MapWindow, instance: &wgpu::Instance)
|
pub fn recreate<MWC>(&mut self, window: &MWC::MapWindow, instance: &wgpu::Instance)
|
||||||
where
|
where
|
||||||
MWC: MapWindowConfig,
|
MWC: MapWindowConfig,
|
||||||
<<MWC as MapWindowConfig>::MapWindow as MapWindow>::RawWindow:
|
<MWC as MapWindowConfig>::MapWindow: HeadedMapWindow,
|
||||||
raw_window_handle::HasRawWindowHandle,
|
|
||||||
{
|
{
|
||||||
match &mut self.head {
|
match &mut self.head {
|
||||||
Head::Headed(window_head) => {
|
Head::Headed(window_head) => {
|
||||||
|
|||||||
@ -3,34 +3,18 @@
|
|||||||
use crate::{HTTPClient, MapSchedule, ScheduleMethod};
|
use crate::{HTTPClient, MapSchedule, ScheduleMethod};
|
||||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||||
|
|
||||||
/// Window with an optional [carte::window::WindowSize].
|
/// Window with a [carte::window::WindowSize].
|
||||||
pub trait MapWindow {
|
pub trait MapWindow {
|
||||||
type EventLoop;
|
|
||||||
type RawWindow;
|
|
||||||
|
|
||||||
fn size(&self) -> WindowSize;
|
fn size(&self) -> WindowSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait HeadedMapWindow: MapWindow {
|
||||||
|
type EventLoop;
|
||||||
|
type RawWindow: HasRawWindowHandle;
|
||||||
|
|
||||||
fn inner(&self) -> &Self::RawWindow;
|
fn inner(&self) -> &Self::RawWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasRawWindow {
|
|
||||||
type HRWH: HasRawWindowHandle;
|
|
||||||
|
|
||||||
fn raw_window(&self) -> &Self::HRWH;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<MW> HasRawWindow for MW
|
|
||||||
where
|
|
||||||
MW: MapWindow,
|
|
||||||
MW::RawWindow: HasRawWindowHandle,
|
|
||||||
{
|
|
||||||
type HRWH = MW::RawWindow;
|
|
||||||
|
|
||||||
fn raw_window(&self) -> &Self::HRWH {
|
|
||||||
self.inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait MapWindowConfig: 'static {
|
pub trait MapWindowConfig: 'static {
|
||||||
type MapWindow: MapWindow;
|
type MapWindow: MapWindow;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user