beginning actual app
This commit is contained in:
@@ -217,18 +217,34 @@ impl<W> Clone for StaticWidgetId<W> {
|
|||||||
|
|
||||||
impl<W> Copy 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>;
|
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> {
|
fn id(self, _: &Sender<Id>) -> WidgetId<W> {
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W> IdLike<W> for StaticWidgetId<W> {
|
impl<W> WidgetIdLike<W> for StaticWidgetId<W> {
|
||||||
fn id(self, send: &Sender<Id>) -> WidgetId<W> {
|
fn id(self, send: &Sender<Id>) -> WidgetId<W> {
|
||||||
self.to_id(send)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ use image::DynamicImage;
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::{TextEdit, TextEditCtx},
|
core::{TextEdit, TextEditCtx},
|
||||||
layout::{
|
layout::{
|
||||||
PainterCtx, PainterData, StaticWidgetId, TextureHandle, Vec2, Widget, WidgetId, WidgetLike,
|
IdLike, PainterCtx, PainterData, StaticWidgetId, TextureHandle, Vec2, Widget, WidgetId,
|
||||||
|
WidgetLike,
|
||||||
},
|
},
|
||||||
util::Id,
|
util::Id,
|
||||||
};
|
};
|
||||||
@@ -69,11 +70,11 @@ impl Ui {
|
|||||||
Self::default()
|
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)
|
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)
|
self.data.widgets.get_mut(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,8 +163,8 @@ impl Ui {
|
|||||||
self.data.active.len()
|
self.data.active.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text(&mut self, id: &WidgetId<TextEdit>) -> TextEditCtx<'_> {
|
pub fn text(&mut self, id: &impl IdLike<TextEdit>) -> TextEditCtx<'_> {
|
||||||
self.updates.push(id.id);
|
self.updates.push(id.id());
|
||||||
TextEditCtx {
|
TextEditCtx {
|
||||||
text: self.data.widgets.get_mut(id).unwrap(),
|
text: self.data.widgets.get_mut(id).unwrap(),
|
||||||
font_system: &mut self.data.text.font_system,
|
font_system: &mut self.data.text.font_system,
|
||||||
@@ -190,14 +191,14 @@ impl<W: Widget> Index<StaticWidgetId<W>> for Ui {
|
|||||||
type Output = W;
|
type Output = W;
|
||||||
|
|
||||||
fn index(&self, id: StaticWidgetId<W>) -> &Self::Output {
|
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 {
|
impl<W: Widget> IndexMut<StaticWidgetId<W>> for Ui {
|
||||||
fn index_mut(&mut self, id: StaticWidgetId<W>) -> &mut Self::Output {
|
fn index_mut(&mut self, id: StaticWidgetId<W>) -> &mut Self::Output {
|
||||||
self.updates.push(id.id);
|
self.updates.push(id.id);
|
||||||
self.data.widgets.get_static_mut(&id).unwrap()
|
self.data.widgets.get_mut(&id).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
layout::{StaticWidgetId, Widget, WidgetId},
|
layout::{IdLike, Widget},
|
||||||
util::{DynBorrower, HashMap, Id, IdTracker},
|
util::{DynBorrower, HashMap, Id, IdTracker},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,20 +47,12 @@ impl Widgets {
|
|||||||
WidgetWrapper::new(data.widget.as_mut(), &mut data.borrowed)
|
WidgetWrapper::new(data.widget.as_mut(), &mut data.borrowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_static<W: Widget>(&self, id: &StaticWidgetId<W>) -> Option<&W> {
|
pub fn get<W: Widget>(&self, id: &impl IdLike<W>) -> Option<&W> {
|
||||||
self.get_dyn(id.id)?.as_any().downcast_ref()
|
self.get_dyn(id.id())?.as_any().downcast_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_static_mut<W: Widget>(&mut self, id: &StaticWidgetId<W>) -> Option<&mut W> {
|
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()
|
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 insert<W: Widget>(&mut self, id: Id, widget: W) {
|
pub fn insert<W: Widget>(&mut self, id: Id, widget: W) {
|
||||||
|
|||||||
Reference in New Issue
Block a user