initial text impl
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
use image::DynamicImage;
|
||||
|
||||
use crate::{
|
||||
ActiveSensors, HashMap, Painter, SensorMap, TextureHandle, Textures, Widget, WidgetId,
|
||||
WidgetLike,
|
||||
HashMap,
|
||||
layout::{
|
||||
ActiveSensors, Painter, SensorMap, TextData, TextureHandle, Textures, Vec2, Widget,
|
||||
WidgetId, WidgetLike,
|
||||
},
|
||||
render::Primitives,
|
||||
util::{Id, IdTracker},
|
||||
};
|
||||
@@ -18,8 +21,11 @@ pub struct Ui<Ctx> {
|
||||
updates: Vec<WidgetId>,
|
||||
recv: Receiver<UiMsg>,
|
||||
send: UiMsgSender,
|
||||
size: Vec2,
|
||||
// TODO: make these non pub(crate)
|
||||
pub(crate) primitives: Primitives,
|
||||
pub(crate) textures: Textures,
|
||||
pub(crate) text: TextData,
|
||||
full_redraw: bool,
|
||||
|
||||
pub(super) active_sensors: ActiveSensors,
|
||||
@@ -85,7 +91,12 @@ impl<Ctx> Ui<Ctx> {
|
||||
}
|
||||
|
||||
pub fn add_texture(&mut self, image: DynamicImage) -> TextureHandle {
|
||||
self.textures.add(image, self.send.clone())
|
||||
self.textures.add(image)
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -100,6 +111,9 @@ impl<Ctx> Ui<Ctx> {
|
||||
ctx,
|
||||
&self.sensor_map,
|
||||
&mut self.active_sensors,
|
||||
&mut self.text,
|
||||
&mut self.textures,
|
||||
self.size,
|
||||
);
|
||||
if let Some(base) = &self.base {
|
||||
painter.draw(base);
|
||||
@@ -217,18 +231,20 @@ impl<Ctx> dyn Widget<Ctx> {
|
||||
|
||||
impl<Ctx: 'static> Default for Ui<Ctx> {
|
||||
fn default() -> Self {
|
||||
let (del_send, del_recv) = channel();
|
||||
let (send, recv) = channel();
|
||||
Self {
|
||||
base: Default::default(),
|
||||
widgets: Widgets::new(),
|
||||
updates: Default::default(),
|
||||
primitives: Default::default(),
|
||||
textures: Textures::default(),
|
||||
textures: Textures::new(send.clone()),
|
||||
text: TextData::default(),
|
||||
full_redraw: false,
|
||||
active_sensors: Default::default(),
|
||||
sensor_map: Default::default(),
|
||||
send: del_send,
|
||||
recv: del_recv,
|
||||
send,
|
||||
recv,
|
||||
size: Vec2::ZERO,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user