ZZufyUI文档首页DocumentationДокументацияDokumentationDocumentationDocumentación

正在准备文档Preparing your docsПодготовка документацииDokumentation wird geladenPréparation de la documentationPreparando la documentación

Language

API reference / v1.29.1

Drag & Drop, cards

Drag & Drop, Expander, SettingsList (v1.19.0)

Download Markdown

Drag & drop comes from ZufyUIDragDrop.h (already included at the end of ZufyUI.h). In-app default is MOVE, cross-app is COPY.

// ---- drag & drop: payload / events ----
class DragData {                                   // read-only for the drop target
    bool HasText() const;   std::wstring GetText() const;
    bool HasFiles() const;  std::vector<std::wstring> GetFiles() const;
    bool HasFormat(const std::wstring& fmt) const;
    bool GetFormatData(const std::wstring& fmt, std::vector<BYTE>& out) const;
};
struct DragEventArgs { const DragData& data; float x, y; DWORD allowed, effect, keyState; };   // x/y are element-relative DIP

// ---- drag & drop: source side ----
class DragDataBuilder {
    DragDataBuilder& AddText(const std::wstring&);
    DragDataBuilder& AddFile(const std::wstring& path);
    DragDataBuilder& AddFiles(const std::vector<std::wstring>& paths);
    DragDataBuilder& AddCustom(const std::wstring& fmt, const void* bytes, size_t n);
    DragDataBuilder& SetPreferredEffect(DWORD);
};
DWORD Window::BeginDrag(DragDataBuilder&, DWORD allowed = COPY|MOVE|LINK, UIElement* source = nullptr);

// ---- drag & drop: target side (element) ----
void UIElement::SetDropTargetEnabled(bool);   bool IsDropTargetEnabled() const;
DWORD UIElement::GetAllowedDropEffects() const;                   // default COPY|MOVE|LINK
DWORD UIElement::OnDragEnter/OnDragOver(DragEventArgs&);         // returns effect
void  UIElement::OnDragLeave(DragEventArgs&);   DWORD UIElement::OnDrop(DragEventArgs&);
void UIElement::SetDragSource(std::function<void(DragDataBuilder&)>, DWORD allowed = COPY|MOVE|LINK);
ZSignal<DragEventArgs&> DragEnter, DragOver, DragLeave, Drop;

// ---- drag & drop: whole-window (when no drop-enabled element is under the cursor) ----
void Window::SetDropTargetEnabled(bool);   bool Window::IsDropTargetEnabled() const;
ZSignal<DragEventArgs&> Window::DragEnter, DragOver, DragLeave, Drop;   // x/y = client-area DIP

// ---- Expander: collapsible card ----
class Expander : public UIElement {
    Expander(const std::wstring& title = L"", const std::wstring& subtitle = L"");
    void SetTitle/SetSubtitle(const std::wstring&);   void SetContent(std::shared_ptr<UIElement>);
    std::shared_ptr<UIElement> GetContent() const;
    void SetExpanded(bool);   bool IsExpanded() const;   void Toggle();
    void SetIcon(Icon, float size = 22.0f);   // leading icon (None = none)
    ZSignal<bool> ExpandedChanged;
};

// ---- SettingsList: settings row list ----
class SettingsList : public UIElement {
    void AddRow(Icon, const std::wstring& text, const std::wstring& subtitle, std::function<void()> onClick, const std::wstring& id = {});
    ZSignal<int> RowClicked;
};
  • Same-control text drag: the source deletes the original selection first, then inserts at the drop point (with left-shift fix); the target detects the private ZufyUI.TextSource format and skips the duplicate insert.

Pitfall

  • DragEventArgs.x/y are element-relative DIP (not screen pixels).
  • Expander drives its expanded height through Measure; it no longer writes the user-visible height_. The parent layout still shrinks/grows with the animation.
  • The content is measured once even while initially collapsed; while expanded it always stays in childrenView_, so collapse/re-expand no longer loses the content.
  • Content clipping keeps at least a 4 px bleed (plus the content's own bleed), so ComboBox borders/shadows/focus rings are not cut off.
  • Version: collapse/expand uses the same smoothstep easing as page transitions; the arrow rotates with that easing (collapsed points down → expanded points up). v1.26.0 fixes first-expand measurement, lost content after collapse/re-expand, and content clipping.
  • Version: the header highlights on hover (rounded); the ComboBox dropdown arrow is likewise a chevron that rotates with expansion.
  • Image display uses Label: SetImage + SetImageFit(true) (scale to fully visible) + SetDragSource (drag-out).
  • Version: whole-window receive — Window::SetDropTargetEnabled(true) + window-level DragEnter/DragOver/DragLeave/Drop (x/y = client-area DIP).
  • Version: Expander::SetIcon(Icon, size) adds a leading icon; TextEdit undo/redo uses the standard scheme (both restore the selection and cursor of that point).
View sourcedocs/src/API.en.md