7 Commits

Author SHA1 Message Date
iris a648c62aa2 update 2026-04-15 20:31:52 -04:00
iris c118bb446b some potentially nice trait stuff 2026-03-15 21:07:06 -04:00
iris 1102dc7338 work 2026-02-26 19:18:27 -05:00
iris 1aadef0e7e fix Draw (redraw) 2026-02-21 00:19:39 -05:00
iris 426ff0adfc oop 2026-02-18 16:49:59 -05:00
iris dab6cf298a Merge branch 'work' of git.arirex.me:shadowcat/iris into work 2026-02-17 18:14:38 -05:00
iris 38d896d44d selector 2026-02-17 18:14:19 -05:00
20 changed files with 717 additions and 492 deletions
Generated
+406 -386
View File
File diff suppressed because it is too large Load Diff
-2
View File
@@ -2,10 +2,8 @@
#![feature(const_ops)]
#![feature(const_trait_impl)]
#![feature(const_convert)]
#![feature(map_try_insert)]
#![feature(unboxed_closures)]
#![feature(fn_traits)]
#![feature(const_cmp)]
#![feature(const_destruct)]
#![feature(portable_simd)]
#![feature(associated_type_defaults)]
+1 -1
View File
@@ -28,7 +28,7 @@ pub trait UiRsc {
#[allow(unused_variables)]
fn on_remove(&mut self, id: WidgetId) {}
#[allow(unused_variables)]
fn on_draw(&mut self, active: &ActiveData) {}
fn on_draw(&mut self, active: &ActiveData, redrawn: bool) {}
#[allow(unused_variables)]
fn on_undraw(&mut self, active: &ActiveData) {}
+3 -1
View File
@@ -81,10 +81,12 @@ impl UiRenderState {
old_children: Option<Vec<WidgetId>>,
rsc: &mut dyn UiRsc,
) {
let mut redrawn = old_children.is_some();
let mut old_children = old_children.unwrap_or_default();
if let Some(active) = self.active.get_mut(&id)
&& !rsc.widgets().needs_redraw.contains(&id)
{
redrawn = true;
// check to see if we can skip drawing first
if active.region == region {
return;
@@ -149,7 +151,7 @@ impl UiRenderState {
}
}
rsc.on_draw(&active);
rsc.on_draw(&active, redrawn);
self.active.insert(id, active);
}
+8 -1
View File
@@ -34,7 +34,7 @@ pub trait HasRoot {
pub trait WidgetArrLike<Rsc, const LEN: usize, Tag> {
#[track_caller]
fn add(self, state: &mut Rsc) -> WidgetArr<LEN>;
fn add(self, rsc: &mut Rsc) -> WidgetArr<LEN>;
}
impl<Rsc, const LEN: usize> WidgetArrLike<Rsc, LEN, ArrTag> for WidgetArr<LEN> {
@@ -58,6 +58,13 @@ macro_rules! impl_widget_arr {
)
}
}
impl<Rsc: UiRsc, $($W: WidgetLike<Rsc, $Tag>,$Tag,)*> IntoWidgetVec<Rsc, ($($Tag,)*), ArrTag> for ($($W,)*) {
fn into_vec(self, rsc: &mut Rsc) -> Vec<StrongWidget> {
#[allow(non_snake_case)]
let ($($W,)*) = self;
vec![$($W.add(rsc).upgrade(rsc),)*]
}
}
};
}
+14 -1
View File
@@ -1,4 +1,4 @@
use crate::{Axis, AxisT, Len, Painter, SizeCtx};
use crate::{Axis, AxisT, Len, Painter, SizeCtx, UiRsc};
use std::any::Any;
mod data;
@@ -85,3 +85,16 @@ impl<State, F: FnOnce(&mut State) -> Option<StrongWidget>> WidgetOption<State> f
self(state)
}
}
pub trait IntoWidgetVec<Rsc, WTag, GTag> {
fn into_vec(self, rsc: &mut Rsc) -> Vec<StrongWidget>;
}
impl<Rsc: UiRsc, I: IntoIterator, Tag> IntoWidgetVec<Rsc, Tag, IterTag> for I
where
I::Item: WidgetLike<Rsc, Tag>,
{
fn into_vec(self, rsc: &mut Rsc) -> Vec<StrongWidget> {
self.into_iter().map(|w| w.add_strong(rsc).any()).collect()
}
}
+1
View File
@@ -62,3 +62,4 @@ impl<Rsc: UiRsc, V: WidgetView> WidgetLike<Rsc, ViewTag> for V {
}
pub struct ArrTag;
pub struct IterTag;
+1 -5
View File
@@ -10,11 +10,7 @@ struct State {
}
impl DefaultAppState for State {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
fn new(mut ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>) -> Self {
rect(Color::RED).set_root(rsc, &mut ui_state);
Self { ui_state }
}
+2 -6
View File
@@ -16,11 +16,7 @@ pub struct Client {
}
impl DefaultAppState for Client {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
fn new(mut ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>) -> Self {
let rrect = rect(Color::WHITE).radius(20);
let pad_test = (
rrect.color(Color::BLUE),
@@ -148,7 +144,7 @@ impl DefaultAppState for Client {
.span(Dir::DOWN)
.add(rsc);
let main = WidgetPtr::new().add(rsc);
let main = WidgetPtr::empty().add(rsc);
let vals = Rc::new(RefCell::new((0, Vec::new())));
let mut switch_button = |color, to: WeakWidget, label| {
+1 -5
View File
@@ -11,11 +11,7 @@ struct State {
}
impl DefaultAppState for State {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
fn new(mut ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>) -> Self {
let rect = rect(Color::RED).add(rsc);
rect.task_on(CursorSense::click(), async move |mut ctx| {
tokio::time::sleep(Duration::from_secs(1)).await;
+1 -5
View File
@@ -36,11 +36,7 @@ impl Test {
}
impl DefaultAppState for State {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
fn new(mut ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>) -> Self {
let test = Test::new(rsc);
test.on(CursorSense::click(), move |_, rsc| {
+8
View File
@@ -7,3 +7,11 @@ impl Event for Submit {}
#[derive(Eq, PartialEq, Hash, Clone)]
pub struct Edited;
impl Event for Edited {}
#[derive(Eq, PartialEq, Hash, Clone)]
pub struct Draw;
impl Event for Draw {}
#[derive(Eq, PartialEq, Hash, Clone)]
pub struct Undraw;
impl Event for Undraw {}
+145 -45
View File
@@ -29,7 +29,26 @@ pub use sense::*;
pub use state::*;
pub use task::*;
pub type Proxy<Event> = EventLoopProxy<Event>;
pub struct EventSender<State: DefaultAppState> {
proxy: EventLoopProxy<UiMainEvent<State>>,
}
impl<State: DefaultAppState> Clone for EventSender<State> {
fn clone(&self) -> Self {
Self {
proxy: self.proxy.clone(),
}
}
}
impl<State: DefaultAppState> EventSender<State> {
pub fn send(&self, event: State::Event) {
let _ = self.proxy.send_event(UiMainEvent::App(event));
}
pub fn run(&self, f: impl MainCallback<State>) {
let _ = self.proxy.send_event(UiMainEvent::Callback(Box::new(f)));
}
}
pub struct DefaultUiState {
pub root: Option<StrongWidget>,
@@ -70,9 +89,8 @@ pub trait HasDefaultUiState: Sized + 'static {
}
pub trait DefaultAppState: HasDefaultUiState {
type Event = ();
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, proxy: Proxy<Self::Event>)
-> Self;
type Event: Send = ();
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>) -> Self;
#[allow(unused_variables)]
fn event(
&mut self,
@@ -96,23 +114,54 @@ pub trait DefaultAppState: HasDefaultUiState {
}
}
pub struct DefaultRsc<State: 'static> {
pub struct DefaultRsc<State: 'static + DefaultAppState> {
pub ui: UiData,
pub events: EventManager<Self>,
pub tasks: Tasks<Self>,
pub state: WidgetState,
pub widget_events: Vec<WidgetEvent>,
pub window_event: EventSender<State>,
_state: PhantomData<State>,
}
impl<State> DefaultRsc<State> {
fn init(window: Arc<Window>) -> (Self, TaskMsgReceiver<Self>) {
let (tasks, recv) = Tasks::init(window);
pub struct WidgetEvent {
id: WidgetId,
ty: WidgetEventType,
}
pub enum WidgetEventType {
Draw,
Undraw,
Remove,
}
pub trait MainCallback<State>: FnOnce(&mut DefaultRsc<State>) + Sync + Send + 'static {}
impl<F: FnOnce(&mut DefaultRsc<State>) + Sync + Send + 'static, State> MainCallback<State> for F {}
pub enum UiMainEvent<State: DefaultAppState> {
RequestUpdate,
Callback(Box<dyn MainCallback<State>>),
App(State::Event),
}
impl<State: DefaultAppState> DefaultRsc<State> {
fn init(proxy: EventLoopProxy<UiMainEvent<State>>) -> (Self, TaskMsgReceiver<Self>) {
let window_event = EventSender {
proxy: proxy.clone(),
};
let (tasks, recv) = Tasks::init(move || {
if proxy.send_event(UiMainEvent::RequestUpdate).is_err() {
panic!("main thread blew up or smth");
}
});
(
Self {
ui: Default::default(),
events: Default::default(),
tasks,
widget_events: Default::default(),
state: Default::default(),
window_event,
_state: Default::default(),
},
recv,
@@ -124,7 +173,7 @@ impl<State> DefaultRsc<State> {
}
}
impl<State> UiRsc for DefaultRsc<State> {
impl<State: DefaultAppState> UiRsc for DefaultRsc<State> {
fn ui(&self) -> &UiData {
&self.ui
}
@@ -133,25 +182,39 @@ impl<State> UiRsc for DefaultRsc<State> {
&mut self.ui
}
fn on_draw(&mut self, active: &ActiveData) {
fn on_draw(&mut self, active: &ActiveData, redrawn: bool) {
self.events.draw(active);
if !redrawn {
self.widget_events.push(WidgetEvent {
id: active.id,
ty: WidgetEventType::Draw,
});
}
}
fn on_undraw(&mut self, active: &ActiveData) {
self.events.undraw(active);
self.widget_events.push(WidgetEvent {
id: active.id,
ty: WidgetEventType::Undraw,
});
}
fn on_remove(&mut self, id: WidgetId) {
self.events.remove(id);
self.state.remove(id);
self.widget_events.push(WidgetEvent {
id,
ty: WidgetEventType::Remove,
});
}
}
impl<State: 'static> HasState for DefaultRsc<State> {
impl<State: 'static + DefaultAppState> HasState for DefaultRsc<State> {
type State = State;
}
impl<State: 'static> HasEvents for DefaultRsc<State> {
impl<State: 'static + DefaultAppState> HasEvents for DefaultRsc<State> {
fn events(&self) -> &EventManager<Self> {
&self.events
}
@@ -161,13 +224,13 @@ impl<State: 'static> HasEvents for DefaultRsc<State> {
}
}
impl<State: 'static> HasTasks for DefaultRsc<State> {
impl<State: 'static + DefaultAppState> HasTasks for DefaultRsc<State> {
fn tasks_mut(&mut self) -> &mut Tasks<Self> {
&mut self.tasks
}
}
impl<State: 'static> HasWidgetState for DefaultRsc<State> {
impl<State: 'static + DefaultAppState> HasWidgetState for DefaultRsc<State> {
fn widget_state(&self) -> &WidgetState {
&self.state
}
@@ -185,15 +248,15 @@ pub struct DefaultApp<State: DefaultAppState> {
}
impl<State: DefaultAppState> AppState for DefaultApp<State> {
type Event = State::Event;
type Event = UiMainEvent<State>;
fn new(event_loop: &ActiveEventLoop, proxy: EventLoopProxy<Self::Event>) -> Self {
let window = event_loop
.create_window(State::window_attributes())
.unwrap();
let default_state = DefaultUiState::new(window);
let (mut rsc, task_recv) = DefaultRsc::init(default_state.window.clone());
let state = State::new(default_state, &mut rsc, proxy);
let (mut rsc, task_recv) = DefaultRsc::init(proxy);
let state = State::new(default_state, &mut rsc);
let render = UiRenderState::new();
Self {
rsc,
@@ -204,38 +267,39 @@ impl<State: DefaultAppState> AppState for DefaultApp<State> {
}
fn event(&mut self, event: Self::Event, _: &ActiveEventLoop) {
self.state.event(event, &mut self.rsc, &mut self.render);
match event {
UiMainEvent::RequestUpdate => {
self.check_updates();
}
UiMainEvent::App(event) => {
self.state.event(event, &mut self.rsc, &mut self.render);
}
UiMainEvent::Callback(f) => f(&mut self.rsc),
}
}
fn window_event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
let Self {
rsc,
render,
state,
task_recv,
rsc, render, state, ..
} = self;
for update in task_recv.try_iter() {
update(state, rsc);
}
// input handling
let ui_state = state.default_state_mut();
let input_changed = ui_state.input.event(&event);
let cursor_state = ui_state.cursor_state().clone();
let old = ui_state.focus;
if cursor_state.buttons.left.is_start() {
ui_state.focus = None;
}
if input_changed {
if ui_state.input.event(&event) {
let cursor_state = ui_state.cursor_state().clone();
let old = ui_state.focus;
if cursor_state.buttons.left.is_start() {
ui_state.focus = None;
}
let window_size = ui_state.window_size();
render.run_sensors(rsc, state, cursor_state, window_size);
if old != state.default_state().focus
&& let Some(old) = old
{
old.edit(rsc).deselect();
}
}
let ui_state = state.default_state_mut();
if old != ui_state.focus
&& let Some(old) = old
{
old.edit(rsc).deselect();
}
match &event {
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::RedrawRequested => {
@@ -297,11 +361,9 @@ impl<State: DefaultAppState> AppState for DefaultApp<State> {
_ => (),
}
state.window_event(event, rsc, render);
let ui_state = self.state.default_state_mut();
if render.needs_redraw(&ui_state.root, rsc.widgets()) {
ui_state.renderer.window().request_redraw();
}
ui_state.input.end_frame();
self.check_updates();
self.state.default_state_mut().input.end_frame();
}
fn exit(&mut self) {
@@ -309,13 +371,49 @@ impl<State: DefaultAppState> AppState for DefaultApp<State> {
}
}
impl<State: DefaultAppState> DefaultApp<State> {
pub fn check_updates(&mut self) {
let Self {
rsc,
render,
state,
task_recv,
} = self;
for update in task_recv.try_iter() {
update(state, rsc);
}
let mut events = std::mem::take(&mut rsc.widget_events);
for event in events.drain(..) {
match event.ty {
WidgetEventType::Draw => {
rsc.run_event::<Draw>(event.id, (), state);
}
WidgetEventType::Undraw => {
rsc.run_event::<Undraw>(event.id, (), state);
}
_ => (),
}
}
rsc.widget_events = events;
let ui_state = state.default_state();
if render.needs_redraw(&ui_state.root, rsc.widgets()) {
ui_state.renderer.window().request_redraw();
}
}
}
pub trait RscIdx<Rsc> {
type Output;
fn get(self, rsc: &Rsc) -> &Self::Output;
fn get_mut(self, rsc: &mut Rsc) -> &mut Self::Output;
}
impl<State: 'static, I: RscIdx<DefaultRsc<State>>> std::ops::Index<I> for DefaultRsc<State> {
impl<State: 'static + DefaultAppState, I: RscIdx<DefaultRsc<State>>> std::ops::Index<I>
for DefaultRsc<State>
{
type Output = I::Output;
fn index(&self, index: I) -> &Self::Output {
@@ -323,7 +421,9 @@ impl<State: 'static, I: RscIdx<DefaultRsc<State>>> std::ops::Index<I> for Defaul
}
}
impl<State: 'static, I: RscIdx<DefaultRsc<State>>> std::ops::IndexMut<I> for DefaultRsc<State> {
impl<State: 'static + DefaultAppState, I: RscIdx<DefaultRsc<State>>> std::ops::IndexMut<I>
for DefaultRsc<State>
{
fn index_mut(&mut self, index: I) -> &mut Self::Output {
index.get_mut(self)
}
+5 -6
View File
@@ -13,7 +13,6 @@ use tokio::{
unbounded_channel as async_channel,
},
};
use winit::window::Window;
pub type TaskMsgSender<Rsc> = SyncSender<Box<dyn TaskUpdate<Rsc>>>;
pub type TaskMsgReceiver<Rsc> = SyncReceiver<Box<dyn TaskUpdate<Rsc>>>;
@@ -23,7 +22,7 @@ impl<F: FnOnce(&mut Rsc::State, &mut Rsc) + Send, Rsc: HasState> TaskUpdate<Rsc>
pub struct Tasks<Rsc: HasState> {
start: AsyncSender<BoxTask>,
window: Arc<Window>,
request_update: Arc<dyn Fn() + Send + Sync>,
msg_send: SyncSender<Box<dyn TaskUpdate<Rsc>>>,
}
@@ -45,7 +44,7 @@ impl<Rsc: HasState + 'static> TaskCtx<Rsc> {
type BoxTask = Pin<Box<dyn Future<Output = ()> + Send>>;
impl<Rsc: HasState> Tasks<Rsc> {
pub fn init(window: Arc<Window>) -> (Self, TaskMsgReceiver<Rsc>) {
pub fn init(request_update: impl Fn() + 'static + Send + Sync) -> (Self, TaskMsgReceiver<Rsc>) {
let (start, start_recv) = async_channel();
let (msgs, msgs_recv) = sync_channel();
std::thread::spawn(|| {
@@ -56,7 +55,7 @@ impl<Rsc: HasState> Tasks<Rsc> {
Self {
start,
msg_send: msgs,
window,
request_update: Arc::new(request_update),
},
msgs_recv,
)
@@ -67,10 +66,10 @@ impl<Rsc: HasState> Tasks<Rsc> {
F::CallOnceFuture: Send,
{
let send = self.msg_send.clone();
let window = self.window.clone();
let request_update = self.request_update.clone();
let _ = self.start.send(Box::pin(async move {
task(TaskCtx::new(send)).await;
window.request_redraw();
request_update();
}));
}
}
+2
View File
@@ -5,6 +5,7 @@ mod ptr;
mod rect;
mod text;
mod trait_fns;
mod selector;
pub use image::*;
pub use mask::*;
@@ -13,3 +14,4 @@ pub use ptr::*;
pub use rect::*;
pub use text::*;
pub use trait_fns::*;
pub use selector::*;
+9 -9
View File
@@ -152,32 +152,32 @@ impl Span {
}
}
pub struct SpanBuilder<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag> {
pub children: Wa,
pub struct SpanBuilder<Children, Rsc, Tag, GTag> {
pub children: Children,
pub dir: Dir,
pub gap: f32,
_pd: PhantomData<(State, Tag)>,
_pd: PhantomData<(Rsc, Tag, GTag)>,
}
impl<Rsc, const LEN: usize, Wa: WidgetArrLike<Rsc, LEN, Tag>, Tag> WidgetFnTrait<Rsc>
for SpanBuilder<Rsc, LEN, Wa, Tag>
impl<Children: IntoWidgetVec<Rsc, Tag, GTag>, Rsc, Tag, GTag> WidgetFnTrait<Rsc>
for SpanBuilder<Children, Rsc, Tag, GTag>
{
type Widget = Span;
#[track_caller]
fn run(self, rsc: &mut Rsc) -> Self::Widget {
Span {
children: self.children.add(rsc).arr.into_iter().collect(),
children: self.children.into_vec(rsc),
dir: self.dir,
gap: self.gap,
}
}
}
impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag>
SpanBuilder<State, LEN, Wa, Tag>
impl<Children: IntoWidgetVec<Rsc, Tag, GTag>, Rsc, Tag, GTag>
SpanBuilder<Children, Rsc, Tag, GTag>
{
pub fn new(children: Wa, dir: Dir) -> Self {
pub fn new(children: Children, dir: Dir) -> Self {
Self {
children,
dir,
+8 -10
View File
@@ -42,30 +42,28 @@ pub enum StackSize {
Child(usize),
}
pub struct StackBuilder<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag> {
pub children: Wa,
pub struct StackBuilder<Children, Rsc, Tag, GTag> {
pub children: Children,
pub size: StackSize,
_pd: PhantomData<(State, Tag)>,
_pd: PhantomData<(Rsc, Tag, GTag)>,
}
impl<Rsc, const LEN: usize, Wa: WidgetArrLike<Rsc, LEN, Tag>, Tag> WidgetFnTrait<Rsc>
for StackBuilder<Rsc, LEN, Wa, Tag>
impl<Children: IntoWidgetVec<Rsc, Tag, GTag>, Rsc, Tag, GTag> WidgetFnTrait<Rsc>
for StackBuilder<Children, Rsc, Tag, GTag>
{
type Widget = Stack;
#[track_caller]
fn run(self, rsc: &mut Rsc) -> Self::Widget {
Stack {
children: self.children.add(rsc).arr.into_iter().collect(),
children: self.children.into_vec(rsc),
size: self.size,
}
}
}
impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag>
StackBuilder<State, LEN, Wa, Tag>
{
pub fn new(children: Wa) -> Self {
impl<Children: IntoWidgetVec<Rsc, Tag, GTag>, Rsc, Tag, GTag> StackBuilder<Children, Rsc, Tag, GTag> {
pub fn new(children: Children) -> Self {
Self {
children,
size: StackSize::default(),
+4 -2
View File
@@ -30,8 +30,10 @@ impl Widget for WidgetPtr {
}
impl WidgetPtr {
pub fn new() -> Self {
Self::default()
pub fn new(widget: StrongWidget) -> Self {
Self {
inner: Some(widget),
}
}
pub fn empty() -> Self {
Self {
+48
View File
@@ -0,0 +1,48 @@
use std::hash::Hash;
use iris_core::util::HashMap;
use crate::prelude::*;
pub struct WidgetSelector<T> {
current: (T, StrongWidget),
map: HashMap<T, StrongWidget>,
}
impl<T: Hash + Eq> WidgetSelector<T> {
pub fn new(key: T, widget: StrongWidget) -> Self {
Self {
current: (key, widget),
map: Default::default(),
}
}
pub fn set(&mut self, key: T, widget: StrongWidget) {
self.map.insert(key, widget);
}
pub fn select(&mut self, key: T) -> bool {
if let Some(val) = self.map.remove(&key) {
let mut new = (key, val);
std::mem::swap(&mut new, &mut self.current);
self.map.insert(new.0, new.1);
true
} else {
false
}
}
}
impl<T: 'static> Widget for WidgetSelector<T> {
fn draw(&mut self, painter: &mut Painter) {
painter.widget(&self.current.1);
}
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
ctx.width(&self.current.1)
}
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
ctx.height(&self.current.1)
}
}
+50 -7
View File
@@ -131,18 +131,61 @@ widget_trait! {
}
}
pub trait CoreWidgetArr<Rsc, const LEN: usize, Wa: WidgetArrLike<Rsc, LEN, Tag>, Tag> {
fn span(self, dir: Dir) -> SpanBuilder<Rsc, LEN, Wa, Tag>;
fn stack(self) -> StackBuilder<Rsc, LEN, Wa, Tag>;
pub trait CoreWidgetArr<Children, Rsc, Tag, GTag> {
fn span(self, dir: Dir) -> SpanBuilder<Children, Rsc, Tag, GTag>;
fn stack(self) -> StackBuilder<Children, Rsc, Tag, GTag>;
}
impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag>
CoreWidgetArr<State, LEN, Wa, Tag> for Wa
impl<Children: IntoWidgetVec<Rsc, Tag, GTag>, Rsc, Tag, GTag>
CoreWidgetArr<Children, Rsc, Tag, GTag> for Children
{
fn span(self, dir: Dir) -> SpanBuilder<State, LEN, Wa, Tag> {
fn span(self, dir: Dir) -> SpanBuilder<Children, Rsc, Tag, GTag> {
SpanBuilder::new(self, dir)
}
fn stack(self) -> StackBuilder<State, LEN, Wa, Tag> {
fn stack(self) -> StackBuilder<Children, Rsc, Tag, GTag> {
StackBuilder::new(self)
}
}
pub trait RscFnMap<Rsc> {
type Input;
fn rsc_map<O>(
self,
f: impl Fn(Self::Input, &mut Rsc) -> O + Clone,
) -> impl Iterator<Item = impl FnOnce(&mut Rsc) -> O>;
}
impl<I: IntoIterator, Rsc> RscFnMap<Rsc> for I {
type Input = I::Item;
fn rsc_map<O>(
self,
f: impl Fn(Self::Input, &mut Rsc) -> O + Clone,
) -> impl Iterator<Item = impl FnOnce(&mut Rsc) -> O> {
self.into_iter().map(move |i| {
let f = f.clone();
move |rsc: &mut Rsc| f(i, rsc)
})
}
}
pub trait WidgetFnMap<Rsc: UiRsc> {
fn widget_map<O: WidgetLike<Rsc, Tag>, Tag>(
self,
f: impl Fn(WeakWidget) -> O + Clone,
) -> impl Iterator<Item = impl FnOnce(&mut Rsc) -> WeakWidget>;
}
impl<I: IntoIterator, Rsc: UiRsc> WidgetFnMap<Rsc> for I
where
I::Item: WidgetIdFn<Rsc>,
{
fn widget_map<O: WidgetLike<Rsc, Tag>, Tag>(
self,
f: impl Fn(WeakWidget) -> O + Clone,
) -> impl Iterator<Item = impl FnOnce(&mut Rsc) -> WeakWidget> {
self.into_iter().map(move |f2| {
let f = f.clone();
move |rsc: &mut Rsc| f(f2(rsc)).add(rsc) as WeakWidget
})
}
}