move widgets on draw if region size is same
This commit is contained in:
@@ -24,22 +24,22 @@ impl Widgets {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_dyn(&self, id: &Id) -> Option<&dyn Widget> {
|
||||
Some(self.map.get(id)?.widget.as_ref())
|
||||
pub fn get_dyn(&self, id: Id) -> Option<&dyn Widget> {
|
||||
Some(self.map.get(&id)?.widget.as_ref())
|
||||
}
|
||||
|
||||
pub fn get_dyn_mut(&mut self, id: &Id) -> Option<&mut dyn Widget> {
|
||||
Some(self.map.get_mut(id)?.widget.as_mut())
|
||||
pub fn get_dyn_mut(&mut self, id: Id) -> Option<&mut dyn Widget> {
|
||||
Some(self.map.get_mut(&id)?.widget.as_mut())
|
||||
}
|
||||
|
||||
/// get_dyn but dynamic borrow checking of widgets
|
||||
/// lets you do recursive (tree) operations, like the painter does
|
||||
pub fn get_dyn_dynamic(&self, id: &Id) -> WidgetWrapper<'_> {
|
||||
pub fn get_dyn_dynamic(&self, id: Id) -> WidgetWrapper<'_> {
|
||||
// SAFETY: must guarantee no other mutable references to this widget exist
|
||||
// done through the borrow variable
|
||||
#[allow(mutable_transmutes)]
|
||||
let data = unsafe {
|
||||
std::mem::transmute::<&WidgetData, &mut WidgetData>(self.map.get(id).unwrap())
|
||||
std::mem::transmute::<&WidgetData, &mut WidgetData>(self.map.get(&id).unwrap())
|
||||
};
|
||||
if data.borrowed {
|
||||
panic!("tried to mutably borrow the same widget twice");
|
||||
@@ -48,19 +48,19 @@ impl Widgets {
|
||||
}
|
||||
|
||||
pub fn get_static<W: Widget>(&self, id: &StaticWidgetId<W>) -> Option<&W> {
|
||||
self.get_dyn(&id.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> {
|
||||
self.get_dyn_mut(&id.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()
|
||||
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()
|
||||
self.get_dyn_mut(id.id)?.as_any_mut().downcast_mut()
|
||||
}
|
||||
|
||||
pub fn insert<W: Widget>(&mut self, id: Id, widget: W) {
|
||||
|
||||
Reference in New Issue
Block a user