made painter actually how I wanted it (draw now takes in an owned painter)

This commit is contained in:
2025-08-23 15:20:25 -04:00
parent 6fbdf9fbc8
commit 2ffb09bef0
10 changed files with 60 additions and 50 deletions

View File

@@ -6,9 +6,8 @@ pub struct Regioned {
}
impl<Ctx: 'static> Widget<Ctx> for Regioned {
fn draw(&self, painter: &mut Painter<Ctx>) {
painter.region.select(&self.region);
painter.draw_inner(&self.inner);
fn draw(&self, mut painter: Painter<Ctx>) {
painter.draw_within(&self.inner, self.region);
}
}

View File

@@ -1,13 +1,13 @@
use image::DynamicImage;
use crate::{Color, TextureHandle, Widget, WidgetFnRet, render::RectPrimitive};
use crate::{Color, Painter, TextureHandle, Widget, WidgetFnRet, render::RectPrimitive};
pub struct Image {
handle: Option<TextureHandle>,
}
impl<Ctx> Widget<Ctx> for Image {
fn draw(&self, painter: &mut crate::Painter<Ctx>) {
fn draw(&self, mut painter: Painter<Ctx>) {
if let Some(handle) = &self.handle {
painter.draw_texture(handle);
} else {

View File

@@ -28,7 +28,7 @@ impl Rect {
}
impl<Ctx> Widget<Ctx> for Rect {
fn draw(&self, painter: &mut Painter<Ctx>) {
fn draw(&self, mut painter: Painter<Ctx>) {
painter.write(RectPrimitive {
color: self.color,
radius: self.radius,

View File

@@ -6,7 +6,7 @@ pub struct Span {
}
impl<Ctx: 'static> Widget<Ctx> for Span {
fn draw(&self, painter: &mut Painter<Ctx>) {
fn draw(&self, mut painter: Painter<Ctx>) {
let total = self.sums();
let mut start = UIScalar::min();
for (child, length) in &self.children {

View File

@@ -1,11 +1,11 @@
use crate::{Widget, WidgetId};
use crate::{Painter, Widget, WidgetId};
pub struct Stack {
pub children: Vec<WidgetId>,
}
impl<Ctx> Widget<Ctx> for Stack {
fn draw(&self, painter: &mut crate::Painter<Ctx>) {
fn draw(&self, mut painter: Painter<Ctx>) {
for child in &self.children {
painter.draw(child);
}