mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
remove old ui files
Former-commit-id: 82979b9df64ffa120f385e625648e04113c6a917
This commit is contained in:
parent
628a91af00
commit
d685706c9b
@ -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<Texture<UiPipeline>>,
|
|
||||||
locals: Consts<UiLocals>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Image {
|
|
||||||
pub fn new(renderer: &mut Renderer, image: &DynamicImage) -> Result<Self, UiError> {
|
|
||||||
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<f32>,
|
|
||||||
resolution: Vec2<f32>,
|
|
||||||
) {
|
|
||||||
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<f32>,
|
|
||||||
resolution: Vec2<f32>,
|
|
||||||
) {
|
|
||||||
renderer.render_ui_element(
|
|
||||||
cache.model(),
|
|
||||||
&self.locals,
|
|
||||||
&self.texture,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<T> = Rect<T, T>;
|
|
||||||
|
|
||||||
pub trait BoundsExt {
|
|
||||||
fn relative_to(self, other: Self) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BoundsExt for Bounds<f32> {
|
|
||||||
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<f32>) -> Bounds<f32>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BoundsSpan for Bounds<Span> {
|
|
||||||
fn in_resolution(self, resolution: Vec2<f32>) -> Bounds<f32> {
|
|
||||||
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<dyn Element>;
|
|
||||||
|
|
||||||
fn get_hsize_request(&self) -> SizeRequest;
|
|
||||||
fn get_vsize_request(&self) -> SizeRequest;
|
|
||||||
|
|
||||||
fn maintain(
|
|
||||||
&mut self,
|
|
||||||
renderer: &mut Renderer,
|
|
||||||
cache: &Cache,
|
|
||||||
bounds: Bounds<f32>,
|
|
||||||
resolution: Vec2<f32>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn render(
|
|
||||||
&self,
|
|
||||||
renderer: &mut Renderer,
|
|
||||||
cache: &Cache,
|
|
||||||
bounds: Bounds<f32>,
|
|
||||||
resolution: Vec2<f32>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Surface
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum Surface {
|
|
||||||
Transparent,
|
|
||||||
Color(Rgba<f32>),
|
|
||||||
Texture(Rc<Texture<UiPipeline>>),
|
|
||||||
Bevel,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Widget
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Widget<E: Element> {
|
|
||||||
inner: Box<E>,
|
|
||||||
background: Surface,
|
|
||||||
margin_top: Span,
|
|
||||||
margin_bottom: Span,
|
|
||||||
margin_left: Span,
|
|
||||||
margin_right: Span,
|
|
||||||
locals: Consts<UiLocals>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: Element> Widget<E> {
|
|
||||||
pub fn new(renderer: &mut Renderer, inner: E) -> Result<Box<Self>, 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<Span> {
|
|
||||||
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<E: Element> Element for Widget<E> {
|
|
||||||
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<f32>,
|
|
||||||
resolution: Vec2<f32>,
|
|
||||||
) {
|
|
||||||
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<f32>,
|
|
||||||
resolution: Vec2<f32>,
|
|
||||||
) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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: what was the purpose of size request?
|
||||||
// TODO: cache entire UI render
|
// TODO: cache entire UI render
|
||||||
// TODO: do we need to store locals for each widget?
|
// TODO: do we need to store locals for each widget?
|
||||||
@ -38,12 +28,6 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Local
|
|
||||||
/*use self::element::{
|
|
||||||
Element,
|
|
||||||
Bounds,
|
|
||||||
};*/
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum UiError {
|
pub enum UiError {
|
||||||
RenderError(RenderError),
|
RenderError(RenderError),
|
||||||
|
@ -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<Span> for SizeRequest {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn add(self, span: Span) -> Self {
|
|
||||||
Self {
|
|
||||||
min: self.min + span,
|
|
||||||
max: self.max + span,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user