Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Path::line is invisible in Canvas #2281

Closed
2 tasks done
fogarecious opened this issue Feb 22, 2024 · 3 comments · Fixed by #2282
Closed
2 tasks done

Some Path::line is invisible in Canvas #2281

fogarecious opened this issue Feb 22, 2024 · 3 comments · Fixed by #2282
Labels
bug Something isn't working

Comments

@fogarecious
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

In the clock example, seconds hand disappears when pointing at 0, 15, 30, and 45.
2

It seems that Path::line will not be drawn when the line is horizontal or vertical. The following code shows this:

use iced::{
    mouse,
    widget::{
        canvas::{Frame, Geometry, Path, Program, Stroke},
        Canvas,
    },
    Color, Length, Rectangle, Renderer, Sandbox, Settings, Theme,
};

fn main() -> iced::Result {
    MyApp::run(Settings::default())
}

struct MyApp;

impl Sandbox for MyApp {
    type Message = ();

    fn new() -> Self {
        Self
    }

    fn title(&self) -> String {
        "".into()
    }

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

    fn view(&self) -> iced::Element<'_, Self::Message> {
        Canvas::new(MyProgram)
            .width(Length::Fill)
            .height(Length::Fill)
            .into()
    }
}

struct MyProgram;

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

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

        frame.stroke(
            &Path::line([0.0, 100.0].into(), [1024.0, 100.0].into()),
            Stroke {
                style: Color::BLACK.into(),
                width: 50.0,
                ..Default::default()
            },
        );

        vec![frame.into_geometry()]
    }
}

However, if we change the code from

&Path::line([0.0, 100.0].into(), [1024.0, 100.0].into()),

to

&Path::line([0.0, 100.0].into(), [1024.0, 101.0].into()),

i.e., move the endpoint down a little bit, then the line is drawn as expected.

What is the expected behavior?

Path::line is drawn for all directions including vertical and horizontal.

Version

master

Operating System

macOS

Do you have any log output?

No response

@fogarecious fogarecious added the bug Something isn't working label Feb 22, 2024
@hecrj
Copy link
Member

hecrj commented Feb 22, 2024

Thanks for the report! This is a problem in iced_tiny_skia. #2282 should fix it.

@carlhammann
Copy link

@hecrj Is this issue really solved? On v0.13.1, which is currently the latetst on crates.io, I still see exactly the behaviour described by @fogarecious. I have to make a few adjustments to the original example code, but the essence remains the same for me (using Linux, Wayland, rustc 1.83.0-nightly).

adapted MWE
use iced::{
    mouse,
    widget::{
        canvas::{Frame, Geometry, Path, Program, Stroke},
        Canvas,
    },
    Color, Length, Rectangle, Renderer, Theme,
};

fn main() -> iced::Result {
    iced::run("", MyApp::update, MyApp::view)
}

#[derive(Default)]
struct MyApp;

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

    fn view(&self) -> iced::Element<'_, ()> {
        Canvas::new(MyProgram)
            .width(Length::Fill)
            .height(Length::Fill)
            .into()
    }
}

struct MyProgram;

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

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

        frame.stroke(
            &Path::line([0.0, 100.0].into(), [1024.0, 100.0].into()),
            Stroke {
                style: Color::BLACK.into(),
                width: 50.0,
                ..Default::default()
            },
        );

        vec![frame.into_geometry()]
    }
}

@Gibbz
Copy link

Gibbz commented Jan 29, 2025

I'm having a similar issue to this. Should we reopen a new issue? Or can we get this issue reopened?

I also have no way to change line ends to be square.

Edit, ive added a new bug report: #2765

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants