diff --git a/examples/dial_test2.rs b/examples/dial_test2.rs new file mode 100644 index 0000000000000000000000000000000000000000..cfad4d7372c0137465437589e311fa638ee49109 --- /dev/null +++ b/examples/dial_test2.rs @@ -0,0 +1,103 @@ +// Copyright 2019 The xi-editor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! An example of an animating widget. + +use std::f64::consts::PI; + +use druid::kurbo::{BezPath, Line}; +use druid::widget::{Flex, Label, WidgetExt}; +use druid::{ + AppLauncher, BoxConstraints, Color, Data, Env, Event, EventCtx, LayoutCtx, Lens, LensWrap, + LinearGradient, PaintCtx, PlatformError, Point, RenderContext, Size, UnitPoint, UpdateCtx, + Vec2, WheelEvent, Widget, WindowDesc, +}; + +use log::info; + +use druid_widgets::*; + +#[derive(Clone, Data, Lens)] +struct DialData { + value: f64, + value2: f64, +} + +fn build_app() -> impl Widget<(DialData)> { + let solid = Color::rgb8(0x3a, 0x3a, 0x3a); + let gradient = LinearGradient::new( + UnitPoint::TOP_LEFT, + UnitPoint::BOTTOM_RIGHT, + (Color::rgb8(0x11, 0x11, 0x11), Color::rgb8(0xbb, 0xbb, 0xbb)), + ); + + Flex::column() + .with_child( + Flex::row() + .with_child( + Label::new("top left") + .background(solid.clone()) + .padding(10.0), + 1.0, + ) + .with_child( + LensWrap::new(Dial::new(Size::new(100.0, 100.0)), DialData::value) + .background(solid.clone()) + .padding(10.0), + 0.0, + ) + .with_child( + LensWrap::new(Dial::new(Size::new(200.0, 200.0)), DialData::value2) + .background(solid.clone()) + .padding(10.0), + 0.0, + ) + .with_child( + Label::new("top right") + .background(solid.clone()) + .padding(10.0), + 1.0, + ), + 0.0, // vertical + ) + .with_child( + Flex::row() + .with_child( + Label::new("bottom left") + .background(gradient.clone()) + .rounded(10.0) + .padding(10.0), + 0.0, + ) + .with_child( + Label::new("bottom right") + .border(solid.clone(), 4.0) + .rounded(10.0) + .padding(10.0), + 1.0, + ), + 1.0, + ) +} + +fn main() -> Result<(), PlatformError> { + AppLauncher::with_window(WindowDesc::new(build_app)) + .use_simple_logger() + .launch(DialData { + value: 0.0, + value2: 1.0, + })?; + + Ok(()) +}