mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-16 07:11:52 +00:00
LibGUI+WindowServer: Allow specifying an optional drag bitmap
This bitmap is displayed alongside the dragged text underneath the mouse cursor while dragging. This will be a perfect fit for dragging e.g files around. :^)
This commit is contained in:
parent
183ee5847c
commit
f5dfb29607
Notes:
sideshowbarker
2024-07-19 10:55:16 +09:00
Author: https://github.com/awesomekling
Commit: f5dfb29607
5 changed files with 36 additions and 6 deletions
|
@ -113,14 +113,23 @@ void GItemView::mousemove_event(GMouseEvent& event)
|
|||
dbg() << "Initiate drag!";
|
||||
auto drag_operation = GDragOperation::construct();
|
||||
|
||||
RefPtr<GraphicsBitmap> bitmap;
|
||||
|
||||
StringBuilder builder;
|
||||
selection().for_each_index([&](auto& index) {
|
||||
auto data = model()->data(index);
|
||||
builder.append(data.to_string());
|
||||
builder.append(" ");
|
||||
|
||||
if (!bitmap) {
|
||||
GVariant icon_data = model()->data(index, GModel::Role::Icon);
|
||||
if (icon_data.is_icon())
|
||||
bitmap = icon_data.as_icon().bitmap_for_size(32);
|
||||
}
|
||||
});
|
||||
|
||||
drag_operation->set_text(builder.to_string());
|
||||
drag_operation->set_bitmap(bitmap);
|
||||
auto outcome = drag_operation->exec();
|
||||
switch (outcome) {
|
||||
case GDragOperation::Outcome::Accepted:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue