pub struct HistoryViewer { /* private fields */ }Expand description
A read-only single-column list over the global history store, shown in a modal recall popup when a user drops down an input field.
Process-global, byte-budget-bounded history store for input fields, plus the
HistoryViewer widget that shows the store in a modal recall list.
Each “channel” is a small u8 id that groups one input field’s recall
list. Entries are stored oldest-first globally; history_str(id, 0)
returns the oldest surviving entry for that id.
§The clean read contract — every non-evicted entry is readable
The store keeps a flat list of entries and a byte budget; once adding an entry would exceed the budget, the globally-oldest entries are evicted until it fits. Every entry that has not been evicted is readable — there is no hidden front record and no skipped-oldest entry.
This is a deliberate simplification of the original store, which carried a hidden front sentinel record and skipped it (and, after the first eviction, the real oldest entry) when reading. Pre-overflow behavior is identical; the only difference is that we keep that one globally-oldest entry visible, and our first-eviction byte boundary is 3 bytes looser because we do not spend budget on a sentinel. The deviation is intentional and noted here so it is not mistaken for a missing behavior.
Enter / double-click confirms; Esc or a cancel command dismisses. All other
events fall through to the base ListViewer navigation.
§history_id type
The channel id is a u8. The store keys on a single byte, so using u8
throughout makes the width explicit and avoids a silent truncation bug at the
call boundary.
§Setup after insertion
Call setup after inserting the viewer into a group:
it needs a Context to publish the list range, default focus, and horizontal
scrollbar range, none of which are available before insertion.
§Palette / theme
The history list recolors the gray-dialog list matrix into the blue
input-field look, surfaced through the ListViewer::list_roles override:
Role::HistoryViewerNormal
(white on blue) and
Role::HistoryViewerFocused
(white on green).
§Turbo Vision heritage
Ports the history store (histlist.cpp) plus THistoryViewer
(thstview.cpp), THistoryWindow (thistwin.cpp), and the THistory
dropdown icon (thistory.cpp). The store drops the original front-sentinel
byte-block bookkeeping in favor of the clean read contract above.
Implementations§
Source§impl HistoryViewer
impl HistoryViewer
Sourcepub const LIST_ROLES: ListRoles
pub const LIST_ROLES: ListRoles
The six-slot color sextet for the history recall list.
Maps all six list-viewer color slots to two history-specific roles:
normal rows (active, inactive, surface, selected, and the divider) use
Role::HistoryViewerNormal
(white on blue), and the focused row uses
Role::HistoryViewerFocused
(white on green). This gives the recall list its blue-on-green highlight
distinct from the gray dialog palette used by plain list boxes. The
history family draws no distinction between normal/inactive/surface
to begin with, so the three-surface rule collapses to the same behavior
this widget already had.
Returned by list_roles and consulted by the base
ListViewer painter. Lives on HistoryViewer (not in list_viewer.rs)
so that the base module has no dependency on history-specific roles.
Sourcepub fn new(
bounds: Rect,
h: Option<ViewId>,
v: Option<ViewId>,
history_id: u8,
) -> Self
pub fn new( bounds: Rect, h: Option<ViewId>, v: Option<ViewId>, history_id: u8, ) -> Self
Construct a HistoryViewer over bounds, wired to optional horizontal
scrollbar h and vertical scrollbar v, displaying channel history_id.
This is the data-init portion only — no Context is available yet.
After inserting the viewer into its group, call setup
to publish the list range, default focus, and horizontal scrollbar range.
Omitting setup leaves the viewer with range == 0 and nothing visible.
In practice you do not construct this directly; HistoryWindow::new
builds and inserts the viewer for you.
Sourcepub fn setup(&mut self, ctx: &mut Context<'_>)
pub fn setup(&mut self, ctx: &mut Context<'_>)
Context-needing tail of construction — call once after insertion into a group, before the first event.
HistoryWindow::handle_event calls this automatically on the first
event; you only need to call it directly when driving a HistoryViewer
standalone (e.g., in tests).
- Sets the list range to the channel’s entry count via
history_count. - If more than one entry exists, focuses item 1 (the second-oldest) so the most-recent non-duplicate entry is highlighted by default.
- If a horizontal scrollbar is wired, publishes its range as
0 ..= history_width() - size.x + 3. A negative max is safe —ScrollBar::set_paramsfloors it to the minimum.
Trait Implementations§
Source§impl ListViewer for HistoryViewer
impl ListViewer for HistoryViewer
Source§fn get_text(&self, item: i32) -> String
fn get_text(&self, item: i32) -> String
Return the display string for list row item (the text the user sees in
the recall list).
Fetches entry item (oldest-first) from the history channel via
history_str. Negative or out-of-range indices return an empty
string rather than panicking, so the base ListViewer paint loop
can call this unconditionally for any row.
Source§fn list_roles(&self) -> ListRoles
fn list_roles(&self) -> ListRoles
The history viewer’s recolored sextet (HistoryViewer::LIST_ROLES).
Source§fn lv(&self) -> &ListViewerState
fn lv(&self) -> &ListViewerState
ListViewerState.Source§fn lv_mut(&mut self) -> &mut ListViewerState
fn lv_mut(&mut self) -> &mut ListViewerState
ListViewerState.Source§fn is_selected(&self, item: i32) -> bool
fn is_selected(&self, item: i32) -> bool
item should be drawn in the selected color. Read moreSource§fn item_role(&self, _item: i32) -> Option<Role>
fn item_role(&self, _item: i32) -> Option<Role>
Role for a normal row — one that is neither
the focused cursor item nor selected. Only the role’s foreground is
used: the row keeps the list’s surface background, so a tinted row
still reads as part of the list. None (the default) keeps the plain
surface colour. A table uses it to tint a whole row (a dimmed or an
error row); the focused and selected colours always win over it.Source§fn select_item(&mut self, _item: i32, ctx: &mut Context<'_>)
fn select_item(&mut self, _item: i32, ctx: &mut Context<'_>)
item (double-click, Space, or Enter). Read moreSource§fn on_focus_changed(&mut self, _ctx: &mut Context<'_>)
fn on_focus_changed(&mut self, _ctx: &mut Context<'_>)
focus_item free fn
calls this after moving focused (and adjusting top_item), so an
override fires on EVERY focus change (keyboard, mouse, scrollbar sync, …).
Default: no-op. A file list overrides it to broadcast that the focused
file changed.Source§fn find_query(&self) -> Option<&str>
fn find_query(&self) -> Option<&str>
None when find mode is Off or
the query is empty. The shared draw reads this to highlight matches;
hosts read it to mirror the query elsewhere.Source§fn set_find_query(&mut self, query: &str, ctx: &mut Context<'_>)
fn set_find_query(&mut self, query: &str, ctx: &mut Context<'_>)
InputLine that
owns the text and drives an unfocused list’s incremental find (a combobox).
The mirror image of typed find, minus the keystrokes: a whole-string setter
because a text source always holds the complete string. Read moreSource§fn clear_find(&mut self, ctx: &mut Context<'_>)
fn clear_find(&mut self, ctx: &mut Context<'_>)
set_find_query("", ctx): no-op when find is Off or already empty,
else fires Command::LIST_FIND_CHANGED and runs Self::on_query_changed.Source§fn on_query_changed(&mut self, _ctx: &mut Context<'_>)
fn on_query_changed(&mut self, _ctx: &mut Context<'_>)
handle_event and by Self::set_find_query
(including Self::clear_find).Source§impl View for HistoryViewer
impl View for HistoryViewer
Source§fn handle_event(&mut self, ev: &mut Event, ctx: &mut Context<'_>)
fn handle_event(&mut self, ev: &mut Event, ctx: &mut Context<'_>)
Confirm or dismiss the modal recall list.
Enter / double-click → end the modal with Command::OK.
Esc / cancel command → end the modal with Command::CANCEL.
Everything else → the base list-viewer handler (nav, scrollbar sync…).
There is no modal-state gate: the viewer only ever lives inside a
HistoryWindow that is always run modally, so ending the modal is
unconditional.
Source§fn on_bounds_changed(&mut self, ctx: &mut Context<'_>)
fn on_bounds_changed(&mut self, ctx: &mut Context<'_>)
Republish the scroll-bar steps after a bounds change.
Source§fn draw(&mut self, ctx: &mut DrawCtx<'_>)
fn draw(&mut self, ctx: &mut DrawCtx<'_>)
ctx. Must be overridden. Read moreSource§fn set_state(&mut self, flag: StateFlag, enable: bool, ctx: &mut Context<'_>)
fn set_state(&mut self, flag: StateFlag, enable: bool, ctx: &mut Context<'_>)
StateFlag::Focused, emits the focus broadcast
(RECEIVED_FOCUS/RELEASED_FOCUS) via ctx. Read moreSource§fn cursor_request(&self) -> Option<Point>
fn cursor_request(&self) -> Option<Point>
None to
hide it. Base: Some(cursor) iff the view is focused with a visible cursor,
else None. Read moreSource§fn apply_scroll_sync(
&mut self,
h: Option<i32>,
v: Option<i32>,
ctx: &mut Context<'_>,
)
fn apply_scroll_sync( &mut self, h: Option<i32>, v: Option<i32>, ctx: &mut Context<'_>, )
None if that bar
is absent or unresolved), each read via View::value. Overridden by the
list viewers (delegate to
list_viewer::apply_scroll),
Scroller, the outline viewer, and the editor —
every sibling-scrollbar read sync routes through this one method instead of
a pump downcast. Read moreSource§fn as_any_mut(&mut self) -> Option<&mut dyn Any>
fn as_any_mut(&mut self) -> Option<&mut dyn Any>
None;
only views that must be reached concretely override it. (Any requires
'static, which every view is.)Source§fn valid(&mut self, _cmd: Command, _ctx: &mut Context<'_>) -> bool
fn valid(&mut self, _cmd: Command, _ctx: &mut Context<'_>) -> bool
cmd (e.g. a modal end / focus
release). Base is always true. Read moreSource§fn set_modal_answer(&mut self, _cmd: Command)
fn set_modal_answer(&mut self, _cmd: Command)
Context::request_message_box (the
answer_to/RouteModalAnswer round-trip). Default: no-op. Overridden by
views that drive a Yes/No/Cancel prompt out of valid (e.g.
FileEditor caches it for the re-validate).Source§fn value(&self) -> Option<FieldValue>
fn value(&self) -> Option<FieldValue>
FieldValue, or None for a view
that carries no transferable data. Read moreSource§fn set_value(&mut self, _v: FieldValue)
fn set_value(&mut self, _v: FieldValue)
FieldValue into this control. Read moreSource§fn set_modal_data(&mut self, _data: FieldValue)
fn set_modal_data(&mut self, _data: FieldValue)
Source§fn set_value_ctx(&mut self, v: FieldValue, ctx: &mut Context<'_>)
fn set_value_ctx(&mut self, v: FieldValue, ctx: &mut Context<'_>)
FieldValue into this control with a Context. Default:
calls set_value (the context-free setter). Override
when scatter needs deferred publishing (e.g.
ListBox republishes its vertical scrollbar via
focus_item).Source§fn awaken(&mut self)
fn awaken(&mut self)
Source§fn calc_bounds(&mut self, owner_size: Point, delta: Point) -> Rect
fn calc_bounds(&mut self, owner_size: Point, delta: Point) -> Rect
owner_size (delta = new - old). Computes the size limits via the overridable
size_limits hook — so a widget override (e.g. a
window’s minimum) participates — then delegates the grow math to
ViewState::calc_bounds (the single source). Returns the bounds; it does
not apply them (change_bounds does).Source§fn change_bounds(&mut self, bounds: Rect)
fn change_bounds(&mut self, bounds: Rect)
bounds to this view and propagate as needed. Read moreSource§fn caret_size(&self) -> u8
fn caret_size(&self) -> u8
CARET_INSERT (a block) when the
cursor_ins state is set, else
CARET_NORMAL (the normal caret).
The event loop reads it along the same focused chain as
cursor_request;
Group overrides it to descend into its current
child. Read moreSource§fn find_mut(&mut self, id: ViewId) -> Option<&mut dyn View>
fn find_mut(&mut self, id: ViewId) -> Option<&mut dyn View>
id to a descendant of this view (never self — the parent
identifies a view by id). A leaf has no descendants, so the base returns
None; a Group overrides to search its children
and recurse; a Group-embedding view delegates to its inner group. This is
the “tree-walk via Context” — the uniform way the event loop
/ a capture handler acts on a view it holds only by id (move a window’s
bounds, flip the dragging flag, …).Source§fn remove_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
fn remove_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
id from whichever group owns it.
Returns true if it was found+removed. Distinct
from find_mut because removal happens in the owner’s
child Vec (a view cannot remove itself — it doesn’t know its owner)
and must run the owning group’s reset_current. Base: false (a leaf owns
nothing).Source§fn focus_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
fn focus_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
id within whichever group owns it
— the tree-op behind a label focusing its linked control. Returns true
if id was found in this subtree (selectable or not — finding it stops the
walk). Distinct from find_mut because focusing happens in
the owning group (a view cannot select itself within itself): the
owning Group calls focus_child after applying the
selectable gate. Base: false (a leaf owns nothing). Read moreSource§fn has_focusable_leaf(&self) -> bool
fn has_focusable_leaf(&self) -> bool
Group
overrides to recurse into children; wrapper views delegate. Used by the
hierarchical Tab traversal to skip selectable-but-empty subtrees.Source§fn focus_to_edge(&mut self, backward: bool, ctx: &mut Context<'_>) -> bool
fn focus_to_edge(&mut self, backward: bool, ctx: &mut Context<'_>) -> bool
backward = false) or last (Shift-Tab,
backward = true) focusable leaf in this view’s subtree, establishing the
full focus path down to it. Returns true if a focusable leaf was focused. Read moreSource§fn reset_current(&mut self, _ctx: &mut Context<'_>)
fn reset_current(&mut self, _ctx: &mut Context<'_>)
Group::insert, so
exec_view calls this on a freshly-inserted modal BEFORE focusing it, so
the modal’s first selectable child is current on open (otherwise the modal
is keyboard-dead until a nav event — see the seam note in exec_view).
Base: no-op (a leaf has no internal currency); Group overrides;
Window/Dialog delegate.Source§fn settle_currency(&mut self, _ctx: &mut Context<'_>)
fn settle_currency(&mut self, _ctx: &mut Context<'_>)
Source§fn set_visible_descendant(
&mut self,
id: ViewId,
visible: bool,
ctx: &mut Context<'_>,
) -> bool
fn set_visible_descendant( &mut self, id: ViewId, visible: bool, ctx: &mut Context<'_>, ) -> bool
visible flag of the descendant named by id from its
OWNING group, running the owning group’s currency tail. Toggling
visibility on a selectable view re-picks the owner’s current child, in both
directions (show and hide). Returns true if id was found in this
subtree. Read moreSource§fn number(&self) -> Option<i16>
fn number(&self) -> Option<i16>
None);
Window overrides to return its number when > 0
(0 means unnumbered → None).Source§fn grabs_focus_on_click(&self) -> bool
fn grabs_focus_on_click(&self) -> bool
Group::route_event). Default true (the common case); a
Button overrides to return its grab-focus flag.
A view returning false is not focused by a click but still
receives the click (so it can act, e.g. press, without becoming the
current view).Source§fn select_window_num(&mut self, num: i16, ctx: &mut Context<'_>) -> bool
fn select_window_num(&mut self, num: i16, ctx: &mut Context<'_>) -> bool
num. Returns
whether one matched. Consistent with the find_mut /
remove_descendant tree-op family: the live
loop holds a subtree only by id (here, the desktop) and asks it to act.
Default: no-op (false). Desktop overrides.Source§fn tile(&mut self, _r: Rect)
fn tile(&mut self, _r: Rect)
Desktop lays out
windows). r is the desktop-local layout rect. Mirrors
select_window_num: the live loop drives the
desktop by id through &mut dyn View.Source§fn cascade(&mut self, _r: Rect)
fn cascade(&mut self, _r: Rect)
Desktop overrides.menu::menu_view::update_menu_commands
implements the re-gray walk. Read moreMenuBar / MenuBox)
override to set their
MenuViewState::current — the write-only
display cache their draw reads to pick the selected colour. Read moreSource§fn get_help_ctx(&self) -> HelpCtx
fn get_help_ctx(&self) -> HelpCtx
HelpCtx::DRAGGING while the view is being dragged, otherwise the
view’s own ViewState::help_ctx. Read moreSource§fn descendant_global_bounds(&self, _id: ViewId, _acc: Point) -> Option<Rect>
fn descendant_global_bounds(&self, _id: ViewId, _acc: Point) -> Option<Rect>
id to its absolute bounds, given acc = this
view’s own absolute origin. Base returns None (a leaf owns no
descendants); a Group overrides to walk its children
accumulating origins, and a Group-embedding view delegates to its inner
group. The THistory open path needs its linked
input line’s bounds in the root/absolute frame, because exec_view
root-inserts the modal and the modal frame hit-tests in absolute coords (the
documented ROOT-INSERT + (0,0) caveat). Mirrors
find_mut’s recursion but returns geometry, not a borrow.Source§fn set_indicator_value(&mut self, _location: Point, _modified: bool)
fn set_indicator_value(&mut self, _location: Point, _modified: bool)
Indicator overrides it to store the new
cursor location + modified flag. Driven by
Deferred::IndicatorSetValue:
the editor (a leaf) cannot reach its indicator sibling inline, so it requests
this and the pump calls the method by id — virtual dispatch, not a downcast.Source§fn apply_page_sync(&mut self, _idx: usize, _ctx: &mut Context<'_>)
fn apply_page_sync(&mut self, _idx: usize, _ctx: &mut Context<'_>)
PageStack overrides it to make page idx
active. Driven by
Deferred::PageStackSync: the pump
reads the bound tab bar’s value and calls this method by id — virtual
dispatch, not a downcast.Auto Trait Implementations§
impl Freeze for HistoryViewer
impl RefUnwindSafe for HistoryViewer
impl Send for HistoryViewer
impl Sync for HistoryViewer
impl Unpin for HistoryViewer
impl UnsafeUnpin for HistoryViewer
impl UnwindSafe for HistoryViewer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.