Skip to content

Commit

Permalink
implement data for interpolation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JAicewizard committed Jan 13, 2021
1 parent 609d867 commit 7245cec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
26 changes: 6 additions & 20 deletions druid/examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,27 @@ static FILL_STRAT_OPTIONS: &[(&str, FillStrat)] = &[
("ScaleDown", FillStrat::ScaleDown),
];

static INTERPOLATION_MODE_OPTIONS: &[(&str, InterpolationModeData)] = &[
static INTERPOLATION_MODE_OPTIONS: &[(&str, InterpolationMode)] = &[
(
"Bilinear",
InterpolationModeData::new(InterpolationMode::Bilinear),
InterpolationMode::Bilinear,
),
(
"NearestNeighbor",
InterpolationModeData::new(InterpolationMode::NearestNeighbor),
InterpolationMode::NearestNeighbor,
),
];
#[derive(Clone, Data, Lens)]
struct AppState {
fill_strat: FillStrat,
interpolate: bool,
interpolation_mode: InterpolationModeData,
interpolation_mode: InterpolationMode,
fix_width: bool,
width: f64,
fix_height: bool,
height: f64,
}

#[derive(Clone, PartialEq)]
struct InterpolationModeData(InterpolationMode);

impl InterpolationModeData {
const fn new(mode: InterpolationMode) -> InterpolationModeData {
InterpolationModeData(mode)
}
}
impl druid::Data for InterpolationModeData {
fn same(&self, other: &InterpolationModeData) -> bool {
self.0 == other.0
}
}

/// builds a child Flex widget from some paramaters.
struct Rebuilder {
inner: Box<dyn Widget<AppState>>,
Expand Down Expand Up @@ -202,7 +188,7 @@ fn build_widget(state: &AppState) -> Box<dyn Widget<AppState>> {

let mut img = Image::new(png_data.clone()).fill_mode(state.fill_strat);
if state.interpolate {
img.set_interpolation_mode(state.interpolation_mode.0)
img.set_interpolation_mode(state.interpolation_mode)
}
let mut sized = SizedBox::new(img);
if state.fix_width {
Expand Down Expand Up @@ -231,7 +217,7 @@ pub fn main() {
let state = AppState {
fill_strat: FillStrat::Cover,
interpolate: true,
interpolation_mode: InterpolationModeData::new(InterpolationMode::Bilinear),
interpolation_mode: InterpolationMode::Bilinear,
fix_width: true,
width: 200.,
fix_height: true,
Expand Down
1 change: 1 addition & 0 deletions druid/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl_data_simple!(std::num::NonZeroU32);
impl_data_simple!(std::num::NonZeroU64);
impl_data_simple!(std::num::NonZeroU128);
impl_data_simple!(std::num::NonZeroUsize);
impl_data_simple!(druid::piet::InterpolationMode);
//TODO: remove me!?
impl_data_simple!(String);

Expand Down

0 comments on commit 7245cec

Please sign in to comment.