pub struct Table { /* private fields */ }Expand description
A multi-column table view. See the module docs.
Implementations§
Source§impl Table
impl Table
Sourcepub fn toggle_column_command(col: usize) -> Command
pub fn toggle_column_command(col: usize) -> Command
The command that shows or hides model column col when it reaches
the focused table — what the column popup’s items post. Bind it to a
key or a menu item to toggle a column directly; like the popup, it
never hides the last visible column, and it broadcasts
Command::TABLE_COLUMNS_CHANGED.
Sourcepub fn column_layout(&self) -> Vec<ColumnState>
pub fn column_layout(&self) -> Vec<ColumnState>
Every column’s state, in model order: the display position, width,
flex weight, fixed flag and hidden flag. Store it and hand it to
set_column_layout to restore what the
user arranged.
Sourcepub fn set_column_layout(&mut self, layout: &[ColumnState])
pub fn set_column_layout(&mut self, layout: &[ColumnState])
Restore a column_layout. Entries for unknown
columns are ignored; the columns layout does not name keep their
state and follow the named ones in their current order. Widths are
clamped to the column’s min_width (at least 1) and to
MAX_COLUMN_WIDTH.
Does not broadcast; the bars catch up on the table’s next event.
Source§impl Table
impl Table
Sourcepub fn is_editing(&self) -> bool
pub fn is_editing(&self) -> bool
Whether a cell editor is open.
Sourcepub fn cursor_column(&self) -> Option<usize>
pub fn cursor_column(&self) -> Option<usize>
The model column under the cell cursor, None when no visible column
is editable.
Sourcepub fn cancel_edit(&mut self, ctx: &mut Context<'_>)
pub fn cancel_edit(&mut self, ctx: &mut Context<'_>)
Close the editor without storing its text.
Source§impl Table
impl Table
Sourcepub fn new(
bounds: Rect,
columns: Vec<ColumnSpec>,
v_scroll_bar: Option<ViewId>,
) -> Self
pub fn new( bounds: Rect, columns: Vec<ColumnSpec>, v_scroll_bar: Option<ViewId>, ) -> Self
A table at bounds (header on the first row, rows below) with
columns, wired to the optional vertical scroll bar v_scroll_bar.
It starts with an empty model; add rows with
with_model or, after insertion,
set_model.
Sourcepub fn with_h_bar(self, h_bar: ViewId) -> Self
pub fn with_h_bar(self, h_bar: ViewId) -> Self
Builder: wire the horizontal scroll bar h_bar (an external sibling,
like the vertical one). Its range is the columns’ overflow past the
view: 0 while they fit. The table publishes range and steps itself.
Sourcepub fn h_offset(&self) -> i32
pub fn h_offset(&self) -> i32
How far the columns are scrolled to the left, in display cells (0 when they fit).
Sourcepub fn set_h_offset(&mut self, offset: i32, ctx: &mut Context<'_>)
pub fn set_h_offset(&mut self, offset: i32, ctx: &mut Context<'_>)
Scroll the columns to offset display cells (clamped to the
overflow) and move the horizontal bar with them.
Sourcepub fn with_model(self, model: Box<dyn TableModel>) -> Self
pub fn with_model(self, model: Box<dyn TableModel>) -> Self
Builder: the initial rows (no Context needed; the table publishes
them to its scroll bar on its first event).
Sourcepub fn with_selection_mode(self, mode: SelectionMode) -> Self
pub fn with_selection_mode(self, mode: SelectionMode) -> Self
Builder: the selection mode (default SelectionMode::Single).
Sourcepub fn selection_mode(&self) -> SelectionMode
pub fn selection_mode(&self) -> SelectionMode
The selection mode.
Sourcepub fn with_separators(self, separators: Separators) -> Self
pub fn with_separators(self, separators: Separators) -> Self
Builder: which column separators to draw (see Separators).
The default, Separators::Off, leaves the one-cell separators
blank; Separators::Header draws the theme’s vertical frame glyph
(│ by default) in the header row only, making the resize handle
visible; Separators::All draws the header rule and the same rule
between every row’s cells as well. When the columns leave spare width,
the header also rules the cell after the last column (its resize
handle); the rows leave that cell blank.
Sourcepub fn separators(&self) -> Separators
pub fn separators(&self) -> Separators
The column separators drawn between the table’s columns.
Sourcepub fn model(&self) -> Ref<'_, dyn TableModel>
pub fn model(&self) -> Ref<'_, dyn TableModel>
The current model.
Sourcepub fn set_model(&mut self, model: Box<dyn TableModel>, ctx: &mut Context<'_>)
pub fn set_model(&mut self, model: Box<dyn TableModel>, ctx: &mut Context<'_>)
Replace the rows. Focus stays on the same RowKey when it still
exists (else the focused position is clamped into the new rows), the
sort is re-applied, marks of vanished rows are dropped, and the scroll
bar’s range is updated. Does not broadcast.
Sourcepub fn focused_row(&self) -> Option<usize>
pub fn focused_row(&self) -> Option<usize>
The model index of the focused row, None when there are no rows.
Sourcepub fn focused_key(&self) -> Option<RowKey>
pub fn focused_key(&self) -> Option<RowKey>
The key of the focused row, None when there are no rows.
Sourcepub fn set_focused_key(&mut self, key: &RowKey, ctx: &mut Context<'_>) -> bool
pub fn set_focused_key(&mut self, key: &RowKey, ctx: &mut Context<'_>) -> bool
Move focus to the row with key (scrolling it into view). Returns
false if no row has that key.
Sourcepub fn sort_spec(&self) -> Option<(usize, SortDir)>
pub fn sort_spec(&self) -> Option<(usize, SortDir)>
The current sort: column and direction, None for model order.
Sourcepub fn sort_by(&mut self, col: usize, dir: SortDir, ctx: &mut Context<'_>)
pub fn sort_by(&mut self, col: usize, dir: SortDir, ctx: &mut Context<'_>)
Sort by column col (an index into the columns) in dir, keeping
focus on its row. An out-of-range column is ignored. Does not
broadcast.
Sourcepub fn clear_sort(&mut self, ctx: &mut Context<'_>)
pub fn clear_sort(&mut self, ctx: &mut Context<'_>)
Back to model order, keeping focus on its row. Does not broadcast.
Hide or show column col. A hidden column takes no space; a hidden
sort column keeps ordering the rows (its marker is just not shown).
Whether column col is hidden (false for an unknown column).
Sourcepub fn selected_keys(&self) -> Vec<RowKey>
pub fn selected_keys(&self) -> Vec<RowKey>
The keys of the marked rows, in model order (multi mode; empty in single mode unless set programmatically).
Sourcepub fn set_selected_keys(&mut self, keys: impl IntoIterator<Item = RowKey>)
pub fn set_selected_keys(&mut self, keys: impl IntoIterator<Item = RowKey>)
Replace the marks with keys; keys without a row are ignored. Does not
broadcast.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear every mark, leaving focus where it is. Does not broadcast.
Trait Implementations§
Source§impl View for Table
impl View for Table
Source§fn set_state(&mut self, flag: StateFlag, enable: bool, ctx: &mut Context<'_>)
fn set_state(&mut self, flag: StateFlag, enable: bool, ctx: &mut Context<'_>)
Publish the rows to the scroll bar if that is still pending, then let
the group fan the flag out. The owner sends Active to every child
when its window or dialog activates, so a table publishes even when no
event ever reaches it (another control holds focus).
Source§fn draw(&mut self, ctx: &mut DrawCtx<'_>)
fn draw(&mut self, ctx: &mut DrawCtx<'_>)
Remember where the table sits on screen (for the drag tracking and the column popup), then draw the header and the rows.
Source§fn valid(&mut self, cmd: Command, ctx: &mut Context<'_>) -> bool
fn valid(&mut self, cmd: Command, ctx: &mut Context<'_>) -> bool
With a cell editor open, Command::CANCEL cancels the edit and any
other command commits it first — a dialog’s OK, but also a window’s
Command::CLOSE and the program’s Command::QUIT, as C++
TInputLine::valid validates for every command but cmCancel. A
refused text shows its box and vetoes the command, so closing never
drops what the field shows. Command::VALID and a focus release
leave the edit alone, and an edit whose cell is gone is discarded.
Then the children are checked as usual.
The Command::TABLE_CELL_EDITED broadcast of a commit made here is
queued; when the command closes a modal dialog, it is delivered after
the dialog is gone. Views outside the dialog receive it, but its
source names a table that no longer exists and views inside the
dialog never see it.
Source§fn change_bounds(&mut self, bounds: Rect)
fn change_bounds(&mut self, bounds: Rect)
Resize the header and the body (grow modes), and mark the bars for a
re-publish: the new size changes the vertical page step and the
horizontal range. Every framework resize path then calls
on_bounds_changed, which publishes at
once. The mark is a fallback for app code that calls change_bounds
directly: the publish then runs on the table’s next event.
Source§fn on_bounds_changed(&mut self, ctx: &mut Context<'_>)
fn on_bounds_changed(&mut self, ctx: &mut Context<'_>)
Re-publish the bars for the new size, and hand the hook on to the children the group re-bounded (the header and body publish nothing themselves; this keeps the group’s cascade intact for any child).
Source§fn value(&self) -> Option<FieldValue>
fn value(&self) -> Option<FieldValue>
Single mode: the focused row’s key as FieldValue::Text ("" with
no rows). Multi mode: the marked keys as a FieldValue::List of
Text, in model order.
Source§fn set_value(&mut self, v: FieldValue)
fn set_value(&mut self, v: FieldValue)
Accepts the shapes value produces: single mode focuses
the row with the Text key (unknown keys are ignored), multi mode
replaces the marks with the List of Text keys. Other shapes are
ignored. Without a Context the scroll bar catches up on its next
sync; prefer set_value_ctx.
Source§fn set_value_ctx(&mut self, v: FieldValue, ctx: &mut Context<'_>)
fn set_value_ctx(&mut self, v: FieldValue, ctx: &mut Context<'_>)
Like set_value, but a single-mode focus move also
updates the scroll bar.
Source§fn handle_event(&mut self, ev: &mut Event, ctx: &mut Context<'_>)
fn handle_event(&mut self, ev: &mut Event, ctx: &mut Context<'_>)
Source§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 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 set_modal_data(&mut self, data: FieldValue)
fn set_modal_data(&mut self, data: FieldValue)
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 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 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.Source§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 moremenu::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 !RefUnwindSafe for Table
impl !Send for Table
impl !Sync for Table
impl !UnwindSafe for Table
impl Freeze for Table
impl Unpin for Table
impl UnsafeUnpin for Table
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.