Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Issue with conrod: trait backend::piston::draw::Graphics is not implemented
[package]
name = "goggles"
version = "0.1.0"
authors = ["Sirius Wu <ccwu660601@gmail.com>"]
[dependencies]
piston_window = "*"
[dependencies.conrod]
version = "*"
features = ["piston"]
Compiling goggles v0.1.0 (file:///home/ccwu/git/botnana/goggles)
error[E0308]: mismatched types
--> src/main.rs:84:59
|
84 | context,
| ^^^^^^^ expected struct `conrod::backend::piston::draw::Context`, found struct `piston_window::Context`
|
= note: expected type `conrod::backend::piston::draw::Context`
= note: found type `piston_window::Context`
error[E0277]: the trait bound `gfx_graphics::back_end::GfxGraphics<'_, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>: conrod::backend::piston::draw::Graphics` is not satisfied
--> src/main.rs:83:17
|
83 | conrod::backend::piston::draw::primitives(primitives,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `conrod::backend::piston::draw::Graphics` is not implemented for `gfx_graphics::back_end::GfxGraphics<'_, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>`
|
= note: required by `conrod::backend::piston::draw::primitives`
error: aborting due to 2 previous errors
error: Could not compile `goggles`.
extern crate piston_window;
#[macro_use]
extern crate conrod;
use piston_window::{PistonWindow, WindowSettings, Graphics, G2dTexture, TextureSettings, G2d};
use piston_window::texture::UpdateTexture;
widget_ids! {
pub struct Ids {
master,
header,
body,
left_column,
middle_column,
right_column,
footer,
}
}
fn gui(ref mut ui: conrod::UiCell, ids: &mut Ids) {
use conrod::{widget, Widget, Colorable, color};
widget::Canvas::new().flow_down(&[
(ids.header, widget::Canvas::new().color(color::BLUE).pad_bottom(20.0)),
(ids.body, widget::Canvas::new().length(300.0).flow_right(&[
(ids.left_column, widget::Canvas::new().color(color::LIGHT_ORANGE).pad(20.0)),
(ids.middle_column, widget::Canvas::new().color(color::ORANGE)),
(ids.right_column, widget::Canvas::new().color(color::DARK_ORANGE).pad(20.0)),
])),
(ids.footer, widget::Canvas::new().color(color::BLUE)),
]).set(ids.master, ui);
}
pub fn main() {
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
let mut window: PistonWindow = WindowSettings::new("Goggles", [WIDTH, HEIGHT])
.exit_on_esc(true)
.build()
.unwrap_or_else(|e| {
panic!("Failed to build PistonWindow: {}", e)
});
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
// Create a texture to use for efficiently caching text on the GPU.
let mut text_vertex_data = Vec::new();
let (mut glyph_cache, mut text_texture_cache) = {
const SCALE_TOLERANCE: f32 = 0.1;
const POSITION_TOLERANCE: f32 = 0.1;
let cache = conrod::text::GlyphCache::new(WIDTH,
HEIGHT,
SCALE_TOLERANCE,
POSITION_TOLERANCE);
let buffer_len = WIDTH as usize * HEIGHT as usize;
let init = vec![128; buffer_len];
let settings = TextureSettings::new();
let factory = &mut window.factory;
let texture = G2dTexture::from_memory_alpha(factory, &init, WIDTH, HEIGHT, &settings)
.unwrap();
(cache, texture)
};
let mut ids = Ids::new(ui.widget_id_generator());
let mut image_map = conrod::image::Map::new();
while let Some(event) = window.next() {
gui(ui.set_widgets(), &mut ids);
window.draw_2d(&event, |context, graphics| {
let cache_queued_glyphs = |graphics: &mut G2d,
cache: &mut G2dTexture,
rect: conrod::text::rt::Rect<u32>,
data: &[u8]| {
let offset = [rect.min.x, rect.min.y];
let size = [rect.width(), rect.height()];
let format = piston_window::texture::Format::Rgba8;
let encoder = &mut graphics.encoder;
text_vertex_data.clear();
text_vertex_data.extend(data.iter().flat_map(|&b| vec![255, 255, 255, b]));
UpdateTexture::update(cache, encoder, format, &text_vertex_data[..], offset, size)
.expect("failed to update texture")
};
fn texture_from_image<T>(img: &T) -> &T {
img
}
if let Some(primitives) = ui.draw_if_changed() {
conrod::backend::piston::draw::primitives(primitives,
context,
graphics,
&mut text_texture_cache,
&mut glyph_cache,
&image_map,
cache_queued_glyphs,
texture_from_image);
}
});
}
}
@simon-whitehead

This comment has been minimized.

Copy link

commented Oct 16, 2017

Hi - did you ever fix this? I have this exact issue and I'm unsure how to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.