Skip to content

Commit 284daf3

Browse files
authored
Rename WidgetPod::paint_with_offset to just paint (#980)
1 parent 5b10bdb commit 284daf3

File tree

16 files changed

+29
-34
lines changed

16 files changed

+29
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i
7171
- `SHOW_WINDOW` and `CLOSE_WINDOW` commands now only use `Target` to determine the affected window. ([#928] by [@finnerale])
7272
- Replaced `NEW_WINDOW`, `SET_MENU` and `SHOW_CONTEXT_MENU` commands with methods on `EventCtx` and `DelegateCtx`. ([#931] by [@finnerale])
7373
- Replaced `Command::one_shot` and `::take_object` with a `SingleUse` payload wrapper type. ([#959] by [@finnerale])
74+
- Renamed `WidgetPod` methods: `paint` to `paint_raw`, `paint_with_offset` to `paint`, `paint_with_offset_always` to `paint_always`. ([#980] by [@totsteps])
7475

7576
### Deprecated
7677

@@ -227,6 +228,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i
227228
[#967]: https://github.com/xi-editor/druid/pull/967
228229
[#969]: https://github.com/xi-editor/druid/pull/969
229230
[#970]: https://github.com/xi-editor/druid/pull/970
231+
[#980]: https://github.com/xi-editor/druid/pull/980
230232

231233
## [0.5.0] - 2020-04-01
232234

druid/examples/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Widget<u32> for TimerWidget {
7979
}
8080

8181
fn paint(&mut self, ctx: &mut PaintCtx, data: &u32, env: &Env) {
82-
self.simple_box.paint_with_offset(ctx, data, env);
82+
self.simple_box.paint(ctx, data, env);
8383
}
8484
}
8585

druid/src/core.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,16 @@ impl<T, W: Widget<T>> WidgetPod<T, W> {
356356
impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
357357
/// Paint a child widget.
358358
///
359-
/// Generally called by container widgets as part of their [`paint`]
359+
/// Generally called by container widgets as part of their [`Widget::paint`]
360360
/// method.
361361
///
362362
/// Note that this method does not apply the offset of the layout rect.
363-
/// If that is desired, use [`paint_with_offset`] instead.
363+
/// If that is desired, use [`paint`] instead.
364364
///
365365
/// [`layout`]: trait.Widget.html#tymethod.layout
366-
/// [`paint`]: trait.Widget.html#tymethod.paint
367-
/// [`paint_with_offset`]: #method.paint_with_offset
368-
pub fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
366+
/// [`Widget::paint`]: trait.Widget.html#tymethod.paint
367+
/// [`paint`]: #method.paint
368+
pub fn paint_raw(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
369369
// we need to do this before we borrow from self
370370
if env.get(Env::DEBUG_WIDGET_ID) {
371371
self.make_widget_id_layout_if_needed(self.state.id, ctx, env);
@@ -400,25 +400,18 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
400400
///
401401
/// This will recursively paint widgets, stopping if a widget's layout
402402
/// rect is outside of the currently visible region.
403-
// Discussion: should this be `paint` and the other `paint_raw`?
404-
pub fn paint_with_offset(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
405-
self.paint_with_offset_impl(ctx, data, env, false)
403+
pub fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
404+
self.paint_impl(ctx, data, env, false)
406405
}
407406

408407
/// Paint the widget, even if its layout rect is outside of the currently
409408
/// visible region.
410-
pub fn paint_with_offset_always(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
411-
self.paint_with_offset_impl(ctx, data, env, true)
409+
pub fn paint_always(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
410+
self.paint_impl(ctx, data, env, true)
412411
}
413412

414413
/// Shared implementation that can skip drawing non-visible content.
415-
fn paint_with_offset_impl(
416-
&mut self,
417-
ctx: &mut PaintCtx,
418-
data: &T,
419-
env: &Env,
420-
paint_if_not_visible: bool,
421-
) {
414+
fn paint_impl(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env, paint_if_not_visible: bool) {
422415
if !paint_if_not_visible && !ctx.region().intersects(self.state.paint_rect()) {
423416
return;
424417
}
@@ -427,7 +420,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
427420
let layout_origin = self.layout_rect().origin().to_vec2();
428421
ctx.transform(Affine::translate(layout_origin));
429422
let visible = ctx.region().to_rect().intersect(self.state.paint_rect()) - layout_origin;
430-
ctx.with_child_ctx(visible, |ctx| self.paint(ctx, data, env));
423+
ctx.with_child_ctx(visible, |ctx| self.paint_raw(ctx, data, env));
431424
});
432425
}
433426

druid/src/tests/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<T: Data> Widget<T> for ReplaceChild<T> {
236236
}
237237

238238
fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
239-
self.inner.paint(ctx, data, env)
239+
self.inner.paint_raw(ctx, data, env)
240240
}
241241
}
242242

druid/src/widget/align.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<T: Data> Widget<T> for Align<T> {
131131
}
132132

133133
fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
134-
self.child.paint_with_offset(ctx, data, env);
134+
self.child.paint(ctx, data, env);
135135
}
136136
}
137137

druid/src/widget/checkbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ impl Widget<bool> for Checkbox {
136136
}
137137

138138
// Paint the text label
139-
self.child_label.paint_with_offset(ctx, data, env);
139+
self.child_label.paint(ctx, data, env);
140140
}
141141
}

druid/src/widget/container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ impl<T: Data> Widget<T> for Container<T> {
154154
ctx.stroke(border_rect, &border.color.resolve(env), border_width);
155155
};
156156

157-
self.inner.paint_with_offset(ctx, data, env);
157+
self.inner.paint(ctx, data, env);
158158
}
159159
}

druid/src/widget/either.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ impl<T: Data> Widget<T> for Either<T> {
103103

104104
fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
105105
if self.current {
106-
self.true_branch.paint(ctx, data, env);
106+
self.true_branch.paint_raw(ctx, data, env);
107107
} else {
108-
self.false_branch.paint(ctx, data, env);
108+
self.false_branch.paint_raw(ctx, data, env);
109109
}
110110
}
111111
}

druid/src/widget/flex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<T: Data> Widget<T> for Flex<T> {
647647

648648
fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
649649
for child in &mut self.children {
650-
child.widget.paint_with_offset(ctx, data, env);
650+
child.widget.paint(ctx, data, env);
651651
}
652652
}
653653
}

druid/src/widget/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<C: Data, T: ListIter<C>> Widget<T> for List<C> {
269269
let mut children = self.children.iter_mut();
270270
data.for_each(|child_data, _| {
271271
if let Some(child) = children.next() {
272-
child.paint_with_offset(ctx, child_data, env);
272+
child.paint(ctx, child_data, env);
273273
}
274274
});
275275
}

0 commit comments

Comments
 (0)