Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename WidgetPod::paint_with_offset to just paint #980

Merged
merged 2 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i
- `SHOW_WINDOW` and `CLOSE_WINDOW` commands now only use `Target` to determine the affected window. ([#928] by [@finnerale])
- Replaced `NEW_WINDOW`, `SET_MENU` and `SHOW_CONTEXT_MENU` commands with methods on `EventCtx` and `DelegateCtx`. ([#931] by [@finnerale])
- Replaced `Command::one_shot` and `::take_object` with a `SingleUse` payload wrapper type. ([#959] by [@finnerale])
- Rename `WidgetPod::paint_with_offset` to just `paint`. ([#980] by [@totsteps])
totsteps marked this conversation as resolved.
Show resolved Hide resolved

### Deprecated

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

## [0.5.0] - 2020-04-01

Expand Down
2 changes: 1 addition & 1 deletion druid/examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Widget<u32> for TimerWidget {
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &u32, env: &Env) {
self.simple_box.paint_with_offset(ctx, data, env);
self.simple_box.paint(ctx, data, env);
}
}

Expand Down
17 changes: 8 additions & 9 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,16 @@ impl<T, W: Widget<T>> WidgetPod<T, W> {
impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
/// Paint a child widget.
///
/// Generally called by container widgets as part of their [`paint`]
/// Generally called by container widgets as part of their [`Widget::paint`]
/// method.
///
/// Note that this method does not apply the offset of the layout rect.
/// If that is desired, use [`paint_with_offset`] instead.
/// If that is desired, use [`paint`] instead.
///
/// [`layout`]: trait.Widget.html#tymethod.layout
/// [`paint`]: trait.Widget.html#tymethod.paint
/// [`paint_with_offset`]: #method.paint_with_offset
pub fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
/// [`Widget::paint`]: trait.Widget.html#tymethod.paint
/// [`paint`]: #method.paint
pub fn paint_raw(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
// we need to do this before we borrow from self
if env.get(Env::DEBUG_WIDGET_ID) {
self.make_widget_id_layout_if_needed(self.state.id, ctx, env);
Expand Down Expand Up @@ -400,14 +400,13 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
///
/// This will recursively paint widgets, stopping if a widget's layout
/// rect is outside of the currently visible region.
// Discussion: should this be `paint` and the other `paint_raw`?
pub fn paint_with_offset(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
pub fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
self.paint_with_offset_impl(ctx, data, env, false)
totsteps marked this conversation as resolved.
Show resolved Hide resolved
}

/// Paint the widget, even if its layout rect is outside of the currently
/// visible region.
pub fn paint_with_offset_always(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
pub fn paint_always(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
self.paint_with_offset_impl(ctx, data, env, true)
}

Expand All @@ -427,7 +426,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
let layout_origin = self.layout_rect().origin().to_vec2();
ctx.transform(Affine::translate(layout_origin));
let visible = ctx.region().to_rect().intersect(self.state.paint_rect()) - layout_origin;
ctx.with_child_ctx(visible, |ctx| self.paint(ctx, data, env));
ctx.with_child_ctx(visible, |ctx| self.paint_raw(ctx, data, env));
});
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<T: Data> Widget<T> for ReplaceChild<T> {
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
self.inner.paint(ctx, data, env)
self.inner.paint_raw(ctx, data, env)
}
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<T: Data> Widget<T> for Align<T> {
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
self.child.paint_with_offset(ctx, data, env);
self.child.paint(ctx, data, env);
}
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ impl Widget<bool> for Checkbox {
}

// Paint the text label
self.child_label.paint_with_offset(ctx, data, env);
self.child_label.paint(ctx, data, env);
}
}
2 changes: 1 addition & 1 deletion druid/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ impl<T: Data> Widget<T> for Container<T> {
ctx.stroke(border_rect, &border.color.resolve(env), border_width);
};

self.inner.paint_with_offset(ctx, data, env);
self.inner.paint(ctx, data, env);
}
}
4 changes: 2 additions & 2 deletions druid/src/widget/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl<T: Data> Widget<T> for Either<T> {

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
if self.current {
self.true_branch.paint(ctx, data, env);
self.true_branch.paint_raw(ctx, data, env);
} else {
self.false_branch.paint(ctx, data, env);
self.false_branch.paint_raw(ctx, data, env);
}
}
}
2 changes: 1 addition & 1 deletion druid/src/widget/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl<T: Data> Widget<T> for Flex<T> {

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
for child in &mut self.children {
child.widget.paint_with_offset(ctx, data, env);
child.widget.paint(ctx, data, env);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<C: Data, T: ListIter<C>> Widget<T> for List<C> {
let mut children = self.children.iter_mut();
data.for_each(|child_data, _| {
if let Some(child) = children.next() {
child.paint_with_offset(ctx, child_data, env);
child.paint(ctx, child_data, env);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ impl<T: Data> Widget<T> for Padding<T> {
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
self.child.paint_with_offset(ctx, data, env);
self.child.paint(ctx, data, env);
}
}
2 changes: 1 addition & 1 deletion druid/src/widget/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ impl<T: Data + PartialEq> Widget<T> for Radio<T> {
}

// Paint the text label
self.child_label.paint_with_offset(ctx, data, env);
self.child_label.paint(ctx, data, env);
}
}
2 changes: 1 addition & 1 deletion druid/src/widget/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for Scroll<T, W> {
ctx.transform(Affine::translate(-self.scroll_offset));

let visible = ctx.region().to_rect() + self.scroll_offset;
ctx.with_child_ctx(visible, |ctx| self.child.paint(ctx, data, env));
ctx.with_child_ctx(visible, |ctx| self.child.paint_raw(ctx, data, env));

self.draw_bars(ctx, viewport, env);
});
Expand Down
4 changes: 2 additions & 2 deletions druid/src/widget/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ impl<T: Data> Widget<T> for Split<T> {
} else {
self.paint_stroked_bar(ctx, env);
}
self.child1.paint_with_offset(ctx, &data, env);
self.child2.paint_with_offset(ctx, &data, env);
self.child1.paint(ctx, &data, env);
self.child2.paint(ctx, &data, env);
}
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/view_switcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<T: Data, U: PartialEq> Widget<T> for ViewSwitcher<T, U> {

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
if let Some(ref mut child) = self.active_child {
child.paint(ctx, data, env);
child.paint_raw(ctx, data, env);
}
}
}
2 changes: 1 addition & 1 deletion druid/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<T: Data> Window<T> {
region: invalid_rect.into(),
depth: 0,
};
ctx.with_child_ctx(invalid_rect, |ctx| self.root.paint(ctx, data, env));
ctx.with_child_ctx(invalid_rect, |ctx| self.root.paint_raw(ctx, data, env));

let mut z_ops = mem::take(&mut ctx.z_ops);
z_ops.sort_by_key(|k| k.z_index);
Expand Down