pub struct Help { /* private fields */ }Expand description
Help widget that renders keybinding entries.
In HelpMode::Short mode, entries are shown inline separated by a bullet
character, truncated with an ellipsis if they exceed the available width.
In HelpMode::Full mode, entries are rendered in a vertical list with
keys and descriptions in aligned columns.
Implementations§
Source§impl Help
impl Help
Sourcepub fn from_keymap<A>(map: &KeyMap<A>, active: &[ContextId]) -> Self
pub fn from_keymap<A>(map: &KeyMap<A>, active: &[ContextId]) -> Self
Build a help bar from a KeyMap: one entry per labelled binding
that wins under active contexts (shadowed bindings are left out),
with the chord’s display text as the key and the label as the
description. Unlabelled bindings have nothing to say and are skipped.
Entries keep bind order; attach a ranker with
Help::register_with_ranker and feed dispatched chords back through
Help::record_used with chord.to_string() to reorder by use.
Sourcepub fn register_with_ranker(
&mut self,
ranker: &mut HintRanker,
context: HintContext,
) -> Vec<usize>
pub fn register_with_ranker( &mut self, ranker: &mut HintRanker, context: HintContext, ) -> Vec<usize>
Register every entry with a HintRanker so the widget can be
reordered by learned utility (see Help::apply_ranking).
Each entry becomes one ranker hint whose display cost is the width of
"key desc" in columns; the returned ids are in entry order, so callers
can feed usage back with HintRanker::record_usage when a shortcut is
pressed. Call this once after the entries are final; adding entries
afterwards requires registering again.
Sourcepub fn hint_id(&self, index: usize) -> Option<usize>
pub fn hint_id(&self, index: usize) -> Option<usize>
Hint id of the entry at index, once registered with a ranker.
Sourcepub fn apply_ranking(
&mut self,
ranker: &mut HintRanker,
context_key: Option<&str>,
) -> Vec<RankingEvidence>
pub fn apply_ranking( &mut self, ranker: &mut HintRanker, context_key: Option<&str>, ) -> Vec<RankingEvidence>
Reorder the entries by the ranker’s current utility ordering.
The ranker decides (expected utility, a value-of-information
exploration bonus, display cost, and a hysteresis margin that stops
near-ties from flickering); this method only applies the order. Entries
the ranker did not rank (for example filtered out by context_key)
keep their relative order after the ranked ones. Returns the ranker’s
evidence ledger so callers can log why the hints are ordered this way.
Does nothing if the entries were never registered or changed since.
Sourcepub fn record_used(&self, ranker: &mut HintRanker, key: &str) -> bool
pub fn record_used(&self, ranker: &mut HintRanker, key: &str) -> bool
Record that the shortcut labelled key was pressed.
Looks the entry up by its key label, records a use for its hint and
returns true when the key belongs to a registered entry. Call it
from update() when a bound key fires; the next
Help::apply_ranking moves frequently used shortcuts forward.
Sourcepub fn record_shown(&self, ranker: &mut HintRanker, except_key: Option<&str>)
pub fn record_shown(&self, ranker: &mut HintRanker, except_key: Option<&str>)
Record that the entries were displayed without being used.
Call once per interaction round for every registered entry except the
one that was used (except_key); the ranker treats it as negative
evidence, so hints nobody acts on drift to the end of the bar.
Sourcepub fn entry(self, key: impl Into<String>, desc: impl Into<String>) -> Self
pub fn entry(self, key: impl Into<String>, desc: impl Into<String>) -> Self
Add an entry to the help widget.
Sourcepub fn with_entry(self, entry: HelpEntry) -> Self
pub fn with_entry(self, entry: HelpEntry) -> Self
Add a pre-built entry.
Sourcepub fn with_entries(self, entries: Vec<HelpEntry>) -> Self
pub fn with_entries(self, entries: Vec<HelpEntry>) -> Self
Set all entries at once.
Sourcepub fn with_separator(self, sep: impl Into<String>) -> Self
pub fn with_separator(self, sep: impl Into<String>) -> Self
Set the separator used between entries in short mode.
Sourcepub fn with_ellipsis(self, ellipsis: impl Into<String>) -> Self
pub fn with_ellipsis(self, ellipsis: impl Into<String>) -> Self
Set the ellipsis string.
Sourcepub fn with_key_style(self, style: Style) -> Self
pub fn with_key_style(self, style: Style) -> Self
Set the style for key text.
Sourcepub fn with_desc_style(self, style: Style) -> Self
pub fn with_desc_style(self, style: Style) -> Self
Set the style for description text.
Sourcepub fn with_separator_style(self, style: Style) -> Self
pub fn with_separator_style(self, style: Style) -> Self
Set the style for separators and ellipsis.
Sourcepub fn toggle_mode(&mut self)
pub fn toggle_mode(&mut self)
Toggle between short and full mode.
Sourcepub fn push_entry(&mut self, entry: HelpEntry)
pub fn push_entry(&mut self, entry: HelpEntry)
Add an entry mutably.