Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
file_drop_zone.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <pulp/view/view.hpp>
5#include <functional>
6#include <vector>
7#include <string>
8
9namespace pulp::view {
10
11// ── FileDropZone ────────────────────────────────────────────────────────────
12// Drag-and-drop file target with visual feedback. Implements DropReceiver so the
13// native drop-dispatch core (drag_drop.cpp) routes file drops here without
14// knowing the concrete type.
15
16class FileDropZone : public View, public DropReceiver {
17public:
19
22 void set_accepted_extensions(std::vector<std::string> exts);
23 const std::vector<std::string>& accepted_extensions() const { return extensions_; }
24
26 void set_label(std::string text) { label_ = std::move(text); }
27 const std::string& label() const { return label_; }
28
30 void set_hover_label(std::string text) { hover_label_ = std::move(text); }
31
33 enum class IconStyle { upload, folder, none };
34 void set_icon_style(IconStyle s) { icon_style_ = s; }
35
37 std::function<void(const std::vector<std::string>& paths)> on_drop;
38
45 void set_browse_on_click(bool on) { browse_on_click_ = on; }
46 bool browse_on_click() const { return browse_on_click_; }
48 void set_dialog_title(std::string title) { dialog_title_ = std::move(title); }
49
51 bool is_drag_over() const { return drag_over_; }
52 bool is_drag_valid() const { return drag_valid_; }
53
54 void paint(canvas::Canvas& canvas) override;
55 void on_mouse_event(const MouseEvent& event) override;
56 bool wants_mouse_input() const override { return true; }
57
58 // Called by the platform drag-drop system
59 void drag_enter(const std::vector<std::string>& paths);
60 void drag_leave();
61 void drop(const std::vector<std::string>& paths);
62
63 // DropReceiver — the dispatch core drives these; they delegate to the typed
64 // drag_enter/drag_leave/drop above. A FileDropZone consumes file drops in its
65 // region (returns true) and ignores text/custom (lets them bubble).
66 bool accept_drag(const DropData& data, Point local) override;
67 void leave_drag() override;
68 bool accept_drop(const DropData& data, Point local) override;
69
70 float intrinsic_height() const override { return 120.0f; }
71
72private:
73 std::vector<std::string> extensions_;
74 std::string label_ = "Drop files here";
75 std::string hover_label_ = "Release to drop";
76 IconStyle icon_style_ = IconStyle::upload;
77 bool drag_over_ = false;
78 bool drag_valid_ = false;
79 bool browse_on_click_ = true;
80 std::string dialog_title_ = "Choose a file";
81
82 bool is_valid_extension(const std::string& path) const;
83};
84
85} // namespace pulp::view
Definition canvas.hpp:240
Definition drag_drop.hpp:37
void set_label(std::string text)
Label shown when idle.
Definition file_drop_zone.hpp:26
bool wants_mouse_input() const override
True if this widget handles mouse down/drag through virtual methods even when it does not expose JS p...
Definition file_drop_zone.hpp:56
const std::string & label() const
Definition file_drop_zone.hpp:27
void set_dialog_title(std::string title)
Title for the click-to-browse dialog (default "Choose a file").
Definition file_drop_zone.hpp:48
void drop(const std::vector< std::string > &paths)
void on_mouse_event(const MouseEvent &event) override
Mouse down with full event context.
void drag_enter(const std::vector< std::string > &paths)
std::function< void(const std::vector< std::string > &paths)> on_drop
Callback when files are dropped.
Definition file_drop_zone.hpp:37
void leave_drag() override
void set_browse_on_click(bool on)
Click-to-browse (on by default): a left click opens the platform file picker (pulp::platform::FileDia...
Definition file_drop_zone.hpp:45
bool accept_drop(const DropData &data, Point local) override
bool accept_drag(const DropData &data, Point local) override
IconStyle
Icon type to display.
Definition file_drop_zone.hpp:33
@ none
Definition file_drop_zone.hpp:33
@ upload
Definition file_drop_zone.hpp:33
@ folder
Definition file_drop_zone.hpp:33
void set_icon_style(IconStyle s)
Definition file_drop_zone.hpp:34
void set_accepted_extensions(std::vector< std::string > exts)
Accepted file extensions (e.g., {".wav", ".aiff", ".mp3"}).
bool browse_on_click() const
Definition file_drop_zone.hpp:46
bool is_drag_over() const
Current drag-over state (for external styling).
Definition file_drop_zone.hpp:51
float intrinsic_height() const override
Definition file_drop_zone.hpp:70
void paint(canvas::Canvas &canvas) override
const std::vector< std::string > & accepted_extensions() const
Definition file_drop_zone.hpp:23
void set_hover_label(std::string text)
Label shown when hovering with valid files.
Definition file_drop_zone.hpp:30
bool is_drag_valid() const
Definition file_drop_zone.hpp:52
@ text
Definition view.hpp:2742
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ path
Definition anchor_strategy.hpp:42
@ s
Definition input_events.hpp:41
@ on
Definition accessibility.hpp:132
Definition drag_drop.hpp:14
Rich mouse/pointer event with position, modifiers, button state, pointer ID, and stylus properties.
Definition input_events.hpp:104
Definition geometry.hpp:20