beginning actual app

This commit is contained in:
2025-11-11 01:35:59 -05:00
parent 379eec771a
commit 92db1264a6
3 changed files with 32 additions and 23 deletions

View File

@@ -217,18 +217,34 @@ impl<W> Clone for StaticWidgetId<W> {
impl<W> Copy for StaticWidgetId<W> {}
pub trait IdLike<W> {
pub trait WidgetIdLike<W> {
fn id(self, send: &Sender<Id>) -> WidgetId<W>;
}
impl<W> IdLike<W> for &WidgetId<W> {
impl<W> WidgetIdLike<W> for &WidgetId<W> {
fn id(self, _: &Sender<Id>) -> WidgetId<W> {
self.clone()
}
}
impl<W> IdLike<W> for StaticWidgetId<W> {
impl<W> WidgetIdLike<W> for StaticWidgetId<W> {
fn id(self, send: &Sender<Id>) -> WidgetId<W> {
self.to_id(send)
}
}
pub trait IdLike<W> {
fn id(&self) -> Id;
}
impl<W> IdLike<W> for WidgetId<W> {
fn id(&self) -> Id {
self.id
}
}
impl<W> IdLike<W> for StaticWidgetId<W> {
fn id(&self) -> Id {
self.id
}
}

View File

@@ -3,7 +3,8 @@ use image::DynamicImage;
use crate::{
core::{TextEdit, TextEditCtx},
layout::{
PainterCtx, PainterData, StaticWidgetId, TextureHandle, Vec2, Widget, WidgetId, WidgetLike,
IdLike, PainterCtx, PainterData, StaticWidgetId, TextureHandle, Vec2, Widget, WidgetId,
WidgetLike,
},
util::Id,
};
@@ -69,11 +70,11 @@ impl Ui {
Self::default()
}
pub fn get<W: Widget>(&self, id: &WidgetId<W>) -> Option<&W> {
pub fn get<W: Widget>(&self, id: &impl IdLike<W>) -> Option<&W> {
self.data.widgets.get(id)
}
pub fn get_mut<W: Widget>(&mut self, id: &WidgetId<W>) -> Option<&mut W> {
pub fn get_mut<W: Widget>(&mut self, id: &impl IdLike<W>) -> Option<&mut W> {
self.data.widgets.get_mut(id)
}
@@ -162,8 +163,8 @@ impl Ui {
self.data.active.len()
}
pub fn text(&mut self, id: &WidgetId<TextEdit>) -> TextEditCtx<'_> {
self.updates.push(id.id);
pub fn text(&mut self, id: &impl IdLike<TextEdit>) -> TextEditCtx<'_> {
self.updates.push(id.id());
TextEditCtx {
text: self.data.widgets.get_mut(id).unwrap(),
font_system: &mut self.data.text.font_system,
@@ -190,14 +191,14 @@ impl<W: Widget> Index<StaticWidgetId<W>> for Ui {
type Output = W;
fn index(&self, id: StaticWidgetId<W>) -> &Self::Output {
self.data.widgets.get_static(&id).unwrap()
self.data.widgets.get(&id).unwrap()
}
}
impl<W: Widget> IndexMut<StaticWidgetId<W>> for Ui {
fn index_mut(&mut self, id: StaticWidgetId<W>) -> &mut Self::Output {
self.updates.push(id.id);
self.data.widgets.get_static_mut(&id).unwrap()
self.data.widgets.get_mut(&id).unwrap()
}
}

View File

@@ -1,5 +1,5 @@
use crate::{
layout::{StaticWidgetId, Widget, WidgetId},
layout::{IdLike, Widget},
util::{DynBorrower, HashMap, Id, IdTracker},
};
@@ -47,20 +47,12 @@ impl Widgets {
WidgetWrapper::new(data.widget.as_mut(), &mut data.borrowed)
}
pub fn get_static<W: Widget>(&self, id: &StaticWidgetId<W>) -> Option<&W> {
self.get_dyn(id.id)?.as_any().downcast_ref()
pub fn get<W: Widget>(&self, id: &impl IdLike<W>) -> Option<&W> {
self.get_dyn(id.id())?.as_any().downcast_ref()
}
pub fn get_static_mut<W: Widget>(&mut self, id: &StaticWidgetId<W>) -> Option<&mut W> {
self.get_dyn_mut(id.id)?.as_any_mut().downcast_mut()
}
pub fn get<W: Widget>(&self, id: &WidgetId<W>) -> Option<&W> {
self.get_dyn(id.id)?.as_any().downcast_ref()
}
pub fn get_mut<W: Widget>(&mut self, id: &WidgetId<W>) -> Option<&mut W> {
self.get_dyn_mut(id.id)?.as_any_mut().downcast_mut()
pub fn get_mut<W: Widget>(&mut self, id: &impl IdLike<W>) -> Option<&mut W> {
self.get_dyn_mut(id.id())?.as_any_mut().downcast_mut()
}
pub fn insert<W: Widget>(&mut self, id: Id, widget: W) {