texture freeing + render updates done a bit nicer
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
use std::{
|
||||
any::TypeId,
|
||||
marker::PhantomData,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicU32, Ordering},
|
||||
mpsc::Sender,
|
||||
},
|
||||
};
|
||||
use std::{any::TypeId, marker::PhantomData};
|
||||
|
||||
use crate::{FnTag, Ui, Widget, WidgetLike, WidgetTag, util::Id};
|
||||
use crate::{
|
||||
FnTag, Ui, UiMsg, UiMsgSender, Widget, WidgetLike, WidgetTag,
|
||||
util::{Id, RefCounter},
|
||||
};
|
||||
|
||||
pub struct AnyWidget;
|
||||
|
||||
@@ -22,8 +17,8 @@ pub struct AnyWidget;
|
||||
pub struct WidgetId<W = AnyWidget> {
|
||||
pub(super) ty: TypeId,
|
||||
pub(super) id: Id,
|
||||
pub(super) refcount: Arc<AtomicU32>,
|
||||
pub(super) send: Sender<Id>,
|
||||
counter: RefCounter,
|
||||
send: UiMsgSender,
|
||||
_pd: PhantomData<W>,
|
||||
}
|
||||
|
||||
@@ -35,11 +30,10 @@ impl<W> std::fmt::Debug for WidgetId<W> {
|
||||
|
||||
impl<W> Clone for WidgetId<W> {
|
||||
fn clone(&self) -> Self {
|
||||
self.refcount.fetch_add(1, Ordering::Release);
|
||||
Self {
|
||||
id: self.id.duplicate(),
|
||||
ty: self.ty,
|
||||
refcount: self.refcount.clone(),
|
||||
counter: self.counter.clone(),
|
||||
send: self.send.clone(),
|
||||
_pd: PhantomData,
|
||||
}
|
||||
@@ -47,11 +41,11 @@ impl<W> Clone for WidgetId<W> {
|
||||
}
|
||||
|
||||
impl<W> WidgetId<W> {
|
||||
pub(super) fn new(id: Id, ty: TypeId, send: Sender<Id>) -> Self {
|
||||
pub(super) fn new(id: Id, ty: TypeId, send: UiMsgSender) -> Self {
|
||||
Self {
|
||||
ty,
|
||||
id,
|
||||
refcount: AtomicU32::new(0).into(),
|
||||
counter: RefCounter::new(),
|
||||
send,
|
||||
_pd: PhantomData,
|
||||
}
|
||||
@@ -72,15 +66,14 @@ impl<W> WidgetId<W> {
|
||||
}
|
||||
|
||||
pub fn refs(&self) -> u32 {
|
||||
self.refcount.load(Ordering::Acquire)
|
||||
self.counter.refs()
|
||||
}
|
||||
}
|
||||
|
||||
impl<W> Drop for WidgetId<W> {
|
||||
fn drop(&mut self) {
|
||||
let refs = self.refcount.fetch_sub(1, Ordering::Release);
|
||||
if refs == 0 {
|
||||
let _ = self.send.send(self.id.duplicate());
|
||||
if self.counter.drop() {
|
||||
let _ = self.send.send(UiMsg::FreeWidget(self.id.duplicate()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user