diff --git a/Cargo.toml b/Cargo.toml index d896626a3c06f32d60a5d4693b4af2b56803372a..2fb210f0b6307343971fc2c598fd6ae847ab50a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "envelop_edit" +name = "druid_widgets" version = "0.1.0" authors = ["Per Lindgren <per.lindgren@ltu.se>"] edition = "2018" diff --git a/examples/dial_test3.rs b/examples/dial_test3.rs new file mode 100644 index 0000000000000000000000000000000000000000..a96a6b34080df617a51ccb3534c7ea4b240390b5 --- /dev/null +++ b/examples/dial_test3.rs @@ -0,0 +1,61 @@ +// 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, Padding, 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 DialLabel { + value: f64, +} + +impl DialLabel { + fn new(text: String) -> impl Widget<DialLabel> { + let solid = Color::rgb8(0x3a, 0x3a, 0x3a); + + let label = + Label::new(move |data: &DialLabel, _env: &_| format!("{} {:.3}", text, data.value)); + let mut col = Flex::column(); + col.add_child( + Dial::new(Size::new(100.0, 100.0)) + .lens(DialLabel::value) + .background(solid.clone()) + .padding(5.0), + 0.0, + ); + col.add_child(label.padding(5.0).background(solid.clone()), 1.0); + col + } +} + +fn main() -> Result<(), PlatformError> { + AppLauncher::with_window(WindowDesc::new(|| DialLabel::new("Value".to_string()))) + .use_simple_logger() + .launch(DialLabel { value: 0.0 })?; + + Ok(()) +}