Skip to content

Commit

Permalink
Simplify demo with new Frame API
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 25, 2024
1 parent c5aa4fd commit faeb1eb
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions crates/egui_demo_lib/src/demo/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ use egui::*;
fn drop_zone<R>(
ui: &mut Ui,
can_accept_what_is_being_dragged: bool,
add_content: impl FnOnce(&mut Ui) -> R,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let is_anything_being_dragged = DragAndDrop::has_any_payload(ui.ctx());

let margin = Vec2::splat(4.0);

let outer_rect_bounds = ui.available_rect_before_wrap();
let inner_rect = outer_rect_bounds.shrink2(margin);
let where_to_put_background = ui.painter().add(Shape::Noop);
let mut content_ui = ui.child_ui(inner_rect, *ui.layout());
let ret = add_content(&mut content_ui);
let outer_rect = Rect::from_min_max(outer_rect_bounds.min, content_ui.min_rect().max + margin);
let (rect, response) = ui.allocate_at_least(outer_rect.size(), Sense::hover());
let frame = Frame::default().inner_margin(4.0);
let mut frame = frame.begin(ui);
let ret = add_contents(&mut frame.content_ui);
let response = frame.allocate_space(ui);

// NOTE: we use `response.contains_pointer` here instead of `hovered`, because
// `hovered` is always false when another widget is being dragged.
Expand All @@ -37,10 +32,10 @@ fn drop_zone<R>(
stroke.color = ui.visuals().gray_out(stroke.color);
}

ui.painter().set(
where_to_put_background,
epaint::RectShape::new(rect, style.rounding, fill, stroke),
);
frame.frame.fill = fill;
frame.frame.stroke = stroke;

frame.paint(ui);

InnerResponse::new(ret, response)
}
Expand Down

0 comments on commit faeb1eb

Please sign in to comment.