Coder Social home page Coder Social logo

plotters-cairo's Introduction

plotters-cairo - The Cairo/GTK backend for Plotters

This is a part of plotters project. For more details, please check the following links:

plotters-cairo's People

Contributors

38 avatar aaronerhardt avatar dependabot-preview[bot] avatar dependabot[bot] avatar dusterthefirst avatar facorread avatar feng23 avatar nokyan avatar nuald avatar sdroege avatar waroengzapa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

plotters-cairo's Issues

Pan/zoom controls?

Is there are a feature to pan and zoom the rendering or a plan to add this feature?

Publish version update on crates.io

Hey, I wanted to ask whether someone could put the breaking version changes for cairo-rs to 0.17.X on crates.io?
Currently in the git version plotters-backend is pulled from the plotters-rs/plotters git which clashes (for some reason) with the plotters-rs 0.3.4 release.

Thank you in advance!

Publish a new version to crates.io

Hi @38,
The current git version uses cairo-rs == "^0.15.1" but the one on crates.io still depends on "^0.9.1". Would you mind publishing a new version to crates.io?

GTK4 compatibility - DrawingBackend trait unimplemented for CairoBackend

Hello,
I try to use plotters-cairo with plotters-rs and gtk-rs in a gtk4 app. I made a minimal example to showcase the problem:

Cargo.toml

name = "cairotest"
version = "0.1.0"
edition = "2021"

[dependencies]
gtk = { version = "0.5.2", package = "gtk4", features = ["v4_8"] }
plotters = "0.3.4"
plotters-cairo = {git = "https://github.com/plotters-rs/plotters-cairo.git",rev ="51326436fc6a001a2084327a3c58d6f365be858c" }

main.rs

use plotters::backend::DrawingBackend;
use plotters::drawing::IntoDrawingArea;
use plotters_cairo::CairoBackend;

fn main() {
    let app = Application::builder().application_id("lambda").build();

    let builder = gtk::Builder::from_file("file.ui");
    let window = builder.object::<gtk::Window>("MainWindow").unwrap();
    window.set_application(Some(&app));
    window.set_title(Some("Cairo test App"));

    let drawing_area: gtk::DrawingArea = builder.object("MainDrawingArea").unwrap();

    drawing_area.set_draw_func(move |widget, cr, w, h| {
        let backend = CairoBackend::new(cr, (w as u32, h as u32)).unwrap();

        do_with_backend(backend);
    });
}

fn do_with_backend<'a, DB>(backend: DB)
where
    DB: DrawingBackend + 'a,
{
    let drawing_area = backend.into_drawing_area();
    todo!()
}

At compile time I get the 2 followings errors:
Error 1

  --> src/main.rs:18:41
   |
18 |         let backend = CairoBackend::new(cr, (w as u32, h as u32)).unwrap();
   |                       ----------------- ^^ expected struct `cairo::context::Context`, found struct `gtk4::cairo::Context`
   |                       |
   |                       arguments to this function are incorrect
   |
   = note: struct `gtk4::cairo::Context` and struct `cairo::context::Context` have similar names, but are actually distinct types
note: struct `gtk4::cairo::Context` is defined in crate `cairo`
  --> /home/joceran/.cargo/registry/src/github.com-1ecc6299db9ec823/cairo-rs-0.16.3/src/context.rs:72:1
   |
72 | pub struct Context(ptr::NonNull<cairo_t>);
   | ^^^^^^^^^^^^^^^^^^
note: struct `cairo::context::Context` is defined in crate `cairo`
  --> /home/joceran/.cargo/registry/src/github.com-1ecc6299db9ec823/cairo-rs-0.15.12/src/context.rs:72:1
   |
72 | pub struct Context(ptr::NonNull<cairo_t>);
   | ^^^^^^^^^^^^^^^^^^
   = note: perhaps two different versions of crate `cairo` are being used?
note: associated function defined here
  --> /home/joceran/.cargo/git/checkouts/plotters-cairo-14b56b08bd22bd2d/5132643/src/backend.rs:70:12
   |
70 |     pub fn new(context: &'a CairoContext, (w, h): (u32, u32)) -> Result<Self, CairoError> {
   |            ^^^

It looks like Gtk4 cairo::Context isn't the same as the cairo::Context referred by plotters-cairo.

Error 2

error[E0277]: the trait bound `CairoBackend<'_>: DrawingBackend` is not satisfied
  --> src/main.rs:20:25
   |
20 |         do_with_backend(backend);
   |         --------------- ^^^^^^^ the trait `DrawingBackend` is not implemented for `CairoBackend<'_>`
   |         |
   |         required by a bound introduced by this call
   |
   = help: the following other types implement trait `DrawingBackend`:
             BitMapBackend<'a, P>
             SVGBackend<'a>
note: required by a bound in `do_with_backend`
  --> src/main.rs:26:9
   |
24 | fn do_with_backend<'a, DB>(backend: DB)
   |    --------------- required by a bound in this
25 | where
26 |     DB: DrawingBackend + 'a,
   |         ^^^^^^^^^^^^^^ required by this bound in `do_with_backend`

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `cairotest` due to 2 previous errors

The DrawingBackend is in scope and I checked cairo-plotters backend.rs : DrawingBackend trait is implemented but somehow is unreachable.

I suppose that plotters-rs and cairo-plotters aren't compatible with gtk4 for now, or I am just mistaken and do something wrong?

Bump plotters-cairo version

After the PR from yesterday with cairo 20 was merged we need a new release of plotters-cairo. For now I have to use git version in my Cargo.toml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.