Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upMajor redesign #713
Comments
bvssvni
added
draft
discussion
labels
Nov 29, 2014
This comment has been minimized.
This comment has been minimized.
|
Perhaps we could use the |
This comment has been minimized.
This comment has been minimized.
|
This reminds me of PistonDevelopers/piston#736 where you blur out the distinction between state and function. |
This comment has been minimized.
This comment has been minimized.
|
One approach is to use context types, but with defaults set to concrete types. The drawback is that you have to use traits: #![feature(default_type_params)]
pub struct Image<C = [f32, ..4], SR = [i32, ..4]> {
pub color: C,
pub source_rectangle: SR
}
pub trait DrawImage {
fn draw(&self);
}
impl DrawImage for Image {
fn draw(&self) {}
}
impl DrawImage for Image<(), ()> {
fn draw(&self) {}
}
fn main() {
Image { color: (), source_rectangle: () }.draw();
} |
This comment has been minimized.
This comment has been minimized.
|
Another approach is to use pub struct Image {
pub color: Option<[f32, ..4]>,
pub source_rectangle: Option<[i32, ..4]>
}
impl Image {
pub fn draw(&self) {}
}
fn main() {
Image { color: None, source_rectangle: None }.draw();
}This could be used like this: Image::new().set(Color(...)).set(SourceRectangle(...)).draw(texture, c, g); |
This comment has been minimized.
This comment has been minimized.
|
One benefit by separating the shape is that you can reuse and modify how you draw in multiple ways and it does not depend on the type. For example, you can change the color by adding your own ways of modifying it in an ad-hoc way. You can also write a different draw method for another texture type. |
This comment has been minimized.
This comment has been minimized.
|
Done. |
bvssvni commentedNov 29, 2014
Example:
I want to investigate an alternative design, where each drawable shape is a type, such that it can be used without transformation context.
pubfieldsContextshould only contain view and transform matrixDrawable shapes:
Todo: