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

horizontal_wrapped does not work with scope inside #2798

Open
xNxExOx opened this issue Mar 10, 2023 · 0 comments
Open

horizontal_wrapped does not work with scope inside #2798

xNxExOx opened this issue Mar 10, 2023 · 0 comments
Labels
bug Something is broken

Comments

@xNxExOx
Copy link
Contributor

xNxExOx commented Mar 10, 2023

horizontal_wrapped does not work with scope inside
When scope is used inside horizontal_wrapped it newer wraps.

I discovered it, when trying to use Drag & Drop, based on the example where with_layer_id is used to create the effect, but it internally calls scope.

To Reproduce
Steps to reproduce the behavior:

ui.horizontal_wrapped(|ui:&mut egui::Ui|{
  for x in anything {
    drag_source(ui, /*...*/);
    // or just
    ui.scope(/*...*/);
  }
});

It will newer wrap

Expected behavior
horizontal_wrapped can be used with Drag & Drop (meaning with scope inside).

Screenshots

my app

before d&d
before d&d

drag "Harvester" card (Card is not wrapped, which causes it to be on first row, which causes everything to shift, scroll area to resize, and only part of card being visible)
drag "Harvester" card

dragging other (not beginning of wrapped row) cards works, because of partial workaround
dragging other cards works

Desktop:

  • OS: Windows 10
  • Browser Chrome, Firefox

Additional context
Partial workaround applied in my app, to have drag and drop not broken for most is to remove the scope in "not dragging part" of the code:

partial workaround
fn drag_source(ui: &mut egui::Ui, id: Id, body: impl FnOnce(&mut egui::Ui) -> Response) {
    let is_being_dragged = ui.memory(|mem| mem.is_being_dragged(id));

    if !is_being_dragged {
        // this is the fixed version
        let response = body(ui);
        //let response = ui.scope(body).response; // this is the broken version where everything would be on single line, with no wrap

        let response = ui.interact(response.rect, id, Sense::drag());
        if response.hovered() {
            ui.ctx().set_cursor_icon(egui::CursorIcon::Grab);
        }
    } else {
        ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing);
        let layer_id = egui::LayerId::new(egui::Order::Tooltip, id);

        // here it breaks, because `with_layer_id` does not have "no `scope`" version
        let response = ui.with_layer_id(layer_id, body).response;

        if let Some(pointer_pos) = ui.ctx().pointer_interact_pos() {
            let delta = pointer_pos - response.rect.center();
            ui.ctx().translate_layer(layer_id, delta);
        }
    }
}
@xNxExOx xNxExOx added the bug Something is broken label Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant