fix sized bounds
This commit is contained in:
@@ -4,7 +4,7 @@ use crate::prelude::*;
|
|||||||
// these methods should "not require any context" (require unit) because they're in core
|
// these methods should "not require any context" (require unit) because they're in core
|
||||||
event_ctx!(());
|
event_ctx!(());
|
||||||
|
|
||||||
pub trait CoreWidget<W, Tag> {
|
pub trait CoreWidget<W: ?std::marker::Sized, Tag> {
|
||||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad>;
|
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad>;
|
||||||
fn align(self, align: impl Into<Align>) -> impl WidgetFn<Aligned>;
|
fn align(self, align: impl Into<Align>) -> impl WidgetFn<Aligned>;
|
||||||
fn center(self) -> impl WidgetFn<Aligned>;
|
fn center(self) -> impl WidgetFn<Aligned>;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::layout::{Ui, WidgetRef, WidgetIdFn, WidgetLike};
|
use crate::layout::{Ui, WidgetRef, WidgetIdFn, WidgetLike};
|
||||||
|
|
||||||
pub trait WidgetAttr<W> {
|
pub trait WidgetAttr<W: ?Sized> {
|
||||||
type Input;
|
type Input;
|
||||||
fn run(ui: &mut Ui, id: &WidgetRef<W>, input: Self::Input);
|
fn run(ui: &mut Ui, id: &WidgetRef<W>, input: Self::Input);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Attrable<W, Tag> {
|
pub trait Attrable<W: ?Sized, Tag> {
|
||||||
fn attr<A: WidgetAttr<W>>(self, input: A::Input) -> impl WidgetIdFn<W>;
|
fn attr<A: WidgetAttr<W>>(self, input: A::Input) -> impl WidgetIdFn<W>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub struct EventCtx<'a, Ctx, Data> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type ECtx<'a, Ctx, Data, W> = EventIdCtx<'a, Ctx, Data, W>;
|
pub type ECtx<'a, Ctx, Data, W> = EventIdCtx<'a, Ctx, Data, W>;
|
||||||
pub struct EventIdCtx<'a, Ctx, Data, W> {
|
pub struct EventIdCtx<'a, Ctx, Data, W: ?Sized> {
|
||||||
pub widget: &'a WidgetRef<W>,
|
pub widget: &'a WidgetRef<W>,
|
||||||
pub ui: &'a mut Ui,
|
pub ui: &'a mut Ui,
|
||||||
pub state: &'a mut Ctx,
|
pub state: &'a mut Ctx,
|
||||||
@@ -27,7 +27,7 @@ pub struct EventIdCtx<'a, Ctx, Data, W> {
|
|||||||
pub trait EventFn<Ctx, Data>: Fn(EventCtx<Ctx, Data>) + 'static {}
|
pub trait EventFn<Ctx, Data>: Fn(EventCtx<Ctx, Data>) + 'static {}
|
||||||
impl<F: Fn(EventCtx<Ctx, Data>) + 'static, Ctx, Data> EventFn<Ctx, Data> for F {}
|
impl<F: Fn(EventCtx<Ctx, Data>) + 'static, Ctx, Data> EventFn<Ctx, Data> for F {}
|
||||||
|
|
||||||
pub trait WidgetEventFn<Ctx, Data, W>: Fn(EventIdCtx<Ctx, Data, W>) + 'static {}
|
pub trait WidgetEventFn<Ctx, Data, W: ?Sized>: Fn(EventIdCtx<Ctx, Data, W>) + 'static {}
|
||||||
impl<F: Fn(EventIdCtx<Ctx, Data, W>) + 'static, Ctx, Data, W> WidgetEventFn<Ctx, Data, W> for F {}
|
impl<F: Fn(EventIdCtx<Ctx, Data, W>) + 'static, Ctx, Data, W> WidgetEventFn<Ctx, Data, W> for F {}
|
||||||
|
|
||||||
// TODO: naming in here is a bit weird like eventable
|
// TODO: naming in here is a bit weird like eventable
|
||||||
@@ -36,10 +36,11 @@ macro_rules! event_ctx {
|
|||||||
($ty: ty) => {
|
($ty: ty) => {
|
||||||
mod local_event_trait {
|
mod local_event_trait {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::marker::Sized;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use $crate::prelude::*;
|
use $crate::prelude::*;
|
||||||
|
|
||||||
pub trait EventableCtx<W, Tag, Ctx: 'static> {
|
pub trait EventableCtx<W: ?Sized, Tag, Ctx: 'static> {
|
||||||
fn on<E: Event>(
|
fn on<E: Event>(
|
||||||
self,
|
self,
|
||||||
event: E,
|
event: E,
|
||||||
@@ -65,7 +66,7 @@ pub use event_ctx;
|
|||||||
pub mod eventable {
|
pub mod eventable {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub trait Eventable<W, Tag> {
|
pub trait Eventable<W: ?Sized, Tag> {
|
||||||
fn on<E: Event, Ctx: 'static>(
|
fn on<E: Event, Ctx: 'static>(
|
||||||
self,
|
self,
|
||||||
event: E,
|
event: E,
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ impl Ui {
|
|||||||
self.data.textures.add(image)
|
self.data.textures.add(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_event<W, E: Event, Ctx: 'static>(
|
pub fn register_event<W: ?Sized, E: Event, Ctx: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: &WidgetRef<W>,
|
id: &WidgetRef<W>,
|
||||||
event: E,
|
event: E,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
layout::{Len, Painter, SizeCtx, Ui, WidgetIdFn, WidgetRef},
|
layout::{Len, Painter, SizeCtx, Ui, WidgetIdFn, WidgetRef},
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{any::Any, marker::PhantomData};
|
use std::{any::Any, marker::Unsize};
|
||||||
|
|
||||||
pub trait Widget: Any {
|
pub trait Widget: Any {
|
||||||
fn draw(&mut self, painter: &mut Painter);
|
fn draw(&mut self, painter: &mut Painter);
|
||||||
@@ -25,7 +25,7 @@ pub struct WidgetTag;
|
|||||||
pub struct FnTag;
|
pub struct FnTag;
|
||||||
|
|
||||||
pub trait WidgetLike<Tag> {
|
pub trait WidgetLike<Tag> {
|
||||||
type Widget: Widget + 'static;
|
type Widget: Widget + ?Sized + Unsize<dyn Widget> + 'static;
|
||||||
|
|
||||||
fn add(self, ui: &mut Ui) -> WidgetRef<Self::Widget>;
|
fn add(self, ui: &mut Ui) -> WidgetRef<Self::Widget>;
|
||||||
|
|
||||||
@@ -78,40 +78,27 @@ impl<W: Widget> WidgetLike<WidgetTag> for W {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WidgetArr<const LEN: usize, Ws> {
|
pub struct WidgetArr<const LEN: usize> {
|
||||||
pub arr: [WidgetRef; LEN],
|
pub arr: [WidgetRef; LEN],
|
||||||
_pd: PhantomData<Ws>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const LEN: usize, Ws> WidgetArr<LEN, Ws> {
|
impl<const LEN: usize> WidgetArr<LEN> {
|
||||||
pub fn new(arr: [WidgetRef; LEN]) -> Self {
|
pub fn new(arr: [WidgetRef; LEN]) -> Self {
|
||||||
Self {
|
Self { arr }
|
||||||
arr,
|
|
||||||
_pd: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ArrTag;
|
pub struct ArrTag;
|
||||||
pub trait WidgetArrLike<const LEN: usize, Tag> {
|
pub trait WidgetArrLike<const LEN: usize, Tag> {
|
||||||
type Ws;
|
fn ui(self, ui: &mut Ui) -> WidgetArr<LEN>;
|
||||||
fn ui(self, ui: &mut Ui) -> WidgetArr<LEN, Self::Ws>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const LEN: usize, Ws> WidgetArrLike<LEN, ArrTag> for WidgetArr<LEN, Ws> {
|
impl<const LEN: usize> WidgetArrLike<LEN, ArrTag> for WidgetArr<LEN> {
|
||||||
type Ws = Ws;
|
fn ui(self, _: &mut Ui) -> WidgetArr<LEN> {
|
||||||
fn ui(self, _: &mut Ui) -> WidgetArr<LEN, Ws> {
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WidgetLike<WidgetTag>> WidgetArrLike<1, WidgetTag> for W {
|
|
||||||
type Ws = (W::Widget,);
|
|
||||||
fn ui(self, ui: &mut Ui) -> WidgetArr<1, (W::Widget,)> {
|
|
||||||
WidgetArr::new([self.add(ui).any()])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// I hate this language it's so bad why do I even use it
|
// I hate this language it's so bad why do I even use it
|
||||||
macro_rules! impl_widget_arr {
|
macro_rules! impl_widget_arr {
|
||||||
($n:expr;$($W:ident)*) => {
|
($n:expr;$($W:ident)*) => {
|
||||||
@@ -119,8 +106,7 @@ macro_rules! impl_widget_arr {
|
|||||||
};
|
};
|
||||||
($n:expr;$($W:ident)*;$($Tag:ident)*) => {
|
($n:expr;$($W:ident)*;$($Tag:ident)*) => {
|
||||||
impl<$($W: WidgetLike<$Tag>,$Tag,)*> WidgetArrLike<$n, ($($Tag,)*)> for ($($W,)*) {
|
impl<$($W: WidgetLike<$Tag>,$Tag,)*> WidgetArrLike<$n, ($($Tag,)*)> for ($($W,)*) {
|
||||||
type Ws = ($($W::Widget,)*);
|
fn ui(self, ui: &mut Ui) -> WidgetArr<$n> {
|
||||||
fn ui(self, ui: &mut Ui) -> WidgetArr<$n, ($($W::Widget,)*)> {
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
let ($($W,)*) = self;
|
let ($($W,)*) = self;
|
||||||
WidgetArr::new(
|
WidgetArr::new(
|
||||||
|
|||||||
@@ -134,20 +134,22 @@ impl<W: ?Sized> Drop for Inner<W> {
|
|||||||
pub struct IdTag;
|
pub struct IdTag;
|
||||||
pub struct IdFnTag;
|
pub struct IdFnTag;
|
||||||
|
|
||||||
pub trait WidgetIdFn<W>: FnOnce(&mut Ui) -> WidgetRef<W> {}
|
pub trait WidgetIdFn<W: ?Sized>: FnOnce(&mut Ui) -> WidgetRef<W> {}
|
||||||
impl<W, F: FnOnce(&mut Ui) -> WidgetRef<W>> WidgetIdFn<W> for F {}
|
impl<W: ?Sized, F: FnOnce(&mut Ui) -> WidgetRef<W>> WidgetIdFn<W> for F {}
|
||||||
|
|
||||||
pub trait WidgetRet: FnOnce(&mut Ui) -> WidgetRef {}
|
pub trait WidgetRet: FnOnce(&mut Ui) -> WidgetRef {}
|
||||||
impl<F: FnOnce(&mut Ui) -> WidgetRef> WidgetRet for F {}
|
impl<F: FnOnce(&mut Ui) -> WidgetRef> WidgetRet for F {}
|
||||||
|
|
||||||
impl<W: Widget + 'static> WidgetLike<IdTag> for WidgetRef<W> {
|
impl<W: Widget + ?Sized + Unsize<dyn Widget> + 'static> WidgetLike<IdTag> for WidgetRef<W> {
|
||||||
type Widget = W;
|
type Widget = W;
|
||||||
fn add(self, _: &mut Ui) -> WidgetRef<W> {
|
fn add(self, _: &mut Ui) -> WidgetRef<W> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: Widget + 'static, F: FnOnce(&mut Ui) -> WidgetRef<W>> WidgetLike<IdFnTag> for F {
|
impl<W: Widget + ?Sized + Unsize<dyn Widget> + 'static, F: FnOnce(&mut Ui) -> WidgetRef<W>>
|
||||||
|
WidgetLike<IdFnTag> for F
|
||||||
|
{
|
||||||
type Widget = W;
|
type Widget = W;
|
||||||
fn add(self, ui: &mut Ui) -> WidgetRef<W> {
|
fn add(self, ui: &mut Ui) -> WidgetRef<W> {
|
||||||
self(ui)
|
self(ui)
|
||||||
|
|||||||
Reference in New Issue
Block a user