diff --git a/voxygen/src/ui/element/image.rs b/voxygen/src/ui/element/image.rs deleted file mode 100644 index 0e8f1d0375..0000000000 --- a/voxygen/src/ui/element/image.rs +++ /dev/null @@ -1,77 +0,0 @@ -// Standard -use std::rc::Rc; - -// Library -use image::DynamicImage; -use vek::*; - -// Crate -use crate::render::{ - Consts, - UiLocals, - Renderer, - Texture, - UiPipeline, -}; - -// Local -use super::{ - super::{ - UiError, - Cache, - }, - Element, - Bounds, - SizeRequest, -}; - -#[derive(Clone)] -pub struct Image { - texture: Rc>, - locals: Consts, -} - -impl Image { - pub fn new(renderer: &mut Renderer, image: &DynamicImage) -> Result { - Ok(Self { - texture: Rc::new( - renderer.create_texture(image) - .map_err(|err| UiError::RenderError(err))? - ), - locals: renderer.create_consts(&[UiLocals::default()]) - .map_err(|err| UiError::RenderError(err))?, - }) - } -} - -impl Element for Image { - fn get_hsize_request(&self) -> SizeRequest { SizeRequest::indifferent() } - fn get_vsize_request(&self) -> SizeRequest { SizeRequest::indifferent() } - - fn maintain( - &mut self, - renderer: &mut Renderer, - cache: &Cache, - bounds: Bounds, - resolution: Vec2, - ) { - renderer.update_consts(&mut self.locals, &[UiLocals::new( - [bounds.x, bounds.y, bounds.w, bounds.h], - )]) - .expect("Could not update UI image consts"); - } - - fn render( - &self, - renderer: &mut Renderer, - cache: &Cache, - bounds: Bounds, - resolution: Vec2, - ) { - renderer.render_ui_element( - cache.model(), - &self.locals, - &self.texture, - ); - } -} diff --git a/voxygen/src/ui/element/mod.rs b/voxygen/src/ui/element/mod.rs deleted file mode 100644 index 1f8d486d1b..0000000000 --- a/voxygen/src/ui/element/mod.rs +++ /dev/null @@ -1,181 +0,0 @@ -pub mod image; - -// Standard -use std::rc::Rc; - -// Library -use vek::*; - -// Crate -use crate::render::{ - Renderer, - Texture, - Consts, - UiLocals, - UiPipeline, -}; - -// Local -use super::{ - UiError, - Cache, - Span, - SizeRequest, -}; - -// Bounds - -pub type Bounds = Rect; - -pub trait BoundsExt { - fn relative_to(self, other: Self) -> Self; -} - -impl BoundsExt for Bounds { - fn relative_to(self, other: Self) -> Self { - Self::new( - other.x + self.x * other.w, - other.y + self.y * other.h, - self.w * other.w, - self.h * other.h, - ) - } -} - -pub trait BoundsSpan { - fn in_resolution(self, resolution: Vec2) -> Bounds; -} - -impl BoundsSpan for Bounds { - fn in_resolution(self, resolution: Vec2) -> Bounds { - Bounds::new( - self.x.to_rel(resolution.x).rel, - self.y.to_rel(resolution.y).rel, - self.w.to_rel(resolution.x).rel, - self.h.to_rel(resolution.y).rel, - ) - } -} - -// Element - -pub trait Element: 'static { - //fn deep_clone(&self) -> Rc; - - fn get_hsize_request(&self) -> SizeRequest; - fn get_vsize_request(&self) -> SizeRequest; - - fn maintain( - &mut self, - renderer: &mut Renderer, - cache: &Cache, - bounds: Bounds, - resolution: Vec2, - ); - - fn render( - &self, - renderer: &mut Renderer, - cache: &Cache, - bounds: Bounds, - resolution: Vec2, - ); -} - -// Surface - -#[derive(Clone)] -pub enum Surface { - Transparent, - Color(Rgba), - Texture(Rc>), - Bevel, -} - -// Widget - -#[derive(Clone)] -pub struct Widget { - inner: Box, - background: Surface, - margin_top: Span, - margin_bottom: Span, - margin_left: Span, - margin_right: Span, - locals: Consts, -} - -impl Widget { - pub fn new(renderer: &mut Renderer, inner: E) -> Result, UiError> { - Ok(Box::new(Self { - inner: Box::new(inner), - background: Surface::Transparent, - margin_top: Span::rel(0.2), - margin_bottom: Span::rel(0.2), - margin_left: Span::rel(0.2), - margin_right: Span::rel(0.2), - locals: renderer.create_consts(&[UiLocals::default()]) - .map_err(|err| UiError::RenderError(err))?, - })) - } - - fn get_inner_bounds(&self) -> Bounds { - Bounds::new( - self.margin_left, - self.margin_top, - Span::full() - self.margin_left - self.margin_right, - Span::full() - self.margin_top - self.margin_bottom, - ) - } -} - -impl Element for Widget { - fn get_hsize_request(&self) -> SizeRequest { - self.inner.get_hsize_request() + self.margin_left + self.margin_right - } - - fn get_vsize_request(&self) -> SizeRequest { - self.inner.get_vsize_request() + self.margin_top + self.margin_bottom - } - - fn maintain( - &mut self, - renderer: &mut Renderer, - cache: &Cache, - bounds: Bounds, - resolution: Vec2, - ) { - renderer.update_consts(&mut self.locals, &[UiLocals::new( - [bounds.x, bounds.y, bounds.w, bounds.h], - )]) - .expect("Could not update UI image consts"); - - let inner_bounds = self - .get_inner_bounds() - .in_resolution(resolution) - .relative_to(bounds); - - self.inner.maintain(renderer, cache, inner_bounds, resolution); - } - - fn render( - &self, - renderer: &mut Renderer, - cache: &Cache, - bounds: Bounds, - resolution: Vec2, - ) { - renderer.render_ui_element( - cache.model(), - &self.locals, - &cache.blank_texture(), - ); - - let inner_bounds = self - .get_inner_bounds() - .in_resolution(resolution) - .relative_to(bounds); - - self.inner.render(renderer, cache, inner_bounds, resolution); - } -} diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index f3efcfa633..e08423a7af 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -1,13 +1,3 @@ -//pub mod element; -//pub mod size_request; -//pub mod span; - -// Reexports -/*pub use self::{ - span::Span, - size_request::SizeRequest, -};*/ - // TODO: what was the purpose of size request? // TODO: cache entire UI render // TODO: do we need to store locals for each widget? @@ -38,12 +28,6 @@ use crate::{ }, }; -// Local -/*use self::element::{ - Element, - Bounds, -};*/ - #[derive(Debug)] pub enum UiError { RenderError(RenderError), diff --git a/voxygen/src/ui/size_request.rs b/voxygen/src/ui/size_request.rs deleted file mode 100644 index ad8658e099..0000000000 --- a/voxygen/src/ui/size_request.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Standard -use std::ops::Add; - -// Local -use super::Span; - -pub struct SizeRequest { - min: Span, - max: Span, -} - -impl SizeRequest { - pub fn indifferent() -> Self { - Self { - min: Span::rel(0.0), - max: Span::rel(std::f32::INFINITY), - } - } -} - -impl Add for SizeRequest { - type Output = Self; - - fn add(self, span: Span) -> Self { - Self { - min: self.min + span, - max: self.max + span, - } - } -} diff --git a/voxygen/src/ui/span.rs b/voxygen/src/ui/span.rs deleted file mode 100644 index e06674164b..0000000000 --- a/voxygen/src/ui/span.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Standard -use std::ops::{Add, Sub}; - -#[derive(Copy, Clone)] -pub struct Span { - pub rel: f32, - pub abs: f32, -} - -impl Span { - pub fn rel(rel: f32) -> Self { Self { rel, abs: 0.0 } } - pub fn abs(abs: f32) -> Self { Self { rel: 0.0, abs } } - - pub fn full() -> Self { Self { rel: 1.0, abs: 0.0 } } - pub fn half() -> Self { Self { rel: 0.5, abs: 0.0 } } - pub fn none() -> Self { Self { rel: 0.0, abs: 0.0 } } - - pub fn to_abs(self, res: f32) -> Self { - Self { rel: 0.0, abs: self.rel * res + self.abs } - } - - pub fn to_rel(self, res: f32) -> Self { - Self { rel: self.rel + self.abs / res, abs: 0.0 } - } -} - -impl Add for Span { - type Output = Self; - - fn add(self, other: Self) -> Self { - Self { - rel: self.rel + other.rel, - abs: self.abs + other.abs, - } - } -} - -impl Sub for Span { - type Output = Self; - - fn sub(self, other: Self) -> Self { - Self { - rel: self.rel - other.rel, - abs: self.abs - other.abs, - } - } -}