clean up layout dir
This commit is contained in:
1
TODO
1
TODO
@@ -16,6 +16,7 @@ scaling
|
|||||||
field could be best solution so redrawing stuff isn't needed & you can specify both as user
|
field could be best solution so redrawing stuff isn't needed & you can specify both as user
|
||||||
|
|
||||||
WidgetRef<W> or smth instead of Id
|
WidgetRef<W> or smth instead of Id
|
||||||
|
fyi this is not the same as what was just implemented
|
||||||
enum that's either an Id or an actual concrete instance of W
|
enum that's either an Id or an actual concrete instance of W
|
||||||
painter takes them in instead of (or in addition to) id
|
painter takes them in instead of (or in addition to) id
|
||||||
then type wrapper widgets to contain them
|
then type wrapper widgets to contain them
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
use std::any::{Any, TypeId};
|
|
||||||
|
|
||||||
use crate::util::{HashMap, Id};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct UiData {
|
|
||||||
map: HashMap<TypeId, Box<dyn Any>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UiData {
|
|
||||||
pub fn get<T: 'static>(&self) -> Option<&T> {
|
|
||||||
self.map
|
|
||||||
.get(&TypeId::of::<T>())
|
|
||||||
.map(|d| d.downcast_ref().unwrap())
|
|
||||||
}
|
|
||||||
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
|
||||||
self.map
|
|
||||||
.get_mut(&TypeId::of::<T>())
|
|
||||||
.map(|d| d.downcast_mut().unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn emit_remove(&mut self, id: &Id) {
|
|
||||||
for (tid, f) in &mut self.on_remove {
|
|
||||||
let data = self.map.get_mut(tid).unwrap().downcast_ref().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
mod attr;
|
||||||
mod color;
|
mod color;
|
||||||
mod event;
|
mod event;
|
||||||
mod id;
|
|
||||||
mod layer;
|
mod layer;
|
||||||
mod module;
|
mod module;
|
||||||
mod num;
|
mod num;
|
||||||
@@ -9,14 +9,13 @@ mod painter;
|
|||||||
mod text;
|
mod text;
|
||||||
mod texture;
|
mod texture;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod attr;
|
|
||||||
mod vec2;
|
|
||||||
mod widget;
|
mod widget;
|
||||||
|
mod widget_ref;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
|
pub use attr::*;
|
||||||
pub use color::*;
|
pub use color::*;
|
||||||
pub use event::*;
|
pub use event::*;
|
||||||
pub use id::*;
|
|
||||||
pub use layer::*;
|
pub use layer::*;
|
||||||
pub use module::*;
|
pub use module::*;
|
||||||
pub use num::*;
|
pub use num::*;
|
||||||
@@ -25,9 +24,9 @@ pub use painter::*;
|
|||||||
pub use text::*;
|
pub use text::*;
|
||||||
pub use texture::*;
|
pub use texture::*;
|
||||||
pub use ui::*;
|
pub use ui::*;
|
||||||
pub use attr::*;
|
|
||||||
pub use vec2::*;
|
|
||||||
pub use widget::*;
|
pub use widget::*;
|
||||||
|
pub use widget_ref::*;
|
||||||
pub use widgets::*;
|
pub use widgets::*;
|
||||||
|
|
||||||
|
pub use crate::util::Vec2;
|
||||||
pub type UiColor = Color<u8>;
|
pub type UiColor = Color<u8>;
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
use std::marker::Destruct;
|
||||||
|
|
||||||
|
use crate::util::Vec2;
|
||||||
|
|
||||||
pub const trait UiNum {
|
pub const trait UiNum {
|
||||||
fn to_f32(self) -> f32;
|
fn to_f32(self) -> f32;
|
||||||
}
|
}
|
||||||
@@ -19,3 +23,28 @@ impl const UiNum for i32 {
|
|||||||
self as f32
|
self as f32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: const UiNum, U: const UiNum> const From<(T, U)> for Vec2
|
||||||
|
where
|
||||||
|
(T, U): const Destruct,
|
||||||
|
{
|
||||||
|
fn from((x, y): (T, U)) -> Self {
|
||||||
|
Self {
|
||||||
|
x: x.to_f32(),
|
||||||
|
y: y.to_f32(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: const UiNum + Copy> const From<T> for Vec2 {
|
||||||
|
fn from(v: T) -> Self {
|
||||||
|
Self {
|
||||||
|
x: v.to_f32(),
|
||||||
|
y: v.to_f32(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn vec2(x: impl const UiNum, y: impl const UiNum) -> Vec2 {
|
||||||
|
Vec2::new(x.to_f32(), y.to_f32())
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ mod axis;
|
|||||||
mod len;
|
mod len;
|
||||||
mod pos;
|
mod pos;
|
||||||
|
|
||||||
use super::vec2::*;
|
use super::Vec2;
|
||||||
|
|
||||||
pub use align::*;
|
pub use align::*;
|
||||||
pub use axis::*;
|
pub use axis::*;
|
||||||
pub use len::*;
|
pub use len::*;
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
use std::ops::{Deref, DerefMut};
|
|
||||||
|
|
||||||
pub struct DynBorrower<'a, T: ?Sized> {
|
|
||||||
data: &'a mut T,
|
|
||||||
borrowed: &'a mut bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T: ?Sized> DynBorrower<'a, T> {
|
|
||||||
pub fn new(data: &'a mut T, borrowed: &'a mut bool) -> Self {
|
|
||||||
if *borrowed {
|
|
||||||
panic!("tried to mutably borrow the same thing twice");
|
|
||||||
}
|
|
||||||
Self { data, borrowed }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: ?Sized> Drop for DynBorrower<'_, T> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
*self.borrowed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: ?Sized> Deref for DynBorrower<'_, T> {
|
|
||||||
type Target = T;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
self.data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: ?Sized> DerefMut for DynBorrower<'_, T> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
self.data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
mod arena;
|
mod arena;
|
||||||
mod borrow;
|
|
||||||
mod change;
|
mod change;
|
||||||
mod id;
|
mod id;
|
||||||
mod math;
|
mod math;
|
||||||
mod refcount;
|
mod refcount;
|
||||||
|
mod vec2;
|
||||||
|
|
||||||
pub(crate) use arena::*;
|
pub(crate) use arena::*;
|
||||||
pub(crate) use borrow::*;
|
|
||||||
pub use change::*;
|
pub use change::*;
|
||||||
pub(crate) use id::*;
|
pub(crate) use id::*;
|
||||||
pub(crate) use math::*;
|
pub(crate) use math::*;
|
||||||
pub(crate) use refcount::*;
|
pub(crate) use refcount::*;
|
||||||
|
pub use vec2::*;
|
||||||
|
|
||||||
pub type HashMap<K, V> = fxhash::FxHashMap<K, V>;
|
pub type HashMap<K, V> = fxhash::FxHashMap<K, V>;
|
||||||
pub type HashSet<K> = fxhash::FxHashSet<K>;
|
pub type HashSet<K> = fxhash::FxHashSet<K>;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ impl RefCounter {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(Arc::new(0.into()))
|
Self(Arc::new(0.into()))
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn refs(&self) -> u32 {
|
pub fn refs(&self) -> u32 {
|
||||||
self.0.load(Ordering::Acquire)
|
self.0.load(Ordering::Acquire)
|
||||||
}
|
}
|
||||||
@@ -17,6 +18,7 @@ impl RefCounter {
|
|||||||
let refs = self.0.fetch_sub(1, Ordering::Release);
|
let refs = self.0.fetch_sub(1, Ordering::Release);
|
||||||
refs == 0
|
refs == 0
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn quiet_clone(&self) -> Self {
|
pub fn quiet_clone(&self) -> Self {
|
||||||
Self(self.0.clone())
|
Self(self.0.clone())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
use crate::util::{DivOr, impl_op};
|
||||||
layout::UiNum,
|
use std::{hash::Hash, ops::*};
|
||||||
util::{DivOr, impl_op},
|
|
||||||
};
|
|
||||||
use std::{hash::Hash, marker::Destruct, ops::*};
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, PartialEq, Default, bytemuck::Pod, bytemuck::Zeroable)]
|
#[derive(Clone, Copy, PartialEq, Default, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
@@ -20,10 +17,6 @@ impl Hash for Vec2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn vec2(x: impl const UiNum, y: impl const UiNum) -> Vec2 {
|
|
||||||
Vec2::new(x.to_f32(), y.to_f32())
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Vec2 {
|
impl Vec2 {
|
||||||
pub const ZERO: Self = Self::new(0.0, 0.0);
|
pub const ZERO: Self = Self::new(0.0, 0.0);
|
||||||
pub const ONE: Self = Self::new(1.0, 1.0);
|
pub const ONE: Self = Self::new(1.0, 1.0);
|
||||||
@@ -68,15 +61,6 @@ impl Vec2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: const UiNum + Copy> const From<T> for Vec2 {
|
|
||||||
fn from(v: T) -> Self {
|
|
||||||
Self {
|
|
||||||
x: v.to_f32(),
|
|
||||||
y: v.to_f32(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this version looks kinda cool... is it more readable? more annoying to copy and change though
|
// this version looks kinda cool... is it more readable? more annoying to copy and change though
|
||||||
impl_op!(impl Add for Vec2: add x y);
|
impl_op!(impl Add for Vec2: add x y);
|
||||||
impl_op!(Vec2 Sub sub; x y);
|
impl_op!(Vec2 Sub sub; x y);
|
||||||
@@ -102,18 +86,6 @@ impl Neg for Vec2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: const UiNum, U: const UiNum> const From<(T, U)> for Vec2
|
|
||||||
where
|
|
||||||
(T, U): const Destruct,
|
|
||||||
{
|
|
||||||
fn from((x, y): (T, U)) -> Self {
|
|
||||||
Self {
|
|
||||||
x: x.to_f32(),
|
|
||||||
y: y.to_f32(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Debug for Vec2 {
|
impl std::fmt::Debug for Vec2 {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "({}, {})", self.x, self.y)
|
write!(f, "({}, {})", self.x, self.y)
|
||||||
Reference in New Issue
Block a user