Window Drag Area Builder

The Window Drag Builder is used to declare a view as a system window drag area. It is primarily used for borderless windows: when the user holds and drags this area, Flor calls the platform layer's drag_window(), letting the system take over window movement.

Basic Usage

After importing WindowDragBuilder, all views implementing ViewIdentity can call .window_drag_area():

use flor::view::builder::WindowDragBuilder;
use flor::views;
use flor::windows::WindowOption;
use flor_lys::div::div;
use flor_lys::label::label;

WindowOption {
    borderless: true,
    ..WindowOption::default()
}
.open(|_| {
    div(views![label("Drag here to move the window")])
        .window_drag_area()
})?;

.window_drag_area() is equivalent to setting the current view's drag policy to WindowDragPolicy::Allow.

Dynamic Policy

If the drag capability needs to change with state, use .window_drag_policy(...):

use flor::view::builder::WindowDragBuilder;
use flor::view::WindowDragPolicy;

let title_bar = title_bar.window_drag_policy(move || {
    if dragging_enabled.get() {
        WindowDragPolicy::Allow
    } else {
        WindowDragPolicy::Deny
    }
});

The policy closure is re-evaluated by the reactive updater, and the result is written to runtime storage.

Policy Meanings

PolicyMeaning
WindowDragPolicy::AllowThe current view allows triggering system window drag.
WindowDragPolicy::DenyThe current view prohibits triggering system window drag.
WindowDragPolicy::InheritThe current view makes no decision; continue looking up to the parent view for the policy.

The default policy is Deny. The view found by hit testing starts from itself and looks up to ancestors for the policy; encountering Deny stops and prohibits dragging, encountering Allow calls the view's on_window_drag_hit_test(...) for final judgment.

Relationship with Events

Window dragging only takes effect when there is no mouse capture. After left button down, if the hit view allows dragging, Flor directly triggers the system drag and returns, no longer dispatching this press event to the view.

If only part of a view's area is draggable, the view author can override View::on_window_drag_hit_test(mouse_position). The passed coordinates are in the current view's local coordinates; the default returns true.

If a view needs to express its own drag policy by default, it can override View::on_window_drag_policy(); the policy set by the application side through the Builder has higher priority.