From 8d12489dbe704732b46bacbba9037418c0211482 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 12 May 2022 08:58:00 +0100 Subject: [PATCH] Mandlebrot/Clippy/doc fixes --- crates/kas-core/src/event/events.rs | 2 +- crates/kas-core/src/root.rs | 2 +- crates/kas-widgets/src/lib.rs | 6 ++---- crates/kas-widgets/src/view/driver.rs | 2 +- crates/kas-widgets/src/view/mod.rs | 3 ++- examples/mandlebrot/mandlebrot.rs | 14 ++++++++------ 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/kas-core/src/event/events.rs b/crates/kas-core/src/event/events.rs index cc86f7033..1f07da1d5 100644 --- a/crates/kas-core/src/event/events.rs +++ b/crates/kas-core/src/event/events.rs @@ -257,7 +257,7 @@ impl Event { Event::Activate => f(mgr), Event::Command(cmd, _) if cmd.is_activate() => f(mgr), Event::PressStart { source, coord, .. } if source.is_primary() => { - mgr.grab_press(id.clone(), source, coord, GrabMode::Grab, None); + mgr.grab_press(id, source, coord, GrabMode::Grab, None); Response::Used } Event::PressMove { source, cur_id, .. } => { diff --git a/crates/kas-core/src/root.rs b/crates/kas-core/src/root.rs index eb24af381..95c932fb9 100644 --- a/crates/kas-core/src/root.rs +++ b/crates/kas-core/src/root.rs @@ -81,7 +81,7 @@ impl RootWidget { /// Add a pop-up as a layer in the current window /// - /// Each [`Popup`] is assigned a [`WindowId`]; both are passed. + /// Each [`crate::Popup`] is assigned a [`WindowId`]; both are passed. pub fn add_popup(&mut self, mgr: &mut EventMgr, id: WindowId, popup: kas::Popup) { let index = self.popups.len(); self.popups.push((id, popup)); diff --git a/crates/kas-widgets/src/lib.rs b/crates/kas-widgets/src/lib.rs index 7a9506248..795feb9c0 100644 --- a/crates/kas-widgets/src/lib.rs +++ b/crates/kas-widgets/src/lib.rs @@ -5,9 +5,9 @@ //! KAS widget library //! -//! ## Dialogs +//! ## Dialogs / pre-made windows //! -//! - [`MessageBox`]: a simple window with a message and an "Ok" button +//! See [`dialog`] module. //! //! ## Container widgets //! @@ -16,8 +16,6 @@ //! - [`Stack`]: a stack of widgets in the same rect (TODO: `TabbedStack`) //! - [`List`]: a dynamic row / column of children //! - [`Splitter`]: similar to [`List`] but with resizing handles -//! - [`Window`] is usually the root widget and has special handling for -//! pop-ups and callbacks //! //! ## Menus //! diff --git a/crates/kas-widgets/src/view/driver.rs b/crates/kas-widgets/src/view/driver.rs index 2291571f7..9a45e8413 100644 --- a/crates/kas-widgets/src/view/driver.rs +++ b/crates/kas-widgets/src/view/driver.rs @@ -114,7 +114,7 @@ impl Driver for DefaultEdit { EditBox::new("".to_string()) } fn set(&self, widget: &mut Self::Widget, data: String) -> TkAction { - widget.set_string(data.to_string()) + widget.set_string(data) } } diff --git a/crates/kas-widgets/src/view/mod.rs b/crates/kas-widgets/src/view/mod.rs index 9f7086ad8..09ff26212 100644 --- a/crates/kas-widgets/src/view/mod.rs +++ b/crates/kas-widgets/src/view/mod.rs @@ -30,7 +30,8 @@ //! //! The user may implement a [`Driver`] or may use a standard one: //! -//! - [`driver::Default`] constructs a default view widget over various data types +//! - [`driver::DefaultView`] constructs a default view widget over various data types +//! - [`driver::DefaultEdit`] chooses a widget allowing editing of the shared data //! - [`driver::DefaultNav`] is a variant of the above, ensuring items support //! keyboard navigation (e.g. useful to allow selection of static items) //! - [`driver::CheckBox`] and [`driver::RadioBox`] support the `bool` type diff --git a/examples/mandlebrot/mandlebrot.rs b/examples/mandlebrot/mandlebrot.rs index 7b9bfcff0..1d335b2a8 100644 --- a/examples/mandlebrot/mandlebrot.rs +++ b/examples/mandlebrot/mandlebrot.rs @@ -18,7 +18,7 @@ use kas::prelude::*; use kas::shell::draw::{CustomPipe, CustomPipeBuilder, CustomWindow, DrawCustom, DrawPipe}; use kas::shell::Options; use kas::widgets::adapter::ReserveP; -use kas::widgets::{Label, Slider, Window}; +use kas::widgets::{Label, Slider}; #[cfg(not(feature = "shader64"))] type ShaderVec2 = Vec2; @@ -445,10 +445,10 @@ impl_scope! { } impl MandlebrotWindow { - fn new_window() -> Window { + fn new() -> MandlebrotWindow { let slider = Slider::new(0, 256, 1).with_value(64); let mbrot = Mandlebrot::new(); - let w = MandlebrotWindow { + MandlebrotWindow { core: Default::default(), label: Label::new(mbrot.loc()), iters: ReserveP::new(Label::from("64"), |size_mgr, axis| { @@ -456,8 +456,7 @@ impl_scope! { }), slider, mbrot, - }; - Window::new("Mandlebrot", w) + } } } impl Widget for Self { @@ -471,6 +470,9 @@ impl_scope! { } } } + impl Window for Self { + fn title(&self) -> &str { "Mandlebrot" } + } } fn main() -> kas::shell::Result<()> { @@ -479,6 +481,6 @@ fn main() -> kas::shell::Result<()> { let theme = kas::theme::FlatTheme::new().with_colours("dark"); kas::shell::Toolkit::new_custom(PipeBuilder, theme, Options::from_env())? - .with(MandlebrotWindow::new_window())? + .with(MandlebrotWindow::new())? .run() }