initial global widget store

This commit is contained in:
iris committed 2025-12-10 01:42:39 -05:00
1 parent 7f4846a2d3
commit 6156c66a20
31 files changed
+536 -352

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct Masked {
pub inner: WidgetRef,
pub inner: WidgetHandle,
}
impl Widget for Masked {
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct Aligned {
pub inner: WidgetRef,
pub inner: WidgetHandle,
pub align: Align,
}
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct LayerOffset {
pub inner: WidgetRef,
pub inner: WidgetHandle,
pub offset: usize,
}
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct MaxSize {
pub inner: WidgetRef,
pub inner: WidgetHandle,
pub x: Option<Len>,
pub y: Option<Len>,
}
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct Offset {
pub inner: WidgetRef,
pub inner: WidgetHandle,
pub amt: UiVec2,
}
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::prelude::*;
pub struct Pad {
pub padding: Padding,
pub inner: WidgetRef,
pub inner: WidgetHandle,
}
impl Widget for Pad {
+2 -2
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct Scroll {
inner: WidgetRef,
inner: WidgetHandle,
axis: Axis,
amt: f32,
snap_end: bool,
@@ -41,7 +41,7 @@ impl Widget for Scroll {
}
impl Scroll {
pub fn new(inner: WidgetRef, axis: Axis) -> Self {
pub fn new(inner: WidgetHandle, axis: Axis) -> Self {
Self {
inner,
axis,
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::prelude::*;
pub struct Sized {
pub inner: WidgetRef,
pub inner: WidgetHandle,
pub x: Option<Len>,
pub y: Option<Len>,
}
+3 -3
View File
@@ -2,7 +2,7 @@ use crate::prelude::*;
use std::marker::PhantomData;
pub struct Span {
pub children: Vec<WidgetRef>,
pub children: Vec<WidgetHandle>,
pub dir: Dir,
pub gap: f32,
}
@@ -158,7 +158,7 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> FnOnce<(&mut Ui,)>
extern "rust-call" fn call_once(self, args: (&mut Ui,)) -> Self::Output {
Span {
children: self.children.ui(args.0).arr.to_vec(),
children: self.children.ui(args.0).arr.into_iter().collect(),
dir: self.dir,
gap: self.gap,
}
@@ -182,7 +182,7 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> SpanBuilder<LEN, Wa, Ta
}
impl std::ops::Deref for Span {
type Target = Vec<WidgetRef>;
type Target = Vec<WidgetHandle>;
fn deref(&self) -> &Self::Target {
&self.children
+2 -2
View File
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
pub struct Stack {
pub children: Vec<WidgetRef>,
pub children: Vec<WidgetHandle>,
pub size: StackSize,
}
@@ -55,7 +55,7 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> FnOnce<(&mut Ui,)>
extern "rust-call" fn call_once(self, args: (&mut Ui,)) -> Self::Output {
Stack {
children: self.children.ui(args.0).arr.to_vec(),
children: self.children.ui(args.0).arr.into_iter().collect(),
size: self.size,
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::prelude::*;
#[derive(Default)]
pub struct WidgetPtr {
pub inner: Option<WidgetRef>,
pub inner: Option<WidgetHandle>,
}
impl Widget for WidgetPtr {
+18 -21
View File
@@ -1,15 +1,12 @@
use crate::prelude::*;
use crate::util::Id;
use std::{
ops::{BitOr, Deref, DerefMut},
rc::Rc,
};
use crate::{
layout::{UiModule, UiRegion, Vec2},
util::HashMap,
};
use std::{
ops::{BitOr, Deref, DerefMut},
rc::Rc,
};
#[derive(Clone, Copy, PartialEq)]
pub enum CursorButton {
@@ -100,10 +97,10 @@ pub enum ActivationState {
/// but I'm not sure how or if worth it
pub struct Sensor<Ctx, Data> {
pub senses: CursorSenses,
pub f: Rc<dyn EventFn<Ctx, Data>>,
pub f: Box<dyn EventFn<Ctx, Data>>,
}
pub type SensorMap<Ctx, Data> = HashMap<Id, SensorGroup<Ctx, Data>>;
pub type SensorMap<Ctx, Data> = HashMap<WidgetId, SensorGroup<Ctx, Data>>;
pub type SenseShape = UiRegion;
pub struct SensorGroup<Ctx, Data> {
pub hover: ActivationState,
@@ -122,7 +119,7 @@ pub struct CursorData {
pub struct CursorModule<Ctx> {
map: SensorMap<Ctx, CursorData>,
active: HashMap<usize, HashMap<Id, SenseShape>>,
active: HashMap<usize, HashMap<WidgetId, SenseShape>>,
}
impl<Ctx: 'static> UiModule for CursorModule<Ctx> {
@@ -141,7 +138,7 @@ impl<Ctx: 'static> UiModule for CursorModule<Ctx> {
}
}
fn on_remove(&mut self, id: &Id) {
fn on_remove(&mut self, id: &WidgetId) {
self.map.remove(id);
for layer in self.active.values_mut() {
layer.remove(id);
@@ -307,34 +304,34 @@ impl Event for CursorSense {
impl<E: Event<Data = <CursorSenses as Event>::Data> + Into<CursorSenses>, Ctx: 'static>
EventModule<E, Ctx> for CursorModule<Ctx>
{
fn register(&mut self, id: Id, senses: E, f: impl EventFn<Ctx, <E as Event>::Data>) {
fn register(&mut self, id: WidgetId, senses: E, f: impl EventFn<Ctx, <E as Event>::Data>) {
// TODO: does not add to active if currently active
self.map.entry(id).or_default().sensors.push(Sensor {
senses: senses.into(),
f: Rc::new(f),
f: Box::new(f),
});
}
fn run<'a>(
&self,
id: &Id,
fn run(
&mut self,
id: WidgetId,
event: E,
) -> Option<impl Fn(EventCtx<Ctx, <E as Event>::Data>) + use<'a, E, Ctx>> {
) -> Option<impl FnOnce(EventCtx<Ctx, <E as Event>::Data>)> {
let senses = event.into();
if let Some(group) = self.map.get(id) {
if let Some(group) = self.map.get_mut(&id) {
let fs: Vec<_> = group
.sensors
.iter()
.iter_mut()
.filter_map(|sensor| {
if sensor.senses.iter().any(|s| senses.contains(s)) {
Some(sensor.f.clone())
Some(&mut sensor.f)
} else {
None
}
})
.collect();
Some(move |ctx: EventCtx<Ctx, CursorData>| {
for f in &fs {
for f in fs {
f(EventCtx {
state: ctx.state,
ui: ctx.ui,
+2 -2
View File
@@ -21,11 +21,11 @@ pub struct TextView {
// cache
tex: Option<RenderedText>,
width: Option<f32>,
pub hint: Option<WidgetRef>,
pub hint: Option<WidgetHandle>,
}
impl TextView {
pub fn new(buf: TextBuffer, attrs: TextAttrs, hint: Option<WidgetRef>) -> Self {
pub fn new(buf: TextBuffer, attrs: TextAttrs, hint: Option<WidgetHandle>) -> Self {
Self {
attrs: attrs.into(),
buf: buf.into(),
+1 -1
View File
@@ -127,7 +127,7 @@ widget_trait! {
|ui| self.add(ui)
}
fn set_ptr(self, ptr: &WidgetRef<WidgetPtr>, ui: &mut Ui) {
fn set_ptr(self, ptr: &WidgetHandle<WidgetPtr>, ui: &mut Ui) {
ptr.get_mut().inner = Some(self.add(ui));
}
}