Skip to content

Clip text groups in tiny_skia backend#3360

Open
wbk wants to merge 1 commit into
iced-rs:masterfrom
wbk:fix/tiny-skia-text-clip
Open

Clip text groups in tiny_skia backend#3360
wbk wants to merge 1 commit into
iced-rs:masterfrom
wbk:fix/tiny-skia-text-clip

Conversation

@wbk

@wbk wbk commented Jun 12, 2026

Copy link
Copy Markdown

Before:

image

After:

image

This clips text in canvases similar to how 76b32d4 settled clipping for primitive groups

Repro:

use iced::mouse;
use iced::widget::canvas::{self, Geometry};
use iced::widget::{canvas as canvas_widget, container, row, space, text};
use iced::{alignment, Color, Element, Length, Point, Rectangle, Renderer, Theme};

fn main() -> iced::Result {
    std::env::set_var("ICED_BACKEND", "tiny-skia");
    iced::application(State::default, State::update, State::view).run()
}

#[derive(Default)]
struct State;

#[derive(Debug, Clone, Copy)]
enum Message {}

impl State {
    fn update(&mut self, _message: Message) {}

    fn view(&self) -> Element<Message> {
        row![
            text("this text gets painted over"),
            space::horizontal(),
            container(
                canvas_widget(self as &Self)
                    .width(Length::Fixed(160.0))
                    .height(Length::Fixed(90.0)),
            ),
        ]
        .padding(40)
        .into()
    }
}

impl canvas::Program<Message> for State {
    type State = ();

    fn draw(
        &self,
        _state: &Self::State,
        renderer: &Renderer,
        _theme: &Theme,
        bounds: Rectangle,
        _cursor: mouse::Cursor,
    ) -> Vec<Geometry> {
        let mut frame = canvas::Frame::new(renderer, bounds.size());

        frame.fill_text(canvas::Text {
            content: "OVERFLOWING CANVAS TEXT".to_string(),
            position: Point::new(-200.0, 30.0),
            color: Color::from_rgb(0.2, 0.6, 1.0),
            size: 36.0.into(),
            align_y: alignment::Vertical::Top,
            ..canvas::Text::default()
        });

        vec![frame.into_geometry()]
    }
}

@mahlquistj

Copy link
Copy Markdown

@wbk AFAIK, tiny-skia is being replaced by vello very soon: #3306

@wbk

wbk commented Jun 12, 2026

Copy link
Copy Markdown
Author

@wbk AFAIK, tiny-skia is being replaced by vello very soon: #3306

Oh interesting, that bench looks super compelling. This fixes some glaring issues in an app I'm working on, but I'd bet I lose nothing just letting it rot in a local fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants