separate state from rsc
This commit is contained in:
@@ -3,35 +3,35 @@ use crate::prelude::*;
|
||||
|
||||
// these methods should "not require any context" (require unit) because they're in core
|
||||
widget_trait! {
|
||||
pub trait CoreWidget<State: HasUi + StateLike<State> + 'static>;
|
||||
pub trait CoreWidget<Rsc: HasUi + 'static>;
|
||||
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<State, Pad> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Rsc, Pad> {
|
||||
|state| Pad {
|
||||
padding: padding.into(),
|
||||
inner: self.add_strong(state),
|
||||
}
|
||||
}
|
||||
|
||||
fn align(self, align: impl Into<Align>) -> impl WidgetFn<State, Aligned> {
|
||||
fn align(self, align: impl Into<Align>) -> impl WidgetFn<Rsc, Aligned> {
|
||||
move |state| Aligned {
|
||||
inner: self.add_strong(state),
|
||||
align: align.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self) -> impl WidgetFn<State, Aligned> {
|
||||
fn center(self) -> impl WidgetFn<Rsc, Aligned> {
|
||||
self.align(Align::CENTER)
|
||||
}
|
||||
|
||||
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<State, WL::Widget> {
|
||||
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<Rsc, WL::Widget> {
|
||||
|state| {
|
||||
let id = self.add(state);
|
||||
state.get_mut().set_label(id, label.into());
|
||||
state.ui_mut().set_label(id, label.into());
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
fn sized(self, size: impl Into<Size>) -> impl WidgetFn<State, Sized> {
|
||||
fn sized(self, size: impl Into<Size>) -> impl WidgetFn<Rsc, Sized> {
|
||||
let size = size.into();
|
||||
move |state| Sized {
|
||||
inner: self.add_strong(state),
|
||||
@@ -40,7 +40,7 @@ widget_trait! {
|
||||
}
|
||||
}
|
||||
|
||||
fn max_width(self, len: impl Into<Len>) -> impl WidgetFn<State, MaxSize> {
|
||||
fn max_width(self, len: impl Into<Len>) -> impl WidgetFn<Rsc, MaxSize> {
|
||||
let len = len.into();
|
||||
move |state| MaxSize {
|
||||
inner: self.add_strong(state),
|
||||
@@ -49,7 +49,7 @@ widget_trait! {
|
||||
}
|
||||
}
|
||||
|
||||
fn max_height(self, len: impl Into<Len>) -> impl WidgetFn<State, MaxSize> {
|
||||
fn max_height(self, len: impl Into<Len>) -> impl WidgetFn<Rsc, MaxSize> {
|
||||
let len = len.into();
|
||||
move |state| MaxSize {
|
||||
inner: self.add_strong(state),
|
||||
@@ -58,7 +58,7 @@ widget_trait! {
|
||||
}
|
||||
}
|
||||
|
||||
fn width(self, len: impl Into<Len>) -> impl WidgetFn<State, Sized> {
|
||||
fn width(self, len: impl Into<Len>) -> impl WidgetFn<Rsc, Sized> {
|
||||
let len = len.into();
|
||||
move |state| Sized {
|
||||
inner: self.add_strong(state),
|
||||
@@ -67,7 +67,7 @@ widget_trait! {
|
||||
}
|
||||
}
|
||||
|
||||
fn height(self, len: impl Into<Len>) -> impl WidgetFn<State, Sized> {
|
||||
fn height(self, len: impl Into<Len>) -> impl WidgetFn<Rsc, Sized> {
|
||||
let len = len.into();
|
||||
move |state| Sized {
|
||||
inner: self.add_strong(state),
|
||||
@@ -76,59 +76,59 @@ widget_trait! {
|
||||
}
|
||||
}
|
||||
|
||||
fn offset(self, amt: impl Into<UiVec2>) -> impl WidgetFn<State, Offset> {
|
||||
fn offset(self, amt: impl Into<UiVec2>) -> impl WidgetFn<Rsc, Offset> {
|
||||
move |state| Offset {
|
||||
inner: self.add_strong(state),
|
||||
amt: amt.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn scrollable(self) -> impl WidgetIdFn<State, Scroll> where State: HasEvents {
|
||||
fn scrollable(self) -> impl WidgetIdFn<Rsc, Scroll> where Rsc: HasEvents {
|
||||
use eventable::*;
|
||||
move |state| {
|
||||
Scroll::new(self.add_strong(state), Axis::Y)
|
||||
.on(CursorSense::Scroll, |ctx: &mut EventIdCtx<'_, State::State, CursorData<'_>, Scroll>| {
|
||||
.on(CursorSense::Scroll, |ctx, rsc| {
|
||||
let delta = ctx.data.scroll_delta.y * 50.0;
|
||||
ctx.widget().scroll(delta);
|
||||
ctx.widget(rsc).scroll(delta);
|
||||
})
|
||||
.add(state)
|
||||
}
|
||||
}
|
||||
|
||||
fn masked(self) -> impl WidgetFn<State, Masked> {
|
||||
fn masked(self) -> impl WidgetFn<Rsc, Masked> {
|
||||
move |state| Masked {
|
||||
inner: self.add_strong(state),
|
||||
}
|
||||
}
|
||||
|
||||
fn background<T>(self, w: impl WidgetLike<State, T>) -> impl WidgetFn<State, Stack> {
|
||||
fn background<T>(self, w: impl WidgetLike<Rsc, T>) -> impl WidgetFn<Rsc, Stack> {
|
||||
move |state| Stack {
|
||||
children: vec![w.add_strong(state), self.add_strong(state)],
|
||||
size: StackSize::Child(1),
|
||||
}
|
||||
}
|
||||
|
||||
fn foreground<T>(self, w: impl WidgetLike<State, T>) -> impl WidgetFn<State, Stack> {
|
||||
fn foreground<T>(self, w: impl WidgetLike<Rsc, T>) -> impl WidgetFn<Rsc, Stack> {
|
||||
move |state| Stack {
|
||||
children: vec![self.add_strong(state), w.add_strong(state)],
|
||||
size: StackSize::Child(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn layer_offset(self, offset: usize) -> impl WidgetFn<State, LayerOffset> {
|
||||
fn layer_offset(self, offset: usize) -> impl WidgetFn<Rsc, LayerOffset> {
|
||||
move |state| LayerOffset {
|
||||
inner: self.add_strong(state),
|
||||
offset,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_any(self) -> impl WidgetIdFn<State> {
|
||||
fn to_any(self) -> impl WidgetIdFn<Rsc> {
|
||||
|state| self.add(state)
|
||||
}
|
||||
|
||||
fn set_ptr(self, ptr: WidgetRef<WidgetPtr>, state: &mut State) {
|
||||
fn set_ptr(self, ptr: WidgetRef<WidgetPtr>, state: &mut Rsc) {
|
||||
let id = self.add_strong(state);
|
||||
state.get_mut()[ptr].inner = Some(id);
|
||||
state.ui_mut()[ptr].inner = Some(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user