mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 19:13:28 +00:00
Dock drags: one region mark that carries the panel's name, no frame at the pointer (photocraft#15526)
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
//! The ghost layer's content (8.4, 8.5): the running drag's preview beside the pointer, the mark of the drop target that
|
||||
//! would take the payload, and the painted pointer the cursor service settled on, which goes to the window as its
|
||||
//! cursor image instead where the window takes one. They come from the drag session's data and the cursor record; the
|
||||
//! layer takes no input.
|
||||
//! would take the payload (with the payload's name inside a region mark, for a drag that names it), and the painted
|
||||
//! pointer the cursor service settled on, which goes to the window as its cursor image instead where the window takes
|
||||
//! one. They come from the drag session's data and the cursor record; the layer takes no input.
|
||||
|
||||
use crate::primitives::pointer_art::{self as pointers, Art};
|
||||
|
||||
use crate::primitives::{Draw, DrawEnv, IconSet, Mirror, PaintRecord, PaintShape, RuleKind, SvgIcon, TextRun, outline};
|
||||
use crate::runtime::drag::{self, DragPreview, DropMark};
|
||||
use crate::runtime::egui::areas;
|
||||
use crate::runtime::env::Env;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::{cursor, pointer};
|
||||
use crate::style::{Corners, Ink, RuleWidth, SurfaceKind, rule_look};
|
||||
use craft_behavior::Flow;
|
||||
@@ -116,6 +116,9 @@ fn pointer_art(env: &Env, cursor: &craft_behavior::PaintedCursor, closed: bool,
|
||||
fn paint_drag(ctx: &Context, env: &Env, painter: &egui::Painter, draw: &Draw<'_>, session: &drag::Ghost) {
|
||||
if let Some(mark) = session.mark {
|
||||
paint_mark(painter, env, mark);
|
||||
if let (DropMark::Region { area, .. }, DragPreview::Named(name)) = (mark, &session.preview) {
|
||||
paint_region_name(draw, env, area, name);
|
||||
}
|
||||
}
|
||||
let Some(at) = pointer::frame(ctx).pos else { return };
|
||||
match &session.preview {
|
||||
@@ -139,6 +142,22 @@ fn paint_drag(ctx: &Context, env: &Env, painter: &egui::Painter, draw: &Draw<'_>
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload's name inside the region `area` a drop would take: at the reading start of its top, inside the mark's
|
||||
/// band, on one line elided to the area's width. A region too small for the line shows no name.
|
||||
fn paint_region_name(draw: &Draw<'_>, env: &Env, area: Rect, name: &Label) {
|
||||
let name = env.view().resolve(name);
|
||||
let inner = area.shrink(env.tokens.space.pad.control);
|
||||
if inner.width() <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let layout = draw.layout(&TextRun::new(name.as_str()).elide(), inner.width());
|
||||
if layout.size().y > inner.height() {
|
||||
return;
|
||||
}
|
||||
let (at, _) = Flow::new(inner, env.direction.is_rtl()).take_start(layout.size().x.min(inner.width()));
|
||||
draw.galley(at.min, &layout);
|
||||
}
|
||||
|
||||
fn paint_drag_badge(draw: &Draw<'_>, env: &Env, at: Pos2, text: &str) {
|
||||
let space = &env.tokens.space;
|
||||
let run = TextRun::new(text);
|
||||
|
||||
@@ -28,8 +28,11 @@ pub enum DragPreview {
|
||||
None,
|
||||
/// A badge with a short text ("3 files").
|
||||
Badge(Label),
|
||||
/// A frame-sized outline centred on the pointer, with an optional label inside its top corner: the ghost of a
|
||||
/// panel or window being moved.
|
||||
/// Nothing beside the pointer: the payload's name shows inside the area of a region mark, as a panel or group
|
||||
/// being moved names the place it would take. With no mark, nothing shows.
|
||||
Named(Label),
|
||||
/// An outline of `size` centred on the pointer, with an optional label inside its top corner: the ghost of a part
|
||||
/// dragged out of a row (a thumbnail).
|
||||
#[non_exhaustive]
|
||||
Frame {
|
||||
/// The size of the frame, in points.
|
||||
|
||||
@@ -262,7 +262,7 @@ pub fn float_drop<P: Clone + PartialEq>(
|
||||
DragUnit::Panel(panel) if edge.is_none() => Action::float(panel.clone(), rect),
|
||||
_ => to_target(unit, Target::float_with_edge(rect, edge)),
|
||||
};
|
||||
DockDropped { action, mark: DropMark::Into(mark) }
|
||||
DockDropped { action, mark: DropMark::region(mark) }
|
||||
}
|
||||
|
||||
/// The action a release of `drag` at `at` makes in the dock `dock`, by the spots of the previous pass; `None` where
|
||||
@@ -439,31 +439,28 @@ pub(crate) fn started(env: &EnvView<'_>) -> Option<Arrangement> {
|
||||
}
|
||||
|
||||
/// Starts the drag of `unit`, whose shown panel is `active` and whose size where it starts is `source`. A group or a
|
||||
/// column drags a ghost frame; `ghost` gives its size and label. A window moves itself, so its drag has no ghost and
|
||||
/// `ghost` is `None`.
|
||||
pub fn start_group_drag<P, C>(cx: &mut Cx<'_, C>, unit: DragUnit<P>, active: PanelKey, source: Option<Vec2>, ghost: Option<(Vec2, Label)>)
|
||||
/// column shows `name` inside the region its drop would take ([`DragPreview::Named`]). A window moves itself, so its
|
||||
/// drag shows nothing and `name` is `None`.
|
||||
pub fn start_group_drag<P, C>(cx: &mut Cx<'_, C>, unit: DragUnit<P>, active: PanelKey, source: Option<Vec2>, name: Option<Label>)
|
||||
where
|
||||
P: Clone + Send + Sync + 'static,
|
||||
C: Component,
|
||||
{
|
||||
let preview = match ghost {
|
||||
Some((size, label)) => DragPreview::frame(size, Some(label)),
|
||||
None => DragPreview::None,
|
||||
};
|
||||
let preview = name.map_or(DragPreview::None, DragPreview::Named);
|
||||
let started = started(&cx.env);
|
||||
cx.start_drag(GroupDrag { unit, active, source, strip: None, started }, preview);
|
||||
}
|
||||
|
||||
/// Starts the drag of `unit` out of a collapsed column, from its icons of size `strip`, whose shown panel is
|
||||
/// `active`: the ghost is a frame of that size with `label`, and a float of the unit lands collapsed with its strip
|
||||
/// under the pointer ([`float_drop`]).
|
||||
/// `active`: the region its drop would take shows `label`, and a float of the unit lands collapsed with its strip under
|
||||
/// the pointer ([`float_drop`]).
|
||||
pub fn start_icon_drag<P, C>(cx: &mut Cx<'_, C>, unit: DragUnit<P>, active: PanelKey, strip: Vec2, label: Label)
|
||||
where
|
||||
P: Clone + Send + Sync + 'static,
|
||||
C: Component,
|
||||
{
|
||||
let started = started(&cx.env);
|
||||
cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), started }, DragPreview::frame(strip, Some(label)));
|
||||
cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), started }, DragPreview::Named(label));
|
||||
}
|
||||
|
||||
/// Ends a running tab or group drag that started on `shown`'s dock under another revision: another arrangement
|
||||
|
||||
@@ -62,7 +62,7 @@ pub struct GroupGrip<P: Clone + Send + Sync + 'static> {
|
||||
common: Common,
|
||||
unit: DragUnit<P>,
|
||||
active: PanelKey,
|
||||
/// The ghost the drag shows: its extent and its label.
|
||||
/// The unit's extent where the drag starts and the name its drop region shows.
|
||||
#[prop]
|
||||
ghost: Option<(Vec2, Label)>,
|
||||
/// A drag on the grip drags the unit.
|
||||
@@ -109,7 +109,7 @@ impl<P: Clone + Send + Sync + 'static> Component for GroupGrip<P> {
|
||||
match self.ghost.clone() {
|
||||
Some((strip, label)) if self.icons => start_icon_drag(cx, self.unit.clone(), self.active, strip, label),
|
||||
// The ghost's extent is the group's own.
|
||||
ghost => start_group_drag(cx, self.unit.clone(), self.active, ghost.as_ref().map(|(size, _)| *size), ghost),
|
||||
ghost => start_group_drag(cx, self.unit.clone(), self.active, ghost.as_ref().map(|(size, _)| *size), ghost.map(|(_, label)| label)),
|
||||
}
|
||||
self.started = true;
|
||||
}
|
||||
@@ -260,7 +260,7 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> {
|
||||
/// The host's items before the tab strip.
|
||||
#[prop(func = "FnMut(&mut egui::Ui, &mut BodyCx<'_>)")]
|
||||
extra: Option<HeaderHook<'a>>,
|
||||
/// The size of the group this pass, for the drag ghost.
|
||||
/// The size of the group this pass, where its drag starts.
|
||||
size: Vec2,
|
||||
reported: Reported,
|
||||
}
|
||||
@@ -306,10 +306,9 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> {
|
||||
IconButton::new(IconId::new("more")).size(ControlSize::Sm).popup(PopupKind::Menu).label(name)
|
||||
}
|
||||
|
||||
/// Starts a drag of the whole group: its ghost is the group's frame with its name.
|
||||
/// Starts a drag of the whole group: its drop region shows the group's name.
|
||||
fn start_drag(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
let ghost = (self.size, cx.label());
|
||||
start_group_drag(cx, DragUnit::Group(self.anchor.clone()), self.active, Some(self.size), Some(ghost));
|
||||
start_group_drag(cx, DragUnit::Group(self.anchor.clone()), self.active, Some(self.size), Some(cx.label()));
|
||||
self.reported.drag_started = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user