Drag Card

A floating card that can be dragged and closed. Used for movable panels.

Preview

Rendered in WASM — scroll may behave differently from the rest of the page

Usage

rust
use ui_theme::components::drag_card::{drag_card, DragCardState};

let mut state = DragCardState {
  pos: egui::pos2(100.0, 100.0),
  size: egui::vec2(250.0, 200.0),
};

let response = drag_card(ui, &theme, egui::Id::new("my_card"), &mut state, "Panel", |ui| {
  ui.label("Drag me around!");
});

if response.closed {
  // Handle close
}

Props

Prop Type Default Description
ui &mut Ui required The egui UI context
theme &Theme required Theme instance
id Id required Unique widget ID
state &mut DragCardState required Position and size state
title &str required Card title
add_contents impl FnOnce(&mut Ui) required Card body content

Response

FieldTypeDescription
closedboolClose button was clicked
draggingboolCard is being dragged