diff --git a/crates/kas-macros/src/widget.rs b/crates/kas-macros/src/widget.rs index eabc629fe..9eb0457be 100644 --- a/crates/kas-macros/src/widget.rs +++ b/crates/kas-macros/src/widget.rs @@ -687,9 +687,7 @@ pub fn widget(mut args: WidgetArgs, scope: &mut Scope) -> Result<()> { set_rect = quote! { ::set_rect(self, mgr, rect); }; - find_id = quote! { - ::find_id(self, coord) - }; + find_id = quote! { ::find_id(self, coord) }; fn_draw = Some(quote! { fn draw(&mut self, draw: ::kas::theme::DrawMgr) { ::draw(self, draw); diff --git a/crates/kas-resvg/src/canvas.rs b/crates/kas-resvg/src/canvas.rs index 9ffa0db6e..c3ac6fd67 100644 --- a/crates/kas-resvg/src/canvas.rs +++ b/crates/kas-resvg/src/canvas.rs @@ -46,7 +46,7 @@ impl_scope! { /// The canvas (re)creates the backing pixmap when the size is set and draws /// to the new pixmap immediately. If the canvas program is modified then /// [`Canvas::redraw`] must be called to update the pixmap. - #[derive(Clone, Debug,)] + #[derive(Clone, Debug)] #[widget] pub struct Canvas { core: widget_core!(), @@ -118,7 +118,8 @@ impl_scope! { if let Some((pm, h)) = self.pixmap.as_mut().zip(self.image.as_ref()) { pm.fill(Color::TRANSPARENT); self.program.draw(pm); - mgr.draw_shared().image_upload(h, pm.data(), ImageFormat::Rgba8); + mgr.draw_shared() + .image_upload(h, pm.data(), ImageFormat::Rgba8); } } } @@ -144,7 +145,8 @@ impl_scope! { program.draw(pm); let (w, h) = (pm.width(), pm.height()); let handle = mgr.draw_shared().image_alloc((w, h)).unwrap(); - mgr.draw_shared().image_upload(&handle, pm.data(), ImageFormat::Rgba8); + mgr.draw_shared() + .image_upload(&handle, pm.data(), ImageFormat::Rgba8); handle }); } diff --git a/crates/kas-resvg/src/svg.rs b/crates/kas-resvg/src/svg.rs index 185eaf08b..359549a3f 100644 --- a/crates/kas-resvg/src/svg.rs +++ b/crates/kas-resvg/src/svg.rs @@ -50,9 +50,7 @@ impl_scope! { pub fn load(&mut self, data: &[u8], resources_dir: Option<&Path>) { let fonts_db = kas::text::fonts::fonts().read_db(); let fontdb = fonts_db.db(); - let font_family = fonts_db - .font_family_from_alias("SERIF") - .unwrap_or_default(); + let font_family = fonts_db.font_family_from_alias("SERIF").unwrap_or_default(); // Defaults are taken from usvg::Options::default(). Notes: // - adjusting for screen scale factor is purely a property of @@ -76,7 +74,9 @@ impl_scope! { }; self.tree = Some(usvg::Tree::from_data(data, &opts).unwrap()); - self.scaling.size = self.tree.as_ref() + self.scaling.size = self + .tree + .as_ref() .map(|tree| LogicalSize::conv(tree.svg_node().size.to_screen_size().dimensions())) .unwrap_or(LogicalSize(128.0, 128.0)); } @@ -147,7 +147,8 @@ impl_scope! { resvg::render(tree, usvg::FitTo::Size(w, h), transform, pm.as_mut()); let handle = mgr.draw_shared().image_alloc((w, h)).unwrap(); - mgr.draw_shared().image_upload(&handle, pm.data(), ImageFormat::Rgba8); + mgr.draw_shared() + .image_upload(&handle, pm.data(), ImageFormat::Rgba8); handle }); } diff --git a/crates/kas-view/src/driver/config.rs b/crates/kas-view/src/driver/config.rs index d0a2bd045..882c1666c 100644 --- a/crates/kas-view/src/driver/config.rs +++ b/crates/kas-view/src/driver/config.rs @@ -49,17 +49,28 @@ impl_scope! { #[derive(Debug)] pub struct EventConfigWidget { core: widget_core!(), - #[widget] menu_delay: Spinner, - #[widget] touch_select_delay: Spinner, - #[widget] scroll_flick_timeout: Spinner, - #[widget] scroll_flick_mul: Spinner, - #[widget] scroll_flick_sub: Spinner, - #[widget] scroll_dist_em: Spinner, - #[widget] pan_dist_thresh: Spinner, - #[widget] mouse_pan: ComboBox, - #[widget] mouse_text_pan: ComboBox, - #[widget] mouse_nav_focus: CheckButton, - #[widget] touch_nav_focus: CheckButton, + #[widget] + menu_delay: Spinner, + #[widget] + touch_select_delay: Spinner, + #[widget] + scroll_flick_timeout: Spinner, + #[widget] + scroll_flick_mul: Spinner, + #[widget] + scroll_flick_sub: Spinner, + #[widget] + scroll_dist_em: Spinner, + #[widget] + pan_dist_thresh: Spinner, + #[widget] + mouse_pan: ComboBox, + #[widget] + mouse_text_pan: ComboBox, + #[widget] + mouse_nav_focus: CheckButton, + #[widget] + touch_nav_focus: CheckButton, } } diff --git a/crates/kas-view/src/list_view.rs b/crates/kas-view/src/list_view.rs index 4d54aee20..f374a98e5 100644 --- a/crates/kas-view/src/list_view.rs +++ b/crates/kas-view/src/list_view.rs @@ -50,11 +50,7 @@ impl_scope! { /// widget emits a [`SelectionMsg`]. #[derive(Clone, Debug)] #[widget] - pub struct ListView< - D: Directional, - T: ListData, - V: Driver = driver::View, - > { + pub struct ListView = driver::View> { core: widget_core!(), frame_offset: Offset, frame_size: Size, @@ -82,7 +78,11 @@ impl_scope! { press_target: Option, } - impl Self where D: Default, V: Default { + impl Self + where + D: Default, + V: Default, + { /// Construct a new instance /// /// This constructor is available where the direction is determined by the @@ -92,13 +92,19 @@ impl_scope! { Self::new_with_dir_driver(D::default(), ::default(), data) } } - impl Self where V: Default { + impl Self + where + V: Default, + { /// Construct a new instance with explicit direction pub fn new_with_direction(direction: D, data: T) -> Self { Self::new_with_dir_driver(direction, ::default(), data) } } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a new instance with explicit driver pub fn new_with_driver(driver: V, data: T) -> Self { Self::new_with_dir_driver(D::default(), driver, data) @@ -167,7 +173,10 @@ impl_scope! { /// This method updates the shared data, if supported (see /// [`SharedDataMut::borrow_mut`]). Other widgets sharing this data /// are notified of the update, if data is changed. - pub fn set_value(&self, mgr: &mut EventMgr, key: &T::Key, data: T::Item) where T: SharedDataMut { + pub fn set_value(&self, mgr: &mut EventMgr, key: &T::Key, data: T::Item) + where + T: SharedDataMut, + { self.data.set(mgr, key, data); } @@ -176,7 +185,15 @@ impl_scope! { /// This method updates the shared data, if supported (see /// [`SharedDataMut::with_ref_mut`]). Other widgets sharing this data /// are notified of the update, if data is changed. - pub fn update_value(&self, mgr: &mut EventMgr, key: &T::Key, f: impl FnOnce(&mut T::Item) -> U) -> Option where T: SharedDataMut { + pub fn update_value( + &self, + mgr: &mut EventMgr, + key: &T::Key, + f: impl FnOnce(&mut T::Item) -> U, + ) -> Option + where + T: SharedDataMut, + { self.data.with_ref_mut(mgr, key, f) } @@ -348,9 +365,7 @@ impl_scope! { let solver = self.position_solver(mgr); let mut action = TkAction::empty(); - let keys = self - .data - .iter_from(solver.first_data, solver.cur_len); + let keys = self.data.iter_from(solver.first_data, solver.cur_len); let mut count = 0; for (i, key) in keys.enumerate() { @@ -465,7 +480,9 @@ impl_scope! { let other_axis = axis.flipped(); size -= self.frame_size.extract(other_axis); if self.direction.is_horizontal() == other_axis.is_horizontal() { - size = (size / self.ideal_visible).min(self.child_size_ideal).max(self.child_size_min); + size = (size / self.ideal_visible) + .min(self.child_size_ideal) + .max(self.child_size_min); } size }); @@ -485,7 +502,8 @@ impl_scope! { if axis.is_vertical() == self.direction.is_vertical() { self.child_size_ideal = rules.ideal_size(); let m = rules.margins(); - self.child_inter_margin = m.0.max(m.1).max(inner_margin.0).max(inner_margin.1).cast(); + self.child_inter_margin = + m.0.max(m.1).max(inner_margin.0).max(inner_margin.1).cast(); rules.multiply_with_margin(2, self.ideal_visible); rules.set_stretch(rules.stretch().max(Stretch::High)); } else { @@ -524,7 +542,11 @@ impl_scope! { if data_len <= avail_widgets { req_widgets = data_len } else if avail_widgets < req_widgets { - log::debug!("set_rect: allocating widgets (old len = {}, new = {})", avail_widgets, req_widgets); + log::debug!( + "set_rect: allocating widgets (old len = {}, new = {})", + avail_widgets, + req_widgets + ); self.widgets.reserve(req_widgets - avail_widgets); for _ in avail_widgets..req_widgets { let widget = self.driver.make(); @@ -737,7 +759,8 @@ impl_scope! { }; return if let Some(i_data) = data { // Set nav focus to i_data and update scroll position - let (rect, action) = self.scroll.focus_rect(solver.rect(i_data), self.core.rect); + let (rect, action) = + self.scroll.focus_rect(solver.rect(i_data), self.core.rect); if !action.is_empty() { *mgr |= action; mgr.config_mgr(|mgr| self.update_widgets(mgr)); @@ -753,7 +776,9 @@ impl_scope! { _ => (), // fall through to scroll handler } - let (moved, r) = self.scroll.scroll_by_event(mgr, event, self.id(), self.core.rect); + let (moved, r) = self + .scroll + .scroll_by_event(mgr, event, self.id(), self.core.rect); if moved { mgr.config_mgr(|mgr| self.update_widgets(mgr)); } diff --git a/crates/kas-view/src/matrix_view.rs b/crates/kas-view/src/matrix_view.rs index 616bd8cda..ae00caee5 100644 --- a/crates/kas-view/src/matrix_view.rs +++ b/crates/kas-view/src/matrix_view.rs @@ -56,10 +56,7 @@ impl_scope! { /// widget emits a [`SelectionMsg`]. #[derive(Clone, Debug)] #[widget] - pub struct MatrixView< - T: MatrixData, - V: Driver = driver::View, - > { + pub struct MatrixView = driver::View> { core: widget_core!(), frame_offset: Offset, frame_size: Size, @@ -87,7 +84,10 @@ impl_scope! { press_target: Option, } - impl Self where V: Default { + impl Self + where + V: Default, + { /// Construct a new instance pub fn new(data: T) -> Self { Self::new_with_driver(::default(), data) @@ -149,7 +149,10 @@ impl_scope! { /// This method updates the shared data, if supported (see /// [`SharedDataMut::borrow_mut`]). Other widgets sharing this data /// are notified of the update, if data is changed. - pub fn set_value(&self, mgr: &mut EventMgr, key: &T::Key, data: T::Item) where T: SharedDataMut { + pub fn set_value(&self, mgr: &mut EventMgr, key: &T::Key, data: T::Item) + where + T: SharedDataMut, + { self.data.set(mgr, key, data); } @@ -158,7 +161,15 @@ impl_scope! { /// This method updates the shared data, if supported (see /// [`SharedDataMut::with_ref_mut`]). Other widgets sharing this data /// are notified of the update, if data is changed. - pub fn update_value(&self, mgr: &mut EventMgr, key: &T::Key, f: impl FnOnce(&mut T::Item) -> U) -> Option where T: SharedDataMut { + pub fn update_value( + &self, + mgr: &mut EventMgr, + key: &T::Key, + f: impl FnOnce(&mut T::Item) -> U, + ) -> Option + where + T: SharedDataMut, + { self.data.with_ref_mut(mgr, key, f) } @@ -325,9 +336,7 @@ impl_scope! { ); } - let row_iter = self - .data - .row_iter_from(solver.first_row, solver.row_len); + let row_iter = self.data.row_iter_from(solver.first_row, solver.row_len); let mut action = TkAction::empty(); let mut row_count = 0; @@ -381,7 +390,8 @@ impl_scope! { let avail = size - self.frame_size; let m = self.child_inter_margin; let child_size = Size(avail.0 / self.ideal_len.cols, avail.1 / self.ideal_len.rows) - .min(self.child_size_ideal).max(self.child_size_min); + .min(self.child_size_ideal) + .max(self.child_size_min); let (d_cols, d_rows) = self.data.len(); let data_len = Size(d_cols.cast(), d_rows.cast()); let content_size = ((child_size + m).cwise_mul(data_len) - m).max(Size::ZERO); @@ -461,10 +471,13 @@ impl_scope! { } } - self.child_size_ideal.set_component(axis, rules.ideal_size()); + self.child_size_ideal + .set_component(axis, rules.ideal_size()); let m = rules.margins(); - self.child_inter_margin - .set_component(axis, m.0.max(m.1).max(inner_margin.0).max(inner_margin.1).cast()); + self.child_inter_margin.set_component( + axis, + m.0.max(m.1).max(inner_margin.0).max(inner_margin.1).cast(), + ); let ideal_len = match axis.is_vertical() { false => self.ideal_len.cols, @@ -485,7 +498,8 @@ impl_scope! { let avail = rect.size - self.frame_size; let child_size = Size(avail.0 / self.ideal_len.cols, avail.1 / self.ideal_len.rows) - .min(self.child_size_ideal).max(self.child_size_min); + .min(self.child_size_ideal) + .max(self.child_size_min); self.child_size = child_size; let (d_cols, d_rows) = self.data.len(); @@ -498,9 +512,8 @@ impl_scope! { } else { // Case: reallocate children when scrolling let skip = child_size + self.child_inter_margin; - vis_len = data_len.min( - (rect.size + skip - Size::splat(1)).cwise_div(skip) + Size::splat(1) - ); + vis_len = data_len + .min((rect.size + skip - Size::splat(1)).cwise_div(skip) + Size::splat(1)); req_widgets = usize::conv(vis_len.0) * usize::conv(vis_len.1); } self.alloc_len = Dim { @@ -509,7 +522,11 @@ impl_scope! { }; if avail_widgets < req_widgets { - log::debug!("set_rect: allocating widgets (old len = {}, new = {})", avail_widgets, req_widgets); + log::debug!( + "set_rect: allocating widgets (old len = {}, new = {})", + avail_widgets, + req_widgets + ); self.widgets.reserve(req_widgets - avail_widgets); for _ in avail_widgets..req_widgets { let widget = self.driver.make(); @@ -567,7 +584,10 @@ impl_scope! { // widgets (this allows resource loading which may affect size.) self.data_ver = self.data.version(); if self.widgets.is_empty() && !self.data.is_empty() { - let cols: Vec<_> = self.data.col_iter_limit(self.ideal_len.cols.cast()).collect(); + let cols: Vec<_> = self + .data + .col_iter_limit(self.ideal_len.cols.cast()) + .collect(); let rows = self.data.row_iter_limit(self.ideal_len.rows.cast()); let lbound = cols.len() * rows.size_hint().0; log::debug!("configure: allocating {} widgets", lbound); @@ -607,7 +627,7 @@ impl_scope! { let (ci, ri) = if let Some(index) = from { let (ci, ri) = solver.child_to_data(index); if !reverse { - if ci + 1 < d_cols{ + if ci + 1 < d_cols { (ci + 1, ri) } else if ri + 1 < d_rows { (0, ri + 1) @@ -737,9 +757,7 @@ impl_scope! { C::Up if ri > 0 => Some((ci, ri - 1)), C::Right | C::WordRight if ci < last_col => Some((ci + 1, ri)), C::Down if ri < last_row => Some((ci, ri + 1)), - C::PageUp if ri > 0 => { - Some((ci, ri.saturating_sub(solver.row_len / 2))) - } + C::PageUp if ri > 0 => Some((ci, ri.saturating_sub(solver.row_len / 2))), C::PageDown if ri < last_row => { Some((ci, (ri + solver.row_len / 2).min(last_row))) } @@ -748,19 +766,23 @@ impl_scope! { }; return if let Some((ci, ri)) = data { // Set nav focus and update scroll position - let (rect, action) = self.scroll.focus_rect(solver.rect(ci, ri), self.core.rect); + let (rect, action) = + self.scroll.focus_rect(solver.rect(ci, ri), self.core.rect); if !action.is_empty() { *mgr |= action; solver = mgr.config_mgr(|mgr| self.update_widgets(mgr)); } let index = solver.data_to_child(ci, ri); - #[cfg(debug_assertions)] { - let rk = self.data + #[cfg(debug_assertions)] + { + let rk = self + .data .row_iter_from(ri, 1) .next() .expect("data row len > data.row_iter_vec len"); - let ck = self.data + let ck = self + .data .col_iter_from(ci, 1) .next() .expect("data col len > data.col_iter_vec len"); @@ -781,7 +803,9 @@ impl_scope! { _ => (), // fall through to scroll handler } - let (moved, r) = self.scroll.scroll_by_event(mgr, event, self.id(), self.core.rect); + let (moved, r) = self + .scroll + .scroll_by_event(mgr, event, self.id(), self.core.rect); if moved { mgr.config_mgr(|mgr| self.update_widgets(mgr)); } diff --git a/crates/kas-view/src/single_view.rs b/crates/kas-view/src/single_view.rs index b197e6130..886c5e17f 100644 --- a/crates/kas-view/src/single_view.rs +++ b/crates/kas-view/src/single_view.rs @@ -32,10 +32,7 @@ impl_scope! { #[widget{ layout = self.child; }] - pub struct SingleView< - T: SingleData, - V: Driver = driver::View, - > { + pub struct SingleView = driver::View> { core: widget_core!(), driver: V, data: T, @@ -53,7 +50,10 @@ impl_scope! { Self::new(T::default()) } } - impl Self where V: Default { + impl Self + where + V: Default, + { /// Construct a new instance pub fn new(data: T) -> Self { Self::new_with_driver(::default(), data) @@ -98,7 +98,10 @@ impl_scope! { /// This method updates the shared data, if supported (see /// [`SharedDataMut::borrow_mut`]). Other widgets sharing this data /// are notified of the update, if data is changed. - pub fn set_value(&self, mgr: &mut EventMgr, data: T::Item) where T: SharedDataMut { + pub fn set_value(&self, mgr: &mut EventMgr, data: T::Item) + where + T: SharedDataMut, + { self.data.set(mgr, &(), data); } @@ -107,7 +110,14 @@ impl_scope! { /// This method updates the shared data, if supported (see /// [`SharedDataMut::with_ref_mut`]). Other widgets sharing this data /// are notified of the update, if data is changed. - pub fn update_value(&self, mgr: &mut EventMgr, f: impl FnOnce(&mut T::Item) -> U) -> Option where T: SharedDataMut { + pub fn update_value( + &self, + mgr: &mut EventMgr, + f: impl FnOnce(&mut T::Item) -> U, + ) -> Option + where + T: SharedDataMut, + { self.data.with_ref_mut(mgr, &(), f) } } @@ -143,7 +153,8 @@ impl_scope! { } fn handle_message(&mut self, mgr: &mut EventMgr, _: usize) { - self.driver.on_message(mgr, &mut self.child, &self.data, &()); + self.driver + .on_message(mgr, &mut self.child, &self.data, &()); } } } diff --git a/crates/kas-widgets/src/adapter/map.rs b/crates/kas-widgets/src/adapter/map.rs index bd399b9ac..95f7bcac9 100644 --- a/crates/kas-widgets/src/adapter/map.rs +++ b/crates/kas-widgets/src/adapter/map.rs @@ -19,7 +19,12 @@ impl_scope! { #[widget{ layout = self.inner; }] - pub struct MapMessage N + 'static> { + pub struct MapMessage< + W: Widget, + M: Debug + 'static, + N: Debug + 'static, + F: FnMut(M) -> N + 'static, + > { core: widget_core!(), #[widget] inner: W, @@ -52,14 +57,22 @@ impl_scope! { } } - impl Menu for Self where W: Menu { + impl Menu for Self + where + W: Menu, + { fn sub_items(&mut self) -> Option { self.inner.sub_items() } fn menu_is_open(&self) -> bool { self.inner.menu_is_open() } - fn set_menu_path(&mut self, mgr: &mut EventMgr, target: Option<&WidgetId>, set_focus: bool) { + fn set_menu_path( + &mut self, + mgr: &mut EventMgr, + target: Option<&WidgetId>, + set_focus: bool, + ) { self.inner.set_menu_path(mgr, target, set_focus); } } diff --git a/crates/kas-widgets/src/adapter/reserve.rs b/crates/kas-widgets/src/adapter/reserve.rs index 42ec0e0b5..f0974d559 100644 --- a/crates/kas-widgets/src/adapter/reserve.rs +++ b/crates/kas-widgets/src/adapter/reserve.rs @@ -85,10 +85,7 @@ impl_scope! { /// and the result of the `reserve` closure. #[inline] pub fn new(inner: W, reserve: R) -> Self { - Reserve { - inner, - reserve, - } + Reserve { inner, reserve } } } diff --git a/crates/kas-widgets/src/adapter/with_label.rs b/crates/kas-widgets/src/adapter/with_label.rs index 8c8c1a2a7..0b9e67bfc 100644 --- a/crates/kas-widgets/src/adapter/with_label.rs +++ b/crates/kas-widgets/src/adapter/with_label.rs @@ -29,7 +29,10 @@ impl_scope! { label: AccelLabel, } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct from `inner` widget and `label` #[inline] pub fn new>(inner: W, label: T) -> Self { diff --git a/crates/kas-widgets/src/edit.rs b/crates/kas-widgets/src/edit.rs index 957a5be0c..fb33cdfc9 100644 --- a/crates/kas-widgets/src/edit.rs +++ b/crates/kas-widgets/src/edit.rs @@ -198,8 +198,10 @@ impl_scope! { #[widget] pub struct EditBox { core: widget_core!(), - #[widget] inner: EditField, - #[widget] bar: ScrollBar, + #[widget] + inner: EditField, + #[widget] + bar: ScrollBar, frame_offset: Offset, frame_size: Size, inner_margin: i32, @@ -271,7 +273,8 @@ impl_scope! { impl Widget for Self { fn handle_message(&mut self, mgr: &mut EventMgr<'_>, _: usize) { if let Some(ScrollMsg(y)) = mgr.try_pop_msg() { - self.inner.set_scroll_offset(mgr, Offset(self.inner.view_offset.0, y)); + self.inner + .set_scroll_offset(mgr, Offset(self.inner.view_offset.0, y)); } } diff --git a/crates/kas-widgets/src/filler.rs b/crates/kas-widgets/src/filler.rs index 1222fbea6..cad189171 100644 --- a/crates/kas-widgets/src/filler.rs +++ b/crates/kas-widgets/src/filler.rs @@ -22,11 +22,7 @@ impl_scope! { impl Layout for Filler { fn size_rules(&mut self, _: SizeMgr, axis: AxisInfo) -> SizeRules { - let stretch = if axis.is_horizontal() { - self.horiz - } else { - self.vert - }; + let stretch = if axis.is_horizontal() { self.horiz } else { self.vert }; SizeRules::empty(stretch) } diff --git a/crates/kas-widgets/src/grid.rs b/crates/kas-widgets/src/grid.rs index 7630f8362..506544083 100644 --- a/crates/kas-widgets/src/grid.rs +++ b/crates/kas-widgets/src/grid.rs @@ -81,7 +81,9 @@ impl_scope! { fn size_rules(&mut self, mgr: SizeMgr, axis: AxisInfo) -> SizeRules { let mut solver = GridSolver::, Vec<_>, _>::new(axis, self.dim, &mut self.data); for (info, child) in &mut self.widgets { - solver.for_child(&mut self.data, *info, |axis| child.size_rules(mgr.re(), axis)); + solver.for_child(&mut self.data, *info, |axis| { + child.size_rules(mgr.re(), axis) + }); } solver.finish(&mut self.data) } @@ -98,7 +100,10 @@ impl_scope! { if !self.rect().contains(coord) { return None; } - self.widgets.iter_mut().find_map(|(_, child)| child.find_id(coord)).or_else(|| Some(self.id())) + self.widgets + .iter_mut() + .find_map(|(_, child)| child.find_id(coord)) + .or_else(|| Some(self.id())) } fn draw(&mut self, mut draw: DrawMgr) { diff --git a/crates/kas-widgets/src/image.rs b/crates/kas-widgets/src/image.rs index f5645c900..5bef692cc 100644 --- a/crates/kas-widgets/src/image.rs +++ b/crates/kas-widgets/src/image.rs @@ -91,7 +91,7 @@ impl_scope! { pub fn load_path>( &mut self, path: P, - draw: &mut dyn DrawShared + draw: &mut dyn DrawShared, ) -> Result { let image = image::io::Reader::open(path)? .with_guessed_format()? diff --git a/crates/kas-widgets/src/list.rs b/crates/kas-widgets/src/list.rs index 7aab7d674..acb410c7c 100644 --- a/crates/kas-widgets/src/list.rs +++ b/crates/kas-widgets/src/list.rs @@ -94,7 +94,8 @@ impl_scope! { } fn find_child_index(&self, id: &WidgetId) -> Option { - id.next_key_after(self.id_ref()).and_then(|k| self.id_map.get(&k).cloned()) + id.next_key_after(self.id_ref()) + .and_then(|k| self.id_map.get(&k).cloned()) } fn make_child_id(&mut self, index: usize) -> WidgetId { @@ -132,7 +133,10 @@ impl_scope! { } } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a new instance /// /// This constructor is available where the direction is determined by the diff --git a/crates/kas-widgets/src/menu/menu_entry.rs b/crates/kas-widgets/src/menu/menu_entry.rs index 7fb615519..8f6694774 100644 --- a/crates/kas-widgets/src/menu/menu_entry.rs +++ b/crates/kas-widgets/src/menu/menu_entry.rs @@ -164,7 +164,7 @@ impl_scope! { where F: Fn(&mut EventMgr, bool) + 'static, { - MenuToggle { + MenuToggle { core: self.core, checkbox: self.checkbox.on_toggle(f), label: self.label, diff --git a/crates/kas-widgets/src/menu/menubar.rs b/crates/kas-widgets/src/menu/menubar.rs index 38fd85a8e..b4abe3efb 100644 --- a/crates/kas-widgets/src/menu/menubar.rs +++ b/crates/kas-widgets/src/menu/menubar.rs @@ -26,7 +26,10 @@ impl_scope! { delayed_open: Option, } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a menubar /// /// Note: it appears that `MenuBar::new(..)` causes a type inference error, @@ -133,7 +136,11 @@ impl_scope! { start_id, coord, } => { - if start_id.as_ref().map(|id| self.is_ancestor_of(id)).unwrap_or(false) { + if start_id + .as_ref() + .map(|id| self.is_ancestor_of(id)) + .unwrap_or(false) + { if source.is_primary() { let any_menu_open = self.widgets.iter().any(|w| w.menu_is_open()); let press_in_the_bar = self.rect().contains(coord); @@ -193,7 +200,12 @@ impl_scope! { } Response::Used } - Event::PressEnd { coord, end_id, success, .. } if success => { + Event::PressEnd { + coord, + end_id, + success, + .. + } if success => { let id = match end_id { Some(x) => x, None => return Response::Used, @@ -241,8 +253,16 @@ impl_scope! { } impl Self { - fn set_menu_path(&mut self, mgr: &mut EventMgr, target: Option<&WidgetId>, set_focus: bool) { - log::trace!("set_menu_path: self={}, target={target:?}, set_focus={set_focus}", self.identify()); + fn set_menu_path( + &mut self, + mgr: &mut EventMgr, + target: Option<&WidgetId>, + set_focus: bool, + ) { + log::trace!( + "set_menu_path: self={}, target={target:?}, set_focus={set_focus}", + self.identify() + ); self.delayed_open = None; for i in 0..self.widgets.len() { self.widgets[i].set_menu_path(mgr, target, set_focus); diff --git a/crates/kas-widgets/src/menu/submenu.rs b/crates/kas-widgets/src/menu/submenu.rs index 45dffd353..c29d4946d 100644 --- a/crates/kas-widgets/src/menu/submenu.rs +++ b/crates/kas-widgets/src/menu/submenu.rs @@ -32,7 +32,10 @@ impl_scope! { popup_id: Option, } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a sub-menu #[inline] pub fn new>(label: S, list: Vec) -> Self { @@ -65,7 +68,9 @@ impl_scope! { /// The sub-menu is opened in the `direction` given (contents are always vertical). #[inline] pub fn new_with_direction>( - direction: D, label: S, list: Vec + direction: D, + label: S, + list: Vec, ) -> Self { SubMenu { core: Default::default(), @@ -196,7 +201,12 @@ impl_scope! { self.popup_id.is_some() } - fn set_menu_path(&mut self, mgr: &mut EventMgr, target: Option<&WidgetId>, set_focus: bool) { + fn set_menu_path( + &mut self, + mgr: &mut EventMgr, + target: Option<&WidgetId>, + set_focus: bool, + ) { match target { Some(id) if self.is_ancestor_of(id) => { if self.popup_id.is_none() { @@ -373,7 +383,7 @@ impl_scope! { let info = layout::GridChildInfo::new(1, row); w.set_rect(mgr, subtract_frame(setter.child_rect(store, info))); } - if let Some(w) = items.label { + if let Some(w) = items.label { let info = layout::GridChildInfo::new(2, row); w.set_rect(mgr, subtract_frame(setter.child_rect(store, info))); } diff --git a/crates/kas-widgets/src/progress.rs b/crates/kas-widgets/src/progress.rs index 100fe1404..99e8e61b4 100644 --- a/crates/kas-widgets/src/progress.rs +++ b/crates/kas-widgets/src/progress.rs @@ -23,7 +23,10 @@ impl_scope! { value: f32, } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a progress bar /// /// The initial value is `0.0`; use `ProgressBar::with_value` to override. @@ -84,10 +87,13 @@ impl_scope! { impl Layout for Self { fn size_rules(&mut self, size_mgr: SizeMgr, axis: AxisInfo) -> SizeRules { - self.align.set_component(axis, match axis.is_vertical() == self.direction.is_vertical() { - false => axis.align_or_center(), - true => axis.align_or_stretch(), - }); + self.align.set_component( + axis, + match axis.is_vertical() == self.direction.is_vertical() { + false => axis.align_or_center(), + true => axis.align_or_stretch(), + }, + ); size_mgr.feature(Feature::ProgressBar(self.direction()), axis) } diff --git a/crates/kas-widgets/src/radio_box.rs b/crates/kas-widgets/src/radio_box.rs index 856f4fb69..4dd162e64 100644 --- a/crates/kas-widgets/src/radio_box.rs +++ b/crates/kas-widgets/src/radio_box.rs @@ -86,7 +86,7 @@ impl_scope! { } } Response::Used - }) + }), } } } diff --git a/crates/kas-widgets/src/scroll.rs b/crates/kas-widgets/src/scroll.rs index d455ed7ba..353d91745 100644 --- a/crates/kas-widgets/src/scroll.rs +++ b/crates/kas-widgets/src/scroll.rs @@ -140,7 +140,9 @@ impl_scope! { } fn handle_event(&mut self, mgr: &mut EventMgr, event: Event) -> Response { - self.scroll.scroll_by_event(mgr, event, self.id(), self.core.rect).1 + self.scroll + .scroll_by_event(mgr, event, self.id(), self.core.rect) + .1 } fn handle_scroll(&mut self, mgr: &mut EventMgr, scroll: Scroll) { diff --git a/crates/kas-widgets/src/scroll_bar.rs b/crates/kas-widgets/src/scroll_bar.rs index f36134ecc..d9f260e32 100644 --- a/crates/kas-widgets/src/scroll_bar.rs +++ b/crates/kas-widgets/src/scroll_bar.rs @@ -47,7 +47,10 @@ impl_scope! { handle: GripPart, } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a scroll bar /// /// Default values are assumed for all parameters. @@ -253,10 +256,13 @@ impl_scope! { impl Layout for Self { fn size_rules(&mut self, size_mgr: SizeMgr, axis: AxisInfo) -> SizeRules { - self.align.set_component(axis, match axis.is_vertical() == self.direction.is_vertical() { - false => axis.align_or_center(), - true => axis.align_or_stretch(), - }); + self.align.set_component( + axis, + match axis.is_vertical() == self.direction.is_vertical() { + false => axis.align_or_center(), + true => axis.align_or_stretch(), + }, + ); size_mgr.feature(Feature::ScrollBar(self.direction()), axis) } @@ -279,9 +285,9 @@ impl_scope! { } fn draw(&mut self, mut draw: DrawMgr) { - if !self.invisible || - (self.max_value != 0 && (self.hover || self.force_visible)) || - draw.ev_state().is_depressed(self.handle.id_ref()) + if !self.invisible + || (self.max_value != 0 && (self.hover || self.force_visible)) + || draw.ev_state().is_depressed(self.handle.id_ref()) { let dir = self.direction.as_direction(); draw.scroll_bar(self.rect(), &self.handle, dir); @@ -302,7 +308,7 @@ impl_scope! { self.apply_grip_offset(mgr, offset); Response::Used } - _ => Response::Unused + _ => Response::Unused, } } @@ -476,15 +482,13 @@ impl_scope! { if self.show_bars.0 { let pos = Coord(pos.0, rect.pos2().1 - bar_width); let size = Size::new(child_size.0, bar_width); - self.horiz_bar - .set_rect(mgr, Rect { pos, size }); + self.horiz_bar.set_rect(mgr, Rect { pos, size }); let _ = self.horiz_bar.set_limits(max_scroll_offset.0, rect.size.0); } if self.show_bars.1 { let pos = Coord(rect.pos2().0 - bar_width, pos.1); let size = Size::new(bar_width, self.core.rect.size.1); - self.vert_bar - .set_rect(mgr, Rect { pos, size }); + self.vert_bar.set_rect(mgr, Rect { pos, size }); let _ = self.vert_bar.set_limits(max_scroll_offset.1, rect.size.1); } } @@ -493,7 +497,8 @@ impl_scope! { if !self.rect().contains(coord) { return None; } - self.vert_bar.find_id(coord) + self.vert_bar + .find_id(coord) .or_else(|| self.horiz_bar.find_id(coord)) .or_else(|| self.inner.find_id(coord)) .or_else(|| Some(self.id())) diff --git a/crates/kas-widgets/src/scroll_label.rs b/crates/kas-widgets/src/scroll_label.rs index 135e28a2a..07794cd28 100644 --- a/crates/kas-widgets/src/scroll_label.rs +++ b/crates/kas-widgets/src/scroll_label.rs @@ -30,7 +30,8 @@ impl_scope! { text_size: Size, selection: SelectionHelper, input_handler: TextInput, - #[widget] bar: ScrollBar, + #[widget] + bar: ScrollBar, } impl Layout for Self { @@ -77,12 +78,7 @@ impl_scope! { // TODO(opt): we could cache the selection rectangles here to make // drawing more efficient (self.text.highlight_lines(range) output). // The same applies to the edit marker below. - draw.text_selected( - rect, - &self.text, - self.selection.range(), - class, - ); + draw.text_selected(rect, &self.text, self.selection.range(), class); } }); draw.with_pass(|mut draw| { @@ -111,7 +107,9 @@ impl_scope! { /// Note: this must not be called before fonts have been initialised /// (usually done by the theme when the main loop starts). pub fn set_text(&mut self, text: T) -> TkAction { - self.text.set_and_try_prepare(text).expect("invalid font_id"); + self.text + .set_and_try_prepare(text) + .expect("invalid font_id"); self.text_size = Vec2::from(self.text.bounding_box().unwrap().1).cast_ceil(); let max_offset = self.max_scroll_offset(); @@ -137,18 +135,19 @@ impl_scope! { // Pan by given delta. Return `Response::Scrolled` or `Response::Pan(remaining)`. fn pan_delta(&mut self, mgr: &mut EventMgr, mut delta: Offset) -> Response { - let new_offset = (self.view_offset - delta).min(self.max_scroll_offset()).max(Offset::ZERO); + let new_offset = (self.view_offset - delta) + .min(self.max_scroll_offset()) + .max(Offset::ZERO); if new_offset != self.view_offset { delta -= self.view_offset - new_offset; self.set_offset(mgr, new_offset); } mgr.set_scroll(if delta == Offset::ZERO { - Scroll::Scrolled - } else { - Scroll::Offset(delta) - } - ); + Scroll::Scrolled + } else { + Scroll::Offset(delta) + }); Response::Used } diff --git a/crates/kas-widgets/src/slider.rs b/crates/kas-widgets/src/slider.rs index af5c052c7..988ab9620 100644 --- a/crates/kas-widgets/src/slider.rs +++ b/crates/kas-widgets/src/slider.rs @@ -109,7 +109,10 @@ impl_scope! { on_move: Option>, } - impl Self where D: Default { + impl Self + where + D: Default, + { /// Construct a slider /// /// Values vary within the given `range`. When keyboard navigation @@ -258,10 +261,13 @@ impl_scope! { impl Layout for Self { fn size_rules(&mut self, size_mgr: SizeMgr, axis: AxisInfo) -> SizeRules { - self.align.set_component(axis, match axis.is_vertical() == self.direction.is_vertical() { - false => axis.align_or_center(), - true => axis.align_or_stretch(), - }); + self.align.set_component( + axis, + match axis.is_vertical() == self.direction.is_vertical() { + false => axis.align_or_center(), + true => axis.align_or_stretch(), + }, + ); size_mgr.feature(Feature::Slider(self.direction()), axis) } diff --git a/crates/kas-widgets/src/spinner.rs b/crates/kas-widgets/src/spinner.rs index 85bb93edc..45a58e0f8 100644 --- a/crates/kas-widgets/src/spinner.rs +++ b/crates/kas-widgets/src/spinner.rs @@ -318,13 +318,11 @@ impl_scope! { fn steal_event(&mut self, mgr: &mut EventMgr, _: &WidgetId, event: &Event) -> Response { let btn = match event { - Event::Command(cmd) => { - match cmd { - Command::Down => SpinBtn::Down, - Command::Up => SpinBtn::Up, - _ => return Response::Unused, - } - } + Event::Command(cmd) => match cmd { + Command::Down => SpinBtn::Down, + Command::Up => SpinBtn::Up, + _ => return Response::Unused, + }, Event::Scroll(ScrollDelta::LineDelta(_, y)) => { if *y > 0.0 { SpinBtn::Up diff --git a/crates/kas-widgets/src/splitter.rs b/crates/kas-widgets/src/splitter.rs index 942f1acd9..4bf49cc96 100644 --- a/crates/kas-widgets/src/splitter.rs +++ b/crates/kas-widgets/src/splitter.rs @@ -130,7 +130,8 @@ impl_scope! { } fn find_child_index(&self, id: &WidgetId) -> Option { - id.next_key_after(self.id_ref()).and_then(|k| self.id_map.get(&k).cloned()) + id.next_key_after(self.id_ref()) + .and_then(|k| self.id_map.get(&k).cloned()) } fn make_child_id(&mut self, child_index: usize) -> WidgetId { diff --git a/crates/kas-widgets/src/stack.rs b/crates/kas-widgets/src/stack.rs index 792422636..985687da6 100644 --- a/crates/kas-widgets/src/stack.rs +++ b/crates/kas-widgets/src/stack.rs @@ -61,7 +61,8 @@ impl_scope! { } fn find_child_index(&self, id: &WidgetId) -> Option { - id.next_key_after(self.id_ref()).and_then(|k| self.id_map.get(&k).cloned()) + id.next_key_after(self.id_ref()) + .and_then(|k| self.id_map.get(&k).cloned()) } fn make_child_id(&mut self, index: usize) -> WidgetId { @@ -89,7 +90,10 @@ impl_scope! { impl Layout for Self { fn size_rules(&mut self, size_mgr: SizeMgr, axis: AxisInfo) -> SizeRules { let mut rules = SizeRules::EMPTY; - let end = self.active.saturating_add(self.size_limit).min(self.widgets.len()); + let end = self + .active + .saturating_add(self.size_limit) + .min(self.widgets.len()); let start = end.saturating_sub(self.size_limit); self.sized_range = start..end; debug_assert!(self.sized_range.contains(&self.active)); @@ -127,11 +131,7 @@ impl_scope! { self.id_map.clear(); } - fn nav_next(&mut self, - _: &mut ConfigMgr, - _: bool, - from: Option, - ) -> Option { + fn nav_next(&mut self, _: &mut ConfigMgr, _: bool, from: Option) -> Option { match from { None => Some(self.active), Some(active) if active != self.active => Some(self.active), diff --git a/examples/async-event.rs b/examples/async-event.rs index 8cb41be03..35b4b5b8b 100644 --- a/examples/async-event.rs +++ b/examples/async-event.rs @@ -69,7 +69,12 @@ impl_scope! { fn set_rect(&mut self, mgr: &mut ConfigMgr, rect: Rect) { self.core.rect = rect; let align = Some(AlignPair::new(Align::Center, Align::Center)); - mgr.text_set_size(&mut self.loading_text, TextClass::Label(false), rect.size, align); + mgr.text_set_size( + &mut self.loading_text, + TextClass::Label(false), + rect.size, + align, + ); } fn draw(&mut self, mut draw: DrawMgr) { @@ -95,7 +100,9 @@ impl_scope! { } } impl Window for Self { - fn title(&self) -> &str { "Async event demo" } + fn title(&self) -> &str { + "Async event demo" + } } } diff --git a/examples/clock.rs b/examples/clock.rs index 64d27ceea..95b5cd812 100644 --- a/examples/clock.rs +++ b/examples/clock.rs @@ -126,8 +126,12 @@ impl_scope! { self.now = Local::now(); let date = self.now.format("%Y-%m-%d").to_string(); let time = self.now.format("%H:%M:%S").to_string(); - self.date.set_and_try_prepare(date).expect("invalid font_id"); - self.time.set_and_try_prepare(time).expect("invalid font_id"); + self.date + .set_and_try_prepare(date) + .expect("invalid font_id"); + self.time + .set_and_try_prepare(time) + .expect("invalid font_id"); let ns = 1_000_000_000 - (self.now.time().nanosecond() % 1_000_000_000); log::info!("Requesting update in {}ns", ns); mgr.request_update(self.id(), 0, Duration::new(0, ns), true); @@ -159,7 +163,9 @@ impl_scope! { } impl Window for Self { - fn title(&self) -> &str { "Clock" } + fn title(&self) -> &str { + "Clock" + } } } diff --git a/examples/counter.rs b/examples/counter.rs index 52092387a..ee15a257c 100644 --- a/examples/counter.rs +++ b/examples/counter.rs @@ -46,7 +46,9 @@ impl_scope! { } } impl Window for Self { - fn title(&self) -> &str { "Counter" } + fn title(&self) -> &str { + "Counter" + } } } diff --git a/examples/mandlebrot/mandlebrot.rs b/examples/mandlebrot/mandlebrot.rs index 3c575db4e..8464d85cb 100644 --- a/examples/mandlebrot/mandlebrot.rs +++ b/examples/mandlebrot/mandlebrot.rs @@ -437,11 +437,15 @@ impl_scope! { }] struct MandlebrotWindow { core: widget_core!(), - #[widget] label: Label, - #[widget] iters: ReserveP>, - #[widget] slider: Slider, + #[widget] + label: Label, + #[widget] + iters: ReserveP>, + #[widget] + slider: Slider, // extra col span allows use of Label's margin - #[widget] mbrot: Mandlebrot, + #[widget] + mbrot: Mandlebrot, } impl MandlebrotWindow { @@ -473,7 +477,9 @@ impl_scope! { } } impl Window for Self { - fn title(&self) -> &str { "Mandlebrot" } + fn title(&self) -> &str { + "Mandlebrot" + } } }