forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibGUI: Add search/removal methods to Breadcrumbbar
Both are used by FileManager in the next commit. find_segment_with_data() was previously a single-use lambda in FileManager, but making it a method of Breadcrumbbar means we can re-use it more easily.
- Loading branch information
Showing
2 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Sam Atkins <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
@@ -72,7 +73,7 @@ void Breadcrumbbar::clear_segments() | |
remove_all_children(); | ||
} | ||
|
||
void Breadcrumbbar::append_segment(String text, const Gfx::Bitmap* icon, String data, String tooltip) | ||
void Breadcrumbbar::append_segment(String text, Gfx::Bitmap const* icon, String data, String tooltip) | ||
{ | ||
auto& button = add<BreadcrumbButton>(); | ||
button.set_button_style(Gfx::ButtonStyle::Coolbar); | ||
|
@@ -105,6 +106,23 @@ void Breadcrumbbar::append_segment(String text, const Gfx::Bitmap* icon, String | |
m_segments.append(move(segment)); | ||
} | ||
|
||
void Breadcrumbbar::remove_end_segments(size_t start_segment_index) | ||
{ | ||
while (segment_count() > start_segment_index) { | ||
auto segment = m_segments.take_last(); | ||
remove_child(*segment.button); | ||
} | ||
} | ||
|
||
Optional<size_t> Breadcrumbbar::find_segment_with_data(String const& data) | ||
{ | ||
for (size_t i = 0; i < segment_count(); ++i) { | ||
if (segment_data(i) == data) | ||
return i; | ||
} | ||
return {}; | ||
} | ||
|
||
void Breadcrumbbar::set_selected_segment(Optional<size_t> index) | ||
{ | ||
if (!index.has_value()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters