Skip to content

Commit

Permalink
Use rustfmt#5538 to format macro bodies (temporary)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Oct 8, 2022
1 parent aa32edd commit b90f126
Show file tree
Hide file tree
Showing 31 changed files with 335 additions and 174 deletions.
4 changes: 1 addition & 3 deletions crates/kas-macros/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,7 @@ pub fn widget(mut args: WidgetArgs, scope: &mut Scope) -> Result<()> {
set_rect = quote! {
<Self as ::kas::layout::AutoLayout>::set_rect(self, mgr, rect);
};
find_id = quote! {
<Self as ::kas::layout::AutoLayout>::find_id(self, coord)
};
find_id = quote! { <Self as ::kas::layout::AutoLayout>::find_id(self, coord) };
fn_draw = Some(quote! {
fn draw(&mut self, draw: ::kas::theme::DrawMgr) {
<Self as ::kas::layout::AutoLayout>::draw(self, draw);
Expand Down
8 changes: 5 additions & 3 deletions crates/kas-resvg/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: CanvasProgram> {
core: widget_core!(),
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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
});
}
Expand Down
11 changes: 6 additions & 5 deletions crates/kas-resvg/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
Expand Down Expand Up @@ -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
});
}
Expand Down
33 changes: 22 additions & 11 deletions crates/kas-view/src/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,28 @@ impl_scope! {
#[derive(Debug)]
pub struct EventConfigWidget {
core: widget_core!(),
#[widget] menu_delay: Spinner<u32>,
#[widget] touch_select_delay: Spinner<u32>,
#[widget] scroll_flick_timeout: Spinner<u32>,
#[widget] scroll_flick_mul: Spinner<f32>,
#[widget] scroll_flick_sub: Spinner<f32>,
#[widget] scroll_dist_em: Spinner<f32>,
#[widget] pan_dist_thresh: Spinner<f32>,
#[widget] mouse_pan: ComboBox<MousePan>,
#[widget] mouse_text_pan: ComboBox<MousePan>,
#[widget] mouse_nav_focus: CheckButton,
#[widget] touch_nav_focus: CheckButton,
#[widget]
menu_delay: Spinner<u32>,
#[widget]
touch_select_delay: Spinner<u32>,
#[widget]
scroll_flick_timeout: Spinner<u32>,
#[widget]
scroll_flick_mul: Spinner<f32>,
#[widget]
scroll_flick_sub: Spinner<f32>,
#[widget]
scroll_dist_em: Spinner<f32>,
#[widget]
pan_dist_thresh: Spinner<f32>,
#[widget]
mouse_pan: ComboBox<MousePan>,
#[widget]
mouse_text_pan: ComboBox<MousePan>,
#[widget]
mouse_nav_focus: CheckButton,
#[widget]
touch_nav_focus: CheckButton,
}
}

Expand Down
61 changes: 43 additions & 18 deletions crates/kas-view/src/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ impl_scope! {
/// widget emits a [`SelectionMsg`].
#[derive(Clone, Debug)]
#[widget]
pub struct ListView<
D: Directional,
T: ListData,
V: Driver<T::Item, T> = driver::View,
> {
pub struct ListView<D: Directional, T: ListData, V: Driver<T::Item, T> = driver::View> {
core: widget_core!(),
frame_offset: Offset,
frame_size: Size,
Expand Down Expand Up @@ -82,7 +78,11 @@ impl_scope! {
press_target: Option<T::Key>,
}

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
Expand All @@ -92,13 +92,19 @@ impl_scope! {
Self::new_with_dir_driver(D::default(), <V as 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, <V as Default>::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)
Expand Down Expand Up @@ -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);
}

Expand All @@ -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<U>(&self, mgr: &mut EventMgr, key: &T::Key, f: impl FnOnce(&mut T::Item) -> U) -> Option<U> where T: SharedDataMut {
pub fn update_value<U>(
&self,
mgr: &mut EventMgr,
key: &T::Key,
f: impl FnOnce(&mut T::Item) -> U,
) -> Option<U>
where
T: SharedDataMut,
{
self.data.with_ref_mut(mgr, key, f)
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
});
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}
Expand Down
Loading

0 comments on commit b90f126

Please sign in to comment.