Skip to content

Commit 7d0fef1

Browse files
committed
reformat
1 parent 2ddc77f commit 7d0fef1

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

druid/examples/viewport_header.rs

+41-18
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020

2121
use druid::lens::Unit;
2222
use druid::widget::prelude::*;
23-
use druid::widget::{BackgroundBrush, Button, ClipBox, Controller, Flex, Label, List, Padding, Side, Slider, Tabs, TextBox, ViewportHeader};
24-
use druid::{AppLauncher, Color, Data, Insets, Lens, LocalizedString, Point, Rect, RoundedRectRadii, Selector, Vec2, WidgetExt, WidgetPod, WindowDesc};
23+
use druid::widget::{
24+
BackgroundBrush, Button, ClipBox, Controller, Flex, Label, List, Padding, Side, Slider, Tabs,
25+
TextBox, ViewportHeader,
26+
};
27+
use druid::{
28+
AppLauncher, Color, Data, Insets, Lens, LocalizedString, Point, Rect, RoundedRectRadii,
29+
Selector, Vec2, WidgetExt, WidgetPod, WindowDesc,
30+
};
2531
use im::Vector;
2632
use std::sync::Arc;
2733

@@ -67,7 +73,14 @@ fn build_widget() -> impl Widget<AppData> {
6773
.with_default_spacer()
6874
.with_child(Label::new("Info:").align_left())
6975
.with_default_spacer()
70-
.with_child(List::new(|| TextBox::new().padding(Insets::new(15.0, 0.0, 0.0, 10.0)).expand_width()).lens(Contact::info))
76+
.with_child(
77+
List::new(|| {
78+
TextBox::new()
79+
.padding(Insets::new(15.0, 0.0, 0.0, 10.0))
80+
.expand_width()
81+
})
82+
.lens(Contact::info),
83+
)
7184
.with_child(
7285
Button::new("Add Info").on_click(|_, data: &mut Contact, _| {
7386
data.info.push_back(Arc::new(String::new()))
@@ -80,22 +93,25 @@ fn build_widget() -> impl Widget<AppData> {
8093
.rounded(RoundedRectRadii::new(0.0, 0.0, 10.0, 10.0));
8194

8295
let header = Flex::row()
83-
.with_flex_child(Label::dynamic(|data: &Contact, _| format!("Contact \"{}\"", &data.name)).center(), 1.0)
84-
.with_child(Button::new("X").on_click(|ctx, data: &mut Contact, _|{
85-
ctx.submit_notification(REMOVE_ID.with(data.id))
86-
}).padding(5.0))
96+
.with_flex_child(
97+
Label::dynamic(|data: &Contact, _| format!("Contact \"{}\"", &data.name)).center(),
98+
1.0,
99+
)
100+
.with_child(
101+
Button::new("X")
102+
.on_click(|ctx, data: &mut Contact, _| {
103+
ctx.submit_notification(REMOVE_ID.with(data.id))
104+
})
105+
.padding(5.0),
106+
)
87107
.center()
88108
.background(Color::grey8(15))
89109
.rounded(RoundedRectRadii::new(10.0, 10.0, 0.0, 0.0));
90110

91-
ViewportHeader::new(
92-
body,
93-
header,
94-
Side::Top,
95-
)
96-
.clipped_content(true)
97-
.with_minimum_visible_content(20.0)
98-
.padding(Insets::uniform_xy(0.0, 5.0))
111+
ViewportHeader::new(body, header, Side::Top)
112+
.clipped_content(true)
113+
.with_minimum_visible_content(20.0)
114+
.padding(Insets::uniform_xy(0.0, 5.0))
99115
})
100116
.lens(AppData::list)
101117
.controller(RemoveID)
@@ -128,14 +144,21 @@ const REMOVE_ID: Selector<usize> = Selector::new("org.druid.example.remove_id");
128144
struct RemoveID;
129145

130146
impl<W: Widget<AppData>> Controller<AppData, W> for RemoveID {
131-
fn event(&mut self, child: &mut W, ctx: &mut EventCtx, event: &Event, data: &mut AppData, env: &Env) {
147+
fn event(
148+
&mut self,
149+
child: &mut W,
150+
ctx: &mut EventCtx,
151+
event: &Event,
152+
data: &mut AppData,
153+
env: &Env,
154+
) {
132155
if let Event::Notification(notification) = event {
133156
if let Some(id) = notification.get(REMOVE_ID) {
134157
ctx.set_handled();
135-
data.list.retain(|c|c.id != *id);
158+
data.list.retain(|c| c.id != *id);
136159
}
137160
} else {
138161
child.event(ctx, event, data, env);
139162
}
140163
}
141-
}
164+
}

druid/src/widget/align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
//! A widget that aligns its child (for example, centering it).
1616
17+
use crate::contexts::ChangeCtx;
1718
use crate::debug_state::DebugState;
1819
use crate::widget::prelude::*;
1920
use crate::{Data, Rect, Size, UnitPoint, WidgetPod};
2021
use tracing::{instrument, trace};
21-
use crate::contexts::ChangeCtx;
2222

2323
/// A widget that aligns its child.
2424
pub struct Align<T> {

druid/src/widget/viewport_header.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::commands::SCROLL_TO_VIEW;
22
use crate::widget::flex::{Orientation, Side};
3-
use crate::{BoxConstraints, Data, Env, Event, EventCtx, InternalEvent, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, Point, Rect, Size, UpdateCtx, ViewContext, Widget, WidgetPod};
3+
use crate::{
4+
BoxConstraints, Data, Env, Event, EventCtx, InternalEvent, LayoutCtx, LifeCycle, LifeCycleCtx,
5+
PaintCtx, Point, Rect, Size, UpdateCtx, ViewContext, Widget, WidgetPod,
6+
};
47
use druid::RenderContext;
58

69
/// A widget, containing two widgets with horizontal or vertical layout.
@@ -43,7 +46,8 @@ impl ViewportHeaderConfig {
4346
}
4447

4548
pub fn minimum_visible(&self) -> f64 {
46-
self.minimum_visible_content.min(self.header_side.axis().major(self.content_size))
49+
self.minimum_visible_content
50+
.min(self.header_side.axis().major(self.content_size))
4751
}
4852

4953
/// The the layout size of header and content together, when both are fully in view.
@@ -186,7 +190,8 @@ impl<T: Data> Widget<T> for ViewportHeader<T> {
186190
if self.content.is_active() {
187191
ctx.set_handled();
188192
} else {
189-
self.content.event(ctx, &Event::Internal(InternalEvent::MouseLeave), data, env);
193+
self.content
194+
.event(ctx, &Event::Internal(InternalEvent::MouseLeave), data, env);
190195
return;
191196
}
192197
}

0 commit comments

Comments
 (0)