dymokomi/luce-ui
Source of release 0.19.5
0.19.5 / src / docking / drag.lucb
## Pure drop geometry. The header accepts tabs; outer content quarters split.
## A pane's middle, like the outside, is no target: a panel let go there floats.
from luce_std import math
from luce_gpu.gpu import Rect
from docking.model import Model, Geometry, DockPosition
from docking.strip import contains
pub struct Drop:
pub var accepted: bool
pub var group: usize
pub var position: DockPosition
pub var preview: Rect
pub func target(model: Model*, geometry: Geometry*, x: f64, y: f64, header: f64) -> Drop:
for group in 1..<model.nodes.length:
if not model.nodes[group].used or model.nodes[group].first != 0:
continue
let bounds = geometry.panes[group]
if not contains(bounds, x, y): continue
let content = Rect(bounds.x + 1.0, bounds.y + header + 1.0,
math.max(0.0, bounds.width - 2.0), math.max(0.0, bounds.height - header - 2.0))
var drop = Drop(accepted = true, group = group, preview = bounds)
if y < content.y or content.width == 0.0 or content.height == 0.0:
return drop
let left = (x - content.x) / content.width
let right = 1.0 - left
let top = (y - content.y) / content.height
let bottom = 1.0 - top
let edge = math.min(math.min(left, right), math.min(top, bottom))
if edge >= 0.25: return Drop()
if edge == left:
drop.position = DockPosition.left
drop.preview.width *= 0.5
elif edge == right:
drop.position = DockPosition.right
drop.preview.x += bounds.width * 0.5
drop.preview.width *= 0.5
elif edge == top:
drop.position = DockPosition.top
drop.preview.height *= 0.5
else:
drop.position = DockPosition.bottom
drop.preview.y += bounds.height * 0.5
drop.preview.height *= 0.5
return drop
return Drop()