Implemented support for dynamic `SELECTION_TOOLBAR_ANCHOR_VAR`.
Changed selection toolbar properties to be intrinsic to the `Text!` widget and descendants.
This commit is contained in:
parent
e0336fd31f
commit
82385aa4ad
|
@ -10,6 +10,7 @@
|
|||
- Needs to open when a selection finishes creating (mouse/touch release)
|
||||
- And close with any interaction that closes POPUP + any mouse/touch/keyboard interaction with the Text widget.
|
||||
- Test touch.
|
||||
- If the toolbar is not focusable it does not close when changing focus to another app?
|
||||
- Have the selection_toolbar_fn args indicate what kind of event created the selection.
|
||||
- This way we can have the default only open for touch events, and users can have different toolbars
|
||||
without we needing to declare multiple properties.
|
||||
|
|
|
@ -108,8 +108,9 @@ pub struct Text(
|
|||
LangMix<
|
||||
FontFeaturesMix<
|
||||
TextEditMix<
|
||||
SelectionToolbarMix<
|
||||
WidgetBase
|
||||
>>>>>>>>>>
|
||||
>>>>>>>>>>>
|
||||
);
|
||||
|
||||
impl Text {
|
||||
|
@ -124,6 +125,7 @@ impl Text {
|
|||
TextTransformMix::<()>::context_vars_set(set);
|
||||
FontFeaturesMix::<()>::context_vars_set(set);
|
||||
TextEditMix::<()>::context_vars_set(set);
|
||||
SelectionToolbarMix::<()>::context_vars_set(set);
|
||||
|
||||
LangMix::<()>::context_vars_set(set);
|
||||
}
|
||||
|
|
|
@ -3712,7 +3712,7 @@ pub fn selection_toolbar_node(child: impl UiNode) -> impl UiNode {
|
|||
let node = match_widget(node, move |c, op| match op {
|
||||
UiNodeOp::Init => {
|
||||
c.init();
|
||||
// c.with_context(|| );// SELECTION_TOOLBAR_ANCHOR_VAR subscribe TODO
|
||||
c.with_context(WidgetUpdateMode::Bubble, || WIDGET.sub_var_layout(&SELECTION_TOOLBAR_ANCHOR_VAR));
|
||||
}
|
||||
UiNodeOp::Layout { wl, final_size } => {
|
||||
let r_txt = ResolvedText::get();
|
||||
|
@ -3773,6 +3773,7 @@ pub fn selection_toolbar_node(child: impl UiNode) -> impl UiNode {
|
|||
let mut allow = ContextValueSet::new();
|
||||
super::LangMix::<()>::context_vars_set(&mut allow);
|
||||
exclude.remove_all(&allow);
|
||||
exclude.remove(&SELECTION_TOOLBAR_ANCHOR_VAR);
|
||||
|
||||
exclude
|
||||
}),
|
||||
|
|
|
@ -1743,10 +1743,29 @@ pub fn txt_highlight(child: impl UiNode, range: impl IntoVar<std::ops::Range<Car
|
|||
})
|
||||
}
|
||||
|
||||
/// Selection toolbar properties.
|
||||
#[widget_mixin]
|
||||
pub struct SelectionToolbarMix<P>(P);
|
||||
|
||||
context_var! {
|
||||
/// Selection toolbar function.
|
||||
pub static SELECTION_TOOLBAR_FN_VAR: WidgetFn<SelectionToolbarArgs> = WidgetFn::nil();
|
||||
/// Position the selection toolbar in relation to the bounding box of all selection rectangles.
|
||||
pub static SELECTION_TOOLBAR_ANCHOR_VAR: AnchorOffset = AnchorOffset::out_top();
|
||||
}
|
||||
|
||||
impl SelectionToolbarMix<()> {
|
||||
/// Insert context variables used by properties in this mix-in.
|
||||
pub fn context_vars_set(set: &mut ContextValueSet) {
|
||||
set.insert(&SELECTION_TOOLBAR_FN_VAR);
|
||||
set.insert(&SELECTION_TOOLBAR_ANCHOR_VAR);
|
||||
}
|
||||
}
|
||||
|
||||
/// Defines the floating mini-toolbar that shows near a new text selection.
|
||||
///
|
||||
/// The `toolbar` is used
|
||||
#[property(CONTEXT)]
|
||||
#[property(CONTEXT, widget_impl(SelectionToolbarMix<P>))]
|
||||
pub fn selection_toolbar(child: impl UiNode, toolbar: impl UiNode) -> impl UiNode {
|
||||
selection_toolbar_fn(child, WidgetFn::singleton(toolbar))
|
||||
}
|
||||
|
@ -1754,7 +1773,7 @@ pub fn selection_toolbar(child: impl UiNode, toolbar: impl UiNode) -> impl UiNod
|
|||
/// Defines the floating mini-toolbar that shows near a new text selection.
|
||||
///
|
||||
/// Sets the [`SELECTION_TOOLBAR_FN_VAR`].
|
||||
#[property(CONTEXT, default(SELECTION_TOOLBAR_FN_VAR))]
|
||||
#[property(CONTEXT, default(SELECTION_TOOLBAR_FN_VAR), widget_impl(SelectionToolbarMix<P>))]
|
||||
pub fn selection_toolbar_fn(child: impl UiNode, toolbar: impl IntoVar<WidgetFn<SelectionToolbarArgs>>) -> impl UiNode {
|
||||
with_context_var(child, SELECTION_TOOLBAR_FN_VAR, toolbar)
|
||||
}
|
||||
|
@ -1772,14 +1791,7 @@ pub struct SelectionToolbarArgs {
|
|||
/// See [`selection_toolbar_fn`](fn@selection_toolbar_fn).
|
||||
///
|
||||
/// Sets the [`SELECTION_TOOLBAR_ANCHOR_VAR`].
|
||||
#[property(CONTEXT, default(SELECTION_TOOLBAR_ANCHOR_VAR))]
|
||||
#[property(CONTEXT, default(SELECTION_TOOLBAR_ANCHOR_VAR), widget_impl(SelectionToolbarMix<P>))]
|
||||
pub fn selection_toolbar_anchor(child: impl UiNode, offset: impl IntoVar<AnchorOffset>) -> impl UiNode {
|
||||
with_context_var(child, SELECTION_TOOLBAR_ANCHOR_VAR, offset)
|
||||
}
|
||||
|
||||
context_var! {
|
||||
/// Selection toolbar function.
|
||||
pub static SELECTION_TOOLBAR_FN_VAR: WidgetFn<SelectionToolbarArgs> = WidgetFn::nil();
|
||||
/// Position the selection toolbar in relation to the bounding box of all selection rectangles.
|
||||
pub static SELECTION_TOOLBAR_ANCHOR_VAR: AnchorOffset = AnchorOffset::out_top();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue