idek stuff like stack
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{Painter, UINum, UiRegion, Widget, WidgetId};
|
||||
use crate::{Painter, UiNum, UiRegion, Widget, WidgetId};
|
||||
|
||||
pub struct Regioned {
|
||||
pub region: UiRegion,
|
||||
@@ -38,7 +38,7 @@ impl Padding {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: UINum> From<T> for Padding {
|
||||
impl<T: UiNum> From<T> for Padding {
|
||||
fn from(amt: T) -> Self {
|
||||
Self::uniform(amt.to_f32())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ mod num;
|
||||
mod rect;
|
||||
mod sense;
|
||||
mod span;
|
||||
mod stack;
|
||||
mod trait_fns;
|
||||
|
||||
pub use frame::*;
|
||||
@@ -10,4 +11,5 @@ pub use num::*;
|
||||
pub use rect::*;
|
||||
pub use sense::*;
|
||||
pub use span::*;
|
||||
pub use stack::*;
|
||||
pub use trait_fns::*;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
pub trait UINum {
|
||||
pub trait UiNum {
|
||||
fn to_f32(self) -> f32;
|
||||
}
|
||||
|
||||
impl UINum for f32 {
|
||||
impl UiNum for f32 {
|
||||
fn to_f32(self) -> f32 {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl UINum for u32 {
|
||||
impl UiNum for u32 {
|
||||
fn to_f32(self) -> f32 {
|
||||
self as f32
|
||||
}
|
||||
}
|
||||
|
||||
impl UINum for i32 {
|
||||
impl UiNum for i32 {
|
||||
fn to_f32(self) -> f32 {
|
||||
self as f32
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Painter, UiColor, Widget, primitive::RoundedRectData};
|
||||
use crate::{primitive::RoundedRectData, Painter, UiNum, UiColor, Widget};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Rect {
|
||||
@@ -21,6 +21,10 @@ impl Rect {
|
||||
self.color = color;
|
||||
self
|
||||
}
|
||||
pub fn radius(mut self, radius: impl UiNum) -> Self {
|
||||
self.radius = radius.to_f32();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx> Widget<Ctx> for Rect {
|
||||
|
||||
@@ -4,7 +4,7 @@ pub trait SenseCtx: 'static {
|
||||
fn active(&mut self, trigger: &SenseTrigger) -> bool;
|
||||
}
|
||||
|
||||
pub trait Sensable<W, Ctx: SenseCtx, Tag> {
|
||||
pub trait Sensable<W, Ctx, Tag> {
|
||||
fn sense(
|
||||
self,
|
||||
sense: Sense,
|
||||
@@ -21,7 +21,7 @@ pub trait Sensable<W, Ctx: SenseCtx, Tag> {
|
||||
W: Widget<Ctx>;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Ctx, Tag>, Ctx: SenseCtx, Tag> Sensable<W::Widget, Ctx, Tag> for W {
|
||||
impl<W: WidgetLike<Ctx, Tag>, Ctx, Tag> Sensable<W::Widget, Ctx, Tag> for W {
|
||||
fn sense(self, sense: Sense, f: impl SenseFn<Ctx> + Clone) -> impl WidgetIdFn<W::Widget, Ctx> {
|
||||
move |ui| {
|
||||
let id = self.add(ui);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Dir, Painter, Sign, UINum, UiRegion, UIScalar, Widget, WidgetId};
|
||||
use crate::{Dir, Painter, Sign, UiNum, UiRegion, UIScalar, Widget, WidgetId};
|
||||
|
||||
pub struct Span {
|
||||
pub children: Vec<(WidgetId, SpanLen)>,
|
||||
@@ -80,19 +80,19 @@ pub enum SpanLen {
|
||||
Relative(f32),
|
||||
}
|
||||
|
||||
pub fn fixed<N: UINum>(x: N) -> SpanLen {
|
||||
pub fn fixed<N: UiNum>(x: N) -> SpanLen {
|
||||
SpanLen::Fixed(x.to_f32())
|
||||
}
|
||||
|
||||
pub fn ratio<N: UINum>(x: N) -> SpanLen {
|
||||
pub fn ratio<N: UiNum>(x: N) -> SpanLen {
|
||||
SpanLen::Ratio(x.to_f32())
|
||||
}
|
||||
|
||||
pub fn rel<N: UINum>(x: N) -> SpanLen {
|
||||
pub fn rel<N: UiNum>(x: N) -> SpanLen {
|
||||
SpanLen::Relative(x.to_f32())
|
||||
}
|
||||
|
||||
impl<N: UINum> From<N> for SpanLen {
|
||||
impl<N: UiNum> From<N> for SpanLen {
|
||||
fn from(value: N) -> Self {
|
||||
Self::Ratio(value.to_f32())
|
||||
}
|
||||
|
||||
13
src/core/stack.rs
Normal file
13
src/core/stack.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use crate::{Widget, WidgetId};
|
||||
|
||||
pub struct Stack {
|
||||
pub children: Vec<WidgetId>,
|
||||
}
|
||||
|
||||
impl<Ctx> Widget<Ctx> for Stack {
|
||||
fn draw(&self, painter: &mut crate::Painter<Ctx>) {
|
||||
for child in &self.children {
|
||||
painter.draw(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
use super::*;
|
||||
use crate::{UiRegion, Vec2, WidgetArrLike, WidgetFn, WidgetLike};
|
||||
|
||||
pub trait CoreWidget<Ctx: 'static, Tag> {
|
||||
pub trait CoreWidget<W: 'static, Ctx: 'static, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Regioned, Ctx>;
|
||||
fn center(self, size: impl Into<Vec2>) -> impl WidgetFn<Regioned, Ctx>;
|
||||
fn region(self, region: UiRegion) -> impl WidgetFn<Regioned, Ctx>;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<Ctx, Tag> for W {
|
||||
impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<W::Widget, Ctx, Tag> for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Regioned, Ctx> {
|
||||
|ui| Regioned {
|
||||
region: padding.into().region(),
|
||||
@@ -16,7 +17,14 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<Ctx, Tag> for W {
|
||||
|
||||
fn center(self, size: impl Into<Vec2>) -> impl WidgetFn<Regioned, Ctx> {
|
||||
|ui| Regioned {
|
||||
region: UiRegion::center(size.into()),
|
||||
region: UiRegion::center().size(size.into()),
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
fn region(self, region: UiRegion) -> impl WidgetFn<Regioned, Ctx> {
|
||||
move |ui| Regioned {
|
||||
region,
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
@@ -24,10 +32,11 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<Ctx, Tag> for W {
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Ctx: 'static, Tag> {
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> impl WidgetFn<Span, Ctx>;
|
||||
fn stack(self) -> impl WidgetFn<Stack, Ctx>;
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Ctx, Tag>, Ctx: 'static, Tag> CoreWidgetArr<LEN, Ctx, Tag>
|
||||
for Wa
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Ctx, Tag>, Ctx: 'static, Tag>
|
||||
CoreWidgetArr<LEN, Ctx, Tag> for Wa
|
||||
{
|
||||
fn span(self, dir: Dir, lengths: [impl Into<SpanLen>; LEN]) -> impl WidgetFn<Span, Ctx> {
|
||||
let lengths = lengths.map(Into::into);
|
||||
@@ -36,4 +45,9 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Ctx, Tag>, Ctx: 'static, Tag> Core
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
}
|
||||
}
|
||||
fn stack(self) -> impl WidgetFn<Stack, Ctx> {
|
||||
move |ui| Stack {
|
||||
children: self.ui(ui).arr.to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user