Skip to content

Commit

Permalink
Merge pull request #380 from zaynetro/fix-widget-env-lens
Browse files Browse the repository at this point in the history
Fix lens method on WidgetExt
  • Loading branch information
zaynetro committed Dec 5, 2019
2 parents 61770e5 + acf0ecb commit caef3e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions druid/examples/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use druid::widget::{Checkbox, Either, Flex, Label, Padding, Slider};
use druid::{AppLauncher, Data, Lens, LensWrap, Widget, WindowDesc};
use druid::widget::{Checkbox, Either, Flex, Label, Slider, WidgetExt};
use druid::{AppLauncher, Data, Lens, Widget, WindowDesc};

#[derive(Clone, Default, Data, Lens)]
struct AppState {
Expand All @@ -34,14 +34,11 @@ fn ui_builder() -> impl Widget<AppState> {
let label = Label::new("Click to reveal slider");

let mut col = Flex::column();
col.add_child(
Padding::new(5.0, LensWrap::new(Checkbox::new(), AppState::which)),
0.0,
);
col.add_child(Checkbox::new().lens(AppState::which).padding(5.0), 0.0);
let either = Either::new(
|data, _env| data.which,
Padding::new(5.0, LensWrap::new(Slider::new(), AppState::value)),
Padding::new(5.0, label),
Slider::new().lens(AppState::value).padding(5.0),
label.padding(5.0),
);
col.add_child(either, 0.0);
col
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/widget_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub trait WidgetExt<T: Data>: Widget<T> + Sized + 'static {
///
/// [`LensWrap`]: ../struct.LensWrap.html
/// [`Lens`]: ../trait.Lens.html
fn lens<U: Data, L: Lens<T, U>>(self, lens: L) -> LensWrap<U, L, Self> {
fn lens<S: Data, L: Lens<S, T>>(self, lens: L) -> LensWrap<T, L, Self> {
LensWrap::new(self, lens)
}
}
Expand Down

0 comments on commit caef3e3

Please sign in to comment.