I forgot why I did it the other way lol (revert)
This commit is contained in:
@@ -6,7 +6,7 @@ pub struct Regioned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx: 'static> Widget<Ctx> for Regioned {
|
impl<Ctx: 'static> Widget<Ctx> for Regioned {
|
||||||
fn draw(&self, mut painter: Painter<Ctx>) {
|
fn draw(&self, painter: &mut Painter<Ctx>) {
|
||||||
painter.draw_within(&self.inner, self.region);
|
painter.draw_within(&self.inner, self.region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pub struct Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx> Widget<Ctx> for Image {
|
impl<Ctx> Widget<Ctx> for Image {
|
||||||
fn draw(&self, mut painter: Painter<Ctx>) {
|
fn draw(&self, painter: &mut Painter<Ctx>) {
|
||||||
if let Some(handle) = &self.handle {
|
if let Some(handle) = &self.handle {
|
||||||
painter.draw_texture(handle);
|
painter.draw_texture(handle);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ impl Rect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx> Widget<Ctx> for Rect {
|
impl<Ctx> Widget<Ctx> for Rect {
|
||||||
fn draw(&self, mut painter: Painter<Ctx>) {
|
fn draw(&self, painter: &mut Painter<Ctx>) {
|
||||||
painter.write(RectPrimitive {
|
painter.write(RectPrimitive {
|
||||||
color: self.color,
|
color: self.color,
|
||||||
radius: self.radius,
|
radius: self.radius,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ pub struct Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx: 'static> Widget<Ctx> for Span {
|
impl<Ctx: 'static> Widget<Ctx> for Span {
|
||||||
fn draw(&self, mut painter: Painter<Ctx>) {
|
fn draw(&self, painter: &mut Painter<Ctx>) {
|
||||||
let total = self.sums();
|
let total = self.sums();
|
||||||
let mut start = UIScalar::min();
|
let mut start = UIScalar::min();
|
||||||
for (child, length) in &self.children {
|
for (child, length) in &self.children {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ pub struct Stack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx> Widget<Ctx> for Stack {
|
impl<Ctx> Widget<Ctx> for Stack {
|
||||||
fn draw(&self, mut painter: Painter<Ctx>) {
|
fn draw(&self, painter: &mut Painter<Ctx>) {
|
||||||
for child in &self.children {
|
for child in &self.children {
|
||||||
painter.draw(child);
|
painter.draw(child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,20 +60,22 @@ impl<'a, Ctx> Painter<'a, Ctx> {
|
|||||||
if self.sensors_map.get(&id.id).is_some() {
|
if self.sensors_map.get(&id.id).is_some() {
|
||||||
self.active_sensors.push((region, id.id.duplicate()));
|
self.active_sensors.push((region, id.id.duplicate()));
|
||||||
}
|
}
|
||||||
self.nodes.get_dyn(id).draw(Painter {
|
// &mut self is passed to avoid copying all of the "static" pointers in self
|
||||||
nodes: self.nodes,
|
// so need to save non static data here
|
||||||
ctx: self.ctx,
|
let old = self.region;
|
||||||
sensors_map: self.sensors_map,
|
self.region = region;
|
||||||
active_sensors: self.active_sensors,
|
self.nodes.get_dyn(id).draw(self);
|
||||||
primitives: self.primitives,
|
self.region = old;
|
||||||
region,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_texture(&mut self, handle: &TextureHandle) {
|
pub fn draw_texture(&mut self, handle: &TextureHandle) {
|
||||||
self.write(handle.inner);
|
self.write(handle.inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn region(&self) -> UiRegion {
|
||||||
|
self.region
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ctx(&mut self) -> &mut Ctx {
|
pub fn ctx(&mut self) -> &mut Ctx {
|
||||||
self.ctx
|
self.ctx
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::{Painter, Ui, WidgetId, WidgetIdFnRet};
|
|||||||
use std::{any::Any, marker::PhantomData};
|
use std::{any::Any, marker::PhantomData};
|
||||||
|
|
||||||
pub trait Widget<Ctx>: Any {
|
pub trait Widget<Ctx>: Any {
|
||||||
fn draw(&self, painter: Painter<Ctx>);
|
fn draw(&self, painter: &mut Painter<Ctx>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WidgetTag;
|
pub struct WidgetTag;
|
||||||
|
|||||||
Reference in New Issue
Block a user