mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 05:25:13 +00:00
LibGUI: Add on_toggle function to TreeView
This adds a function to expose the index and open/close state of expandible nodes in TreeView.
This commit is contained in:
parent
27109c3467
commit
cbf3c2caeb
Notes:
sideshowbarker
2024-07-19 05:02:46 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/cbf3c2caeb9 Pull-request: https://github.com/SerenityOS/serenity/pull/2726
2 changed files with 7 additions and 2 deletions
|
@ -145,6 +145,8 @@ void TreeView::toggle_index(const ModelIndex& index)
|
|||
ASSERT(model()->row_count(index));
|
||||
auto& metadata = ensure_metadata_for_index(index);
|
||||
metadata.open = !metadata.open;
|
||||
if (on_toggle)
|
||||
on_toggle(index, metadata.open);
|
||||
update_column_sizes();
|
||||
update_content_size();
|
||||
update();
|
||||
|
@ -452,6 +454,8 @@ void TreeView::keydown_event(KeyEvent& event)
|
|||
}
|
||||
|
||||
auto open_tree_node = [&](bool open, MetadataForIndex& metadata) {
|
||||
if (on_toggle)
|
||||
on_toggle(cursor_index, open);
|
||||
metadata.open = open;
|
||||
update_column_sizes();
|
||||
update_content_size();
|
||||
|
@ -499,8 +503,7 @@ void TreeView::keydown_event(KeyEvent& event)
|
|||
|
||||
if (event.key() == KeyCode::Key_Return) {
|
||||
if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
|
||||
auto& metadata = ensure_metadata_for_index(cursor_index);
|
||||
open_tree_node(!metadata.open, metadata);
|
||||
toggle_index(cursor_index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
void expand_tree(const ModelIndex& root = {});
|
||||
void collapse_tree(const ModelIndex& root = {});
|
||||
|
||||
Function<void(const ModelIndex&, const bool)> on_toggle;
|
||||
|
||||
protected:
|
||||
TreeView();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue