forked from 1b-agent/opencadstudio-upstream
Ribbon key tips: Alt shows codes on tabs, buttons and menu items
A lone Alt shows a code on every ribbon tab and quick-access button. Typing a tab code opens the tab and shows the codes of its buttons, dropdowns, slide-outs and collapsed panels; a button code runs it, a dropdown or slide-out code opens it and shows its item codes, Esc goes back one level. Codes follow the reference ribbon; buttons without a reference counterpart get none and unnamed menu items are numbered. Codes are drawn as accent pills over the widgets that reported their bounds in the current frame, with a hint bar under the ribbon. While the tips are open keys go to them only. The automation gets a keytips action and read operation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
592289f4fd
commit
86429bf439
34 files changed
+1569
-53
No files matched your search
+49
-15
@@ -9,7 +9,7 @@ use super::widgets::{
|
||||
make_icon, make_tip, muted_text_style, popup_panel_style, popup_row_style, tip_style,
|
||||
tool_btn_style, LARGE_DROPDOWN_ARROW_SIZE,
|
||||
};
|
||||
use super::{dropdown_backdrop, position_ribbon_dropdown, Ribbon};
|
||||
use super::{dropdown_backdrop, keytips, position_ribbon_dropdown, Ribbon};
|
||||
use crate::app::Message;
|
||||
use crate::modules::IconKind;
|
||||
use crate::t;
|
||||
@@ -248,6 +248,32 @@ fn panel_for_group(title: &str, group_ids: &[&'static str]) -> Option<Panel> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The slide-out under the group `title`, if it has one.
|
||||
pub(super) fn slide_out_id(title: &str, group_ids: &[&'static str]) -> Option<&'static str> {
|
||||
panel_for_group(title, group_ids).map(|panel| panel.id)
|
||||
}
|
||||
|
||||
/// What the open slide-out or tool submenu `id` offers, as (dropdown id,
|
||||
/// command, opens a submenu) in display order.
|
||||
pub(super) fn keytip_items(id: &str) -> Vec<(&'static str, &'static str, bool)> {
|
||||
let Some(panel) = panel_for_dropdown(id) else {
|
||||
return Vec::new();
|
||||
};
|
||||
if panel.id == id {
|
||||
return panel
|
||||
.tools
|
||||
.iter()
|
||||
.map(|tool| (panel.id, tool.command, !tool.options.is_empty()))
|
||||
.collect();
|
||||
}
|
||||
panel
|
||||
.tools
|
||||
.iter()
|
||||
.filter(|tool| tool.command == id)
|
||||
.flat_map(|tool| tool.options.iter().map(|(cmd, _)| (tool.command, *cmd, false)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Every command the slide-out of the group `title` offers: each tool and
|
||||
/// each of its submenu options.
|
||||
pub(super) fn slide_out_commands(
|
||||
@@ -337,6 +363,7 @@ pub(super) fn group_title<'a>(
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style);
|
||||
// Shrink-sized: a Fill here would make the panel claim the whole row.
|
||||
let launcher = keytips::anchor(keytips::XREF_LAUNCHER, launcher);
|
||||
row![title_button, launcher]
|
||||
.spacing(6)
|
||||
.align_y(iced::Center)
|
||||
@@ -362,6 +389,7 @@ fn tool_button(tool: &Tool, active: bool, panel_id: &'static str) -> Element<'st
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style)
|
||||
.into();
|
||||
let face = keytips::anchor_with(|| keytips::item_anchor(panel_id, tool.command), face);
|
||||
if !tool.options.is_empty() {
|
||||
row![
|
||||
face,
|
||||
@@ -401,6 +429,7 @@ fn reference_overlay<'a>(ribbon: &Ribbon, panel: Panel, win: (f32, f32)) -> Elem
|
||||
.style(popup_row_style)
|
||||
.width(Fill)
|
||||
.padding([3, 6]);
|
||||
let edit = keytips::anchor_with(|| keytips::item_anchor(panel.id, tool.command), edit);
|
||||
let fade = ribbon.xref_fade;
|
||||
let on = fade > 0;
|
||||
let switch = button(make_icon(
|
||||
@@ -411,18 +440,23 @@ fn reference_overlay<'a>(ribbon: &Ribbon, panel: Panel, win: (f32, f32)) -> Elem
|
||||
.style(move |theme: &Theme, status| tool_btn_style(theme, on, status))
|
||||
.padding(3);
|
||||
let amount = fade.unsigned_abs().min(90) as u8;
|
||||
let switch = tooltip(
|
||||
switch,
|
||||
make_tip(format!(
|
||||
"{}\n{} XDWGFADECTL",
|
||||
t!("Xref fading"),
|
||||
t!("Command:")
|
||||
)),
|
||||
tooltip::Position::Bottom,
|
||||
)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style);
|
||||
let switch = keytips::anchor_with(
|
||||
|| keytips::item_anchor(panel.id, keytips::XREF_FADE),
|
||||
switch,
|
||||
);
|
||||
let fading = row![
|
||||
tooltip(
|
||||
switch,
|
||||
make_tip(format!(
|
||||
"{}\n{} XDWGFADECTL",
|
||||
t!("Xref fading"),
|
||||
t!("Command:")
|
||||
)),
|
||||
tooltip::Position::Bottom
|
||||
)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style),
|
||||
switch,
|
||||
text(t!("Xref fading")).size(11),
|
||||
iced::widget::slider(0..=90u8, amount, Message::XrefFadeSlide)
|
||||
.on_release(Message::XrefFadeCommit)
|
||||
@@ -468,7 +502,7 @@ pub(super) fn overlay<'a>(ribbon: &Ribbon, id: &str, win: (f32, f32)) -> Element
|
||||
tool.options
|
||||
.iter()
|
||||
.map(|&(cmd, label)| {
|
||||
button(text(t!(label)).size(11))
|
||||
let item = button(text(t!(label)).size(11))
|
||||
.on_press(Message::DropdownSelectItem {
|
||||
dropdown_id: tool.command,
|
||||
cmd,
|
||||
@@ -476,8 +510,8 @@ pub(super) fn overlay<'a>(ribbon: &Ribbon, id: &str, win: (f32, f32)) -> Element
|
||||
.style(popup_row_style)
|
||||
.width(Fill)
|
||||
.height(OPTION_HEIGHT)
|
||||
.padding([3, 7])
|
||||
.into()
|
||||
.padding([3, 7]);
|
||||
keytips::anchor_with(|| keytips::item_anchor(tool.command, cmd), item)
|
||||
})
|
||||
.collect::<Vec<Element<'static, Message>>>(),
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+22
-7
@@ -31,6 +31,12 @@ use widgets::{StyleContext, *};
|
||||
pub(crate) use widgets::{REDO_HISTORY_ID, UNDO_HISTORY_ID};
|
||||
mod collapse;
|
||||
mod locate;
|
||||
mod keytips;
|
||||
pub use keytips::{
|
||||
active as keytips_active, key_pressed as keytip_key_pressed,
|
||||
key_released as keytip_key_released, pointer_pressed as keytip_pointer_pressed, KeyTipInput,
|
||||
KeyTipStep,
|
||||
};
|
||||
use crate::t;
|
||||
use crate::ui::wrap_bar::{PosReport, WrapBar, WrapFlow};
|
||||
pub use collapse::CollapseMode;
|
||||
@@ -122,6 +128,8 @@ pub struct Ribbon {
|
||||
block_editing: Option<usize>,
|
||||
/// XDWGFADECTL as the Reference slide-out shows it (negative = off).
|
||||
pub xref_fade: i32,
|
||||
/// Open key tips (Alt).
|
||||
keytips: Option<keytips::State>,
|
||||
}
|
||||
|
||||
/// Per-layer display data shown in the ribbon layer dropdown.
|
||||
@@ -224,6 +232,7 @@ impl Ribbon {
|
||||
point_cloud_ctx: None,
|
||||
block_editing: None,
|
||||
xref_fade: 50,
|
||||
keytips: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,7 +671,7 @@ impl Ribbon {
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
acc.push(btn.into());
|
||||
acc.push(keytips::anchor_with(|| format!("tab:{}", module.id()), btn));
|
||||
acc
|
||||
},
|
||||
);
|
||||
@@ -800,7 +809,7 @@ impl Ribbon {
|
||||
tool_bar
|
||||
};
|
||||
|
||||
column![tab_bar, tool_bar].into()
|
||||
keytips::ribbon_area(column![tab_bar, tool_bar])
|
||||
}
|
||||
|
||||
// ── Dropdown overlay ──────────────────────────────────────────────────
|
||||
@@ -971,7 +980,7 @@ impl Ribbon {
|
||||
.then_some(theme.palette().background.base.text.scale_alpha(0.72)),
|
||||
});
|
||||
|
||||
button(
|
||||
let item = button(
|
||||
row![checkmark, icon_el, label_el]
|
||||
.spacing(4)
|
||||
.align_y(iced::Center),
|
||||
@@ -982,8 +991,8 @@ impl Ribbon {
|
||||
}))
|
||||
.style(popup_row_style)
|
||||
.width(Fill)
|
||||
.padding([4, 10])
|
||||
.into()
|
||||
.padding([4, 10]);
|
||||
keytips::anchor_with(|| keytips::item_anchor(dd_id, cmd), item)
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -1571,7 +1580,10 @@ fn collapse_button<'a>(
|
||||
.style(opener_style(holds))
|
||||
.width(Fill)
|
||||
.padding([3, 5]);
|
||||
return automatic_large_button(localized_title, content.into());
|
||||
return keytips::anchor_with(
|
||||
|| keytips::collapsed_anchor(title),
|
||||
automatic_large_button(localized_title, content.into()),
|
||||
);
|
||||
}
|
||||
|
||||
// Collapsed (not yet tight): a large representative-tool face — a live button
|
||||
@@ -1636,7 +1648,10 @@ fn collapse_button<'a>(
|
||||
.style(opener_style(holds && !face_lit))
|
||||
.width(Fill)
|
||||
.padding([1, 4]);
|
||||
let opener = automatic_large_button(localized_title, opener.into());
|
||||
let opener = keytips::anchor_with(
|
||||
|| keytips::collapsed_anchor(title),
|
||||
automatic_large_button(localized_title, opener.into()),
|
||||
);
|
||||
|
||||
// The large face fills a fixed slot so a collapsed panel is shorter than a full
|
||||
// 3-row panel, letting `CollapsePanels` shrink the ribbon row.
|
||||
|
||||
+34
-26
@@ -543,11 +543,13 @@ pub(super) fn render_small<'a>(
|
||||
.width(Length::Fixed(SMALL_W))
|
||||
.height(ROW_H)
|
||||
.padding([4, 4]);
|
||||
tooltip(btn, make_tip(tip_text), TipPos::Right)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style)
|
||||
.into()
|
||||
super::keytips::anchor(
|
||||
t.id,
|
||||
tooltip(btn, make_tip(tip_text), TipPos::Right)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style),
|
||||
)
|
||||
}
|
||||
|
||||
RibbonItem::LabeledTool(t) => {
|
||||
@@ -568,11 +570,13 @@ pub(super) fn render_small<'a>(
|
||||
.width(Length::Fixed(LABELED_SMALL_W + ARROW_W))
|
||||
.height(ROW_H)
|
||||
.padding([3, 4]);
|
||||
tooltip(btn, make_tip(tip_text), TipPos::Right)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style)
|
||||
.into()
|
||||
super::keytips::anchor(
|
||||
t.id,
|
||||
tooltip(btn, make_tip(tip_text), TipPos::Right)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style),
|
||||
)
|
||||
}
|
||||
|
||||
RibbonItem::Dropdown {
|
||||
@@ -895,7 +899,7 @@ fn tool_row<'a>(tools: &[ToolDef], active_tool: &Option<String>) -> Element<'a,
|
||||
let event = t.event.clone();
|
||||
let icon_el: Element<Message> = make_icon(t.icon, 16.0);
|
||||
let msg = module_event_to_message(event);
|
||||
tooltip(
|
||||
let btn = tooltip(
|
||||
button(icon_el)
|
||||
.on_press(msg)
|
||||
.style(move |theme: &Theme, status| tool_btn_style(theme, is_active, status))
|
||||
@@ -905,8 +909,8 @@ fn tool_row<'a>(tools: &[ToolDef], active_tool: &Option<String>) -> Element<'a,
|
||||
)
|
||||
.gap(4.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style)
|
||||
.into()
|
||||
.style(tip_style);
|
||||
super::keytips::anchor(t.id, btn)
|
||||
})
|
||||
.collect();
|
||||
row(btns).spacing(2).align_y(iced::Center).into()
|
||||
@@ -974,15 +978,17 @@ pub(super) fn render_large<'a>(item: &RibbonItem, ctx: &RenderCtx<'_>) -> Elemen
|
||||
bottom: 4.0,
|
||||
left: 4.0,
|
||||
});
|
||||
tooltip(
|
||||
automatic_large_button(label, btn.into()),
|
||||
make_tip(tip_text),
|
||||
TipPos::Right,
|
||||
super::keytips::anchor(
|
||||
t.id,
|
||||
tooltip(
|
||||
automatic_large_button(label, btn.into()),
|
||||
make_tip(tip_text),
|
||||
TipPos::Right,
|
||||
)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style),
|
||||
)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style)
|
||||
.into()
|
||||
}
|
||||
|
||||
RibbonItem::LargeDropdown {
|
||||
@@ -1308,11 +1314,13 @@ pub(super) fn quick_access_btn<'a>(
|
||||
.width(Length::Fixed(TOP_HIST_W))
|
||||
.height(24)
|
||||
.padding([2, 0]);
|
||||
tooltip(btn, make_tip(t!(label).into_owned()), TipPos::Bottom)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style)
|
||||
.into()
|
||||
super::keytips::anchor_with(
|
||||
|| super::keytips::quick_access_anchor(cmd),
|
||||
tooltip(btn, make_tip(t!(label).into_owned()), TipPos::Bottom)
|
||||
.gap(6.0)
|
||||
.delay(Duration::from_millis(400))
|
||||
.style(tip_style),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn render_history_control<'a>(
|
||||
|
||||
+37
-4
@@ -34,14 +34,46 @@ use crate::app::Message;
|
||||
thread_local! {
|
||||
/// Screen bounds of every ribbon dropdown button, keyed by dropdown id, so
|
||||
/// an open dropdown's overlay can anchor directly below its widget at any
|
||||
/// size. Written by `PosReport` on draw, read by `dropdown_bounds`.
|
||||
static DD_BOUNDS: RefCell<FxHashMap<String, Rectangle>> =
|
||||
/// size. Written by `PosReport` on draw, read by `dropdown_bounds`. Each
|
||||
/// entry keeps the frame it was drawn in (see `fresh_bounds`).
|
||||
static DD_BOUNDS: RefCell<FxHashMap<String, (Rectangle, u64)>> =
|
||||
RefCell::new(FxHashMap::default());
|
||||
/// Advanced by `end_frame` once everything above the widgets has drawn.
|
||||
static FRAME: Cell<u64> = const { Cell::new(0) };
|
||||
}
|
||||
|
||||
/// Last-drawn screen bounds of the dropdown button with this id.
|
||||
pub fn dropdown_bounds(id: &str) -> Option<Rectangle> {
|
||||
DD_BOUNDS.with(|m| m.borrow().get(id).copied())
|
||||
DD_BOUNDS.with(|m| m.borrow().get(id).map(|(bounds, _)| *bounds))
|
||||
}
|
||||
|
||||
/// Bounds of the widget `id` only when it was drawn in the current frame, so
|
||||
/// a widget that left the screen does not report its old place.
|
||||
pub fn fresh_bounds(id: &str) -> Option<Rectangle> {
|
||||
let frame = FRAME.with(Cell::get);
|
||||
DD_BOUNDS.with(|m| {
|
||||
m.borrow()
|
||||
.get(id)
|
||||
.filter(|(_, drawn)| *drawn == frame)
|
||||
.map(|(bounds, _)| *bounds)
|
||||
})
|
||||
}
|
||||
|
||||
/// Bounds of the widget `id` when it was drawn in the current or the last
|
||||
/// finished frame (for use between frames).
|
||||
pub fn recent_bounds(id: &str) -> Option<Rectangle> {
|
||||
let frame = FRAME.with(Cell::get);
|
||||
DD_BOUNDS.with(|m| {
|
||||
m.borrow()
|
||||
.get(id)
|
||||
.filter(|(_, drawn)| drawn + 1 >= frame)
|
||||
.map(|(bounds, _)| *bounds)
|
||||
})
|
||||
}
|
||||
|
||||
/// Close the current frame for `fresh_bounds`.
|
||||
pub fn end_frame() {
|
||||
FRAME.with(|frame| frame.set(frame.get() + 1));
|
||||
}
|
||||
|
||||
pub struct WrapBar<'a> {
|
||||
@@ -1038,7 +1070,8 @@ impl<'a> Widget<Message, Theme, Renderer> for PosReport<'a> {
|
||||
viewport: &Rectangle,
|
||||
) {
|
||||
DD_BOUNDS.with(|m| {
|
||||
m.borrow_mut().insert(self.id.to_string(), layout.bounds());
|
||||
m.borrow_mut()
|
||||
.insert(self.id.to_string(), (layout.bounds(), FRAME.with(Cell::get)));
|
||||
});
|
||||
self.child.as_widget().draw(
|
||||
&tree.children[0],
|
||||
|
||||
Reference in new issue
Block a user