rename widget fn macros
This commit is contained in:
@@ -15,7 +15,7 @@ impl Widget for Image {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn image(image: impl LoadableImage) -> WidgetFnRet!(Image) {
|
||||
pub fn image(image: impl LoadableImage) -> WidgetFn!(Image) {
|
||||
let image = image.get_image().expect("Failed to load image");
|
||||
move |ui| Image {
|
||||
handle: ui.add_texture(image),
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait Sensable<W, Tag> {
|
||||
fn on(self, sense: Senses, f: impl SenseFn) -> WidgetIdFnRet!(W);
|
||||
fn on(self, sense: Senses, f: impl SenseFn) -> WidgetIdFn!(W);
|
||||
fn id_on(
|
||||
self,
|
||||
senses: Senses,
|
||||
f: impl FnMut(&WidgetId<W>, &mut Ui) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W)
|
||||
) -> WidgetIdFn!(W)
|
||||
where
|
||||
W: Widget;
|
||||
fn edit_on(self, senses: Senses, f: impl FnMut(&mut W) + 'static + Clone) -> WidgetIdFnRet!(W)
|
||||
fn edit_on(self, senses: Senses, f: impl FnMut(&mut W) + 'static + Clone) -> WidgetIdFn!(W)
|
||||
where
|
||||
W: Widget;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
||||
fn on(self, senses: Senses, f: impl SenseFn) -> WidgetIdFnRet!(W::Widget) {
|
||||
fn on(self, senses: Senses, f: impl SenseFn) -> WidgetIdFn!(W::Widget) {
|
||||
move |ui| {
|
||||
let id = self.add(ui);
|
||||
ui.add_sensor(
|
||||
@@ -32,7 +32,7 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
||||
self,
|
||||
senses: Senses,
|
||||
mut f: impl FnMut(&WidgetId<W::Widget>, &mut Ui) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W::Widget)
|
||||
) -> WidgetIdFn!(W::Widget)
|
||||
where
|
||||
W::Widget: Widget,
|
||||
{
|
||||
@@ -45,7 +45,7 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
||||
self,
|
||||
senses: Senses,
|
||||
mut f: impl FnMut(&mut W::Widget) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W::Widget)
|
||||
) -> WidgetIdFn!(W::Widget)
|
||||
where
|
||||
W::Widget: Widget,
|
||||
{
|
||||
|
||||
@@ -2,41 +2,41 @@ use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait CoreWidget<W, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned);
|
||||
fn align(self, align: Align) -> WidgetFnRet!(Aligned);
|
||||
fn center(self) -> WidgetFnRet!(Aligned);
|
||||
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned);
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W);
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized);
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFn!(Regioned);
|
||||
fn align(self, align: Align) -> WidgetFn!(Aligned);
|
||||
fn center(self) -> WidgetFn!(Aligned);
|
||||
fn region(self, region: UiRegion) -> WidgetFn!(Regioned);
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFn!(W);
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFn!(Sized);
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned) {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFn!(Regioned) {
|
||||
|ui| Regioned {
|
||||
region: padding.into().region(),
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
fn align(self, align: Align) -> WidgetFnRet!(Aligned) {
|
||||
fn align(self, align: Align) -> WidgetFn!(Aligned) {
|
||||
move |ui| Aligned {
|
||||
inner: self.add(ui).erase_type(),
|
||||
align,
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self) -> WidgetFnRet!(Aligned) {
|
||||
fn center(self) -> WidgetFn!(Aligned) {
|
||||
self.align(Align::Center)
|
||||
}
|
||||
|
||||
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned) {
|
||||
fn region(self, region: UiRegion) -> WidgetFn!(Regioned) {
|
||||
move |ui| Regioned {
|
||||
region,
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W::Widget) {
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFn!(W::Widget) {
|
||||
|ui| {
|
||||
let id = self.add(ui);
|
||||
ui.set_label(&id, label.into());
|
||||
@@ -44,7 +44,7 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized) {
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFn!(Sized) {
|
||||
move |ui| Sized {
|
||||
inner: self.add(ui).erase_type(),
|
||||
size: size.into(),
|
||||
@@ -53,19 +53,19 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Tag> {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFnRet!(Span);
|
||||
fn stack(self) -> WidgetFnRet!(Stack);
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFn!(Span);
|
||||
fn stack(self) -> WidgetFn!(Stack);
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Tag> for Wa {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFnRet!(Span) {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFn!(Span) {
|
||||
let lengths = lengths.into_lens();
|
||||
move |ui| Span {
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
dir,
|
||||
}
|
||||
}
|
||||
fn stack(self) -> WidgetFnRet!(Stack) {
|
||||
fn stack(self) -> WidgetFn!(Stack) {
|
||||
move |ui| Stack {
|
||||
children: self.ui(ui).arr.to_vec(),
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ pub struct IdTag;
|
||||
pub struct IdFnTag;
|
||||
|
||||
// pub trait WidgetIdFn<W, Ctx> = FnOnce(&mut Ui) -> WidgetId<W>;
|
||||
macro_rules! WidgetIdFnRet {
|
||||
macro_rules! WidgetIdFn {
|
||||
($W:ty) => {
|
||||
impl FnOnce(&mut $crate::layout::Ui) -> $crate::layout::WidgetId<$W>
|
||||
};
|
||||
@@ -128,15 +128,12 @@ macro_rules! WidgetIdFnRet {
|
||||
impl FnOnce(&mut $crate::layout::Ui) -> $crate::layout::WidgetId<$W> + use<$($use)*>
|
||||
};
|
||||
}
|
||||
pub(crate) use WidgetIdFnRet;
|
||||
pub(crate) use WidgetIdFn;
|
||||
|
||||
pub trait Idable<Tag> {
|
||||
type Widget: Widget;
|
||||
fn set(self, ui: &mut Ui, id: &WidgetId<Self::Widget>);
|
||||
fn id<'a>(
|
||||
self,
|
||||
id: &WidgetId<Self::Widget>,
|
||||
) -> WidgetIdFnRet!(Self::Widget, 'a, Self, Tag)
|
||||
fn id<'a>(self, id: &WidgetId<Self::Widget>) -> WidgetIdFn!(Self::Widget, 'a, Self, Tag)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -149,7 +146,7 @@ pub trait Idable<Tag> {
|
||||
fn id_static<'a>(
|
||||
self,
|
||||
id: StaticWidgetId<Self::Widget>,
|
||||
) -> WidgetIdFnRet!(Self::Widget, 'a, Self, Tag)
|
||||
) -> WidgetIdFn!(Self::Widget, 'a, Self, Tag)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::layout::{Painter, TextData, Textures, Ui, Vec2, WidgetId, WidgetIdFnRet, Widgets};
|
||||
use crate::layout::{Painter, TextData, Textures, Ui, Vec2, WidgetId, WidgetIdFn, Widgets};
|
||||
|
||||
use std::{any::Any, marker::PhantomData};
|
||||
|
||||
@@ -31,7 +31,7 @@ pub trait WidgetLike<Tag> {
|
||||
fn with_id<W2>(
|
||||
self,
|
||||
f: impl FnOnce(&mut Ui, WidgetId<Self::Widget>) -> WidgetId<W2>,
|
||||
) -> WidgetIdFnRet!(W2)
|
||||
) -> WidgetIdFn!(W2)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -48,12 +48,12 @@ pub trait WidgetLike<Tag> {
|
||||
/// Useful for defining trait functions on widgets that create a parent widget so that the children
|
||||
/// don't need to be IDs yet
|
||||
/// currently a macro for rust analyzer (doesn't support trait aliases atm)
|
||||
macro_rules! WidgetFnRet {
|
||||
macro_rules! WidgetFn {
|
||||
($W:ty) => {
|
||||
impl FnOnce(&mut $crate::layout::Ui) -> $W
|
||||
};
|
||||
}
|
||||
pub(crate) use WidgetFnRet;
|
||||
pub(crate) use WidgetFn;
|
||||
|
||||
impl<W: Widget, F: FnOnce(&mut Ui) -> W> WidgetLike<FnTag> for F {
|
||||
type Widget = W;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_from)]
|
||||
#![feature(map_try_insert)]
|
||||
#![feature(trait_alias)]
|
||||
|
||||
pub mod core;
|
||||
pub mod layout;
|
||||
|
||||
Reference in New Issue
Block a user