yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
drop_zone_suggester.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_DROP_ZONE_SUGGESTER_H_
2#define YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_DROP_ZONE_SUGGESTER_H_
3
4#include <cstdint>
5
7#include "imgui/imgui.h"
8#include "imgui/imgui_internal.h"
9
10namespace yaze {
11namespace editor {
12namespace layout_designer {
13
14// Which way the mouse-over-a-leaf maps to a tree mutation.
15// Edge bands take the outer ~30% of each axis; the inner region is tab.
17 enum class Kind : std::uint8_t {
18 kNone,
19 kTab, // append to leaf's panels, make active.
20 kSplitLeft, // new panel takes left 30%, existing leaf occupies right.
21 kSplitRight, // new panel takes right 30%, existing occupies left.
22 kSplitTop, // new panel takes top 30%, existing occupies bottom.
23 kSplitBottom, // new panel takes bottom 30%, existing occupies top.
24 };
26};
27
28// Edge band as a fraction of rect width/height. Mouse positions whose
29// relative distance to the nearest edge falls below this threshold become
30// split suggestions; all other interior positions become tabs.
31constexpr float kDropEdgeFraction = 0.3f;
32
33// Split ratio applied when the suggestion creates a new leaf. Using a
34// smaller value keeps the existing leaf (which usually holds more user
35// state) dominant after the split.
36constexpr float kDropSplitRatio = 0.3f;
37
38// Pure geometry: classify `mouse` within `leaf_rect`. Returns kNone when
39// `mouse` is outside the rect or the rect is degenerate.
40DropSuggestion SuggestDrop(const ImRect& leaf_rect, ImVec2 mouse);
41
42// Returns the rect the new panel would occupy if the suggestion applied.
43// For kTab the full leaf_rect is returned (tabs paint atop the leaf). For
44// kNone the returned rect is empty (Min == Max == leaf_rect.Min).
45ImRect ComputeDropPreviewRect(const ImRect& leaf_rect,
46 const DropSuggestion& suggestion);
47
48// Apply `suggestion` to `tree`, using `leaf` as the drop target. Returns
49// the leaf that now owns `panel`, or nullptr (no mutation) when:
50// - tree or leaf is null,
51// - suggestion is kNone,
52// - leaf is not a kLeaf node (collapsed splits render like leaves but
53// still reject drops — the user must grow the split before dropping
54// into it),
55// - panel.panel_id is empty, or
56// - panel.panel_id is already present elsewhere in the tree (DockTree
57// invariant requires unique panel_ids).
59 const DropSuggestion& suggestion,
60 PanelEntry panel);
61
62} // namespace layout_designer
63} // namespace editor
64} // namespace yaze
65
66#endif // YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_DROP_ZONE_SUGGESTER_H_
DropSuggestion SuggestDrop(const ImRect &leaf_rect, ImVec2 mouse)
ImRect ComputeDropPreviewRect(const ImRect &leaf_rect, const DropSuggestion &suggestion)
DockNode * ApplyDropSuggestion(DockTree *tree, DockNode *leaf, const DropSuggestion &suggestion, PanelEntry panel)
Represents a dock node in the layout tree.
Definition dock_tree.h:61