snap text on shader
This commit is contained in:
@@ -19,8 +19,8 @@ pub struct Ui<Ctx> {
|
||||
base: Option<WidgetId>,
|
||||
widgets: Widgets<Ctx>,
|
||||
updates: Vec<WidgetId>,
|
||||
recv: Receiver<UiMsg>,
|
||||
send: UiMsgSender,
|
||||
recv: Receiver<Id>,
|
||||
send: Sender<Id>,
|
||||
size: Vec2,
|
||||
// TODO: make these non pub(crate)
|
||||
pub(crate) primitives: Primitives,
|
||||
@@ -32,12 +32,6 @@ pub struct Ui<Ctx> {
|
||||
pub(super) sensor_map: SensorMap<Ctx>,
|
||||
}
|
||||
|
||||
pub enum UiMsg {
|
||||
FreeWidget(Id),
|
||||
FreeTexture(u32),
|
||||
}
|
||||
pub type UiMsgSender = Sender<UiMsg>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Widgets<Ctx> {
|
||||
ids: IdTracker,
|
||||
@@ -96,7 +90,6 @@ impl<Ctx> Ui<Ctx> {
|
||||
|
||||
pub fn resize(&mut self, size: impl Into<Vec2>) {
|
||||
self.size = size.into();
|
||||
self.full_redraw = true;
|
||||
}
|
||||
|
||||
pub fn redraw_all(&mut self, ctx: &mut Ctx)
|
||||
@@ -105,6 +98,7 @@ impl<Ctx> Ui<Ctx> {
|
||||
{
|
||||
self.active_sensors.clear();
|
||||
self.primitives.clear();
|
||||
self.free();
|
||||
let mut painter = Painter::new(
|
||||
&self.widgets,
|
||||
&mut self.primitives,
|
||||
@@ -124,8 +118,6 @@ impl<Ctx> Ui<Ctx> {
|
||||
where
|
||||
Ctx: 'static,
|
||||
{
|
||||
self.recv_msgs();
|
||||
|
||||
if self.full_redraw {
|
||||
self.redraw_all(ctx);
|
||||
self.full_redraw = false;
|
||||
@@ -136,13 +128,12 @@ impl<Ctx> Ui<Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn recv_msgs(&mut self) {
|
||||
while let Ok(msg) = self.recv.try_recv() {
|
||||
match msg {
|
||||
UiMsg::FreeWidget(id) => self.widgets.delete(id),
|
||||
UiMsg::FreeTexture(id) => self.textures.free(id),
|
||||
}
|
||||
/// free any resources that don't have references anymore
|
||||
fn free(&mut self) {
|
||||
for id in self.recv.try_iter() {
|
||||
self.widgets.delete(id);
|
||||
}
|
||||
self.textures.free();
|
||||
}
|
||||
|
||||
pub fn needs_redraw(&self) -> bool {
|
||||
@@ -237,7 +228,7 @@ impl<Ctx: 'static> Default for Ui<Ctx> {
|
||||
widgets: Widgets::new(),
|
||||
updates: Default::default(),
|
||||
primitives: Default::default(),
|
||||
textures: Textures::new(send.clone()),
|
||||
textures: Textures::new(),
|
||||
text: TextData::default(),
|
||||
full_redraw: false,
|
||||
active_sensors: Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user