mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
Maps: Use StackWidget in panels instead of toggling visibility
This commit is contained in:
1 parent
2887302286
commit
030a430120
9 files changed
+46
-46
No files matched your search
@@ -14,6 +14,9 @@ class FavoritesEditDialog final : public GUI::Widget {
|
||||
C_OBJECT(FavoritesEditDialog)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<FavoritesEditDialog>> try_create();
|
||||
|
||||
private:
|
||||
FavoritesEditDialog() = default;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
ErrorOr<void> load_from_file(Core::File&);
|
||||
|
||||
private:
|
||||
FavoritesModel() = default;
|
||||
|
||||
Vector<Favorite> m_favorites;
|
||||
};
|
||||
|
||||
|
||||
@@ -116,8 +116,7 @@ ErrorOr<void> FavoritesPanel::edit_favorite(GUI::ModelIndex const& index)
|
||||
void FavoritesPanel::favorites_changed()
|
||||
{
|
||||
// Update UI
|
||||
m_empty_container->set_visible(m_model->row_count() == 0);
|
||||
m_favorites_list->set_visible(m_model->row_count() > 0);
|
||||
set_active_widget(m_model->row_count() == 0 ? m_empty_container : m_favorites_list);
|
||||
on_favorites_change(m_model->favorites());
|
||||
|
||||
// Save favorites
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
min_width: 100
|
||||
preferred_width: 200
|
||||
max_width: 350
|
||||
layout: @GUI::VerticalBoxLayout {}
|
||||
|
||||
// Empty and favorites are toggled in visibility
|
||||
@GUI::Frame {
|
||||
name: "empty_container"
|
||||
frame_style: "SunkenPanel"
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
|
||||
#include "FavoritesModel.h"
|
||||
#include <LibGUI/ListView.h>
|
||||
#include <LibGUI/StackWidget.h>
|
||||
|
||||
namespace Maps {
|
||||
|
||||
class FavoritesPanel final : public GUI::Widget {
|
||||
class FavoritesPanel final : public GUI::StackWidget {
|
||||
C_OBJECT(FavoritesPanel)
|
||||
|
||||
public:
|
||||
@@ -26,10 +27,9 @@ public:
|
||||
Function<void(Vector<Favorite> const&)> on_favorites_change;
|
||||
Function<void(Favorite const&)> on_selected_favorite_change;
|
||||
|
||||
protected:
|
||||
private:
|
||||
FavoritesPanel() = default;
|
||||
|
||||
private:
|
||||
ErrorOr<void> edit_favorite(GUI::ModelIndex const& index);
|
||||
void favorites_changed();
|
||||
|
||||
|
||||
@@ -15,13 +15,11 @@ ErrorOr<void> SearchPanel::initialize()
|
||||
|
||||
m_search_textbox = *find_descendant_of_type_named<GUI::TextBox>("search_textbox");
|
||||
m_search_button = *find_descendant_of_type_named<GUI::Button>("search_button");
|
||||
m_stack_widget = *find_descendant_of_type_named<GUI::StackWidget>("stack_widget");
|
||||
m_start_container = *find_descendant_of_type_named<GUI::Frame>("start_container");
|
||||
m_empty_container = *find_descendant_of_type_named<GUI::Frame>("empty_container");
|
||||
m_places_list = *find_descendant_of_type_named<GUI::ListView>("places_list");
|
||||
|
||||
m_empty_container->set_visible(false);
|
||||
m_places_list->set_visible(false);
|
||||
|
||||
m_search_textbox->on_return_pressed = [this]() {
|
||||
search(MUST(String::from_byte_string(m_search_textbox->text())));
|
||||
};
|
||||
@@ -44,12 +42,9 @@ void SearchPanel::search(StringView query)
|
||||
{
|
||||
// Show start container when empty query
|
||||
if (query.is_empty()) {
|
||||
m_start_container->set_visible(true);
|
||||
m_empty_container->set_visible(false);
|
||||
m_places_list->set_visible(false);
|
||||
m_stack_widget->set_active_widget(m_start_container);
|
||||
return;
|
||||
}
|
||||
m_start_container->set_visible(false);
|
||||
|
||||
// Start HTTP GET request to load people.json
|
||||
HTTP::HeaderMap headers;
|
||||
@@ -78,8 +73,7 @@ void SearchPanel::search(StringView query)
|
||||
// Show empty label when no places are found
|
||||
auto json_places = result.release_value().as_array();
|
||||
if (json_places.size() == 0) {
|
||||
m_empty_container->set_visible(true);
|
||||
m_places_list->set_visible(false);
|
||||
m_stack_widget->set_active_widget(m_empty_container);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,9 +103,8 @@ void SearchPanel::search(StringView query)
|
||||
on_places_change(m_places);
|
||||
|
||||
// Update and show places list
|
||||
m_empty_container->set_visible(false);
|
||||
m_places_list->set_model(*GUI::ItemListModel<String>::create(m_places_names));
|
||||
m_places_list->set_visible(true);
|
||||
m_stack_widget->set_active_widget(m_places_list);
|
||||
});
|
||||
|
||||
request->on_certificate_requested = []() -> Protocol::Request::CertificateAndKey { return {}; };
|
||||
|
||||
@@ -26,38 +26,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Start, empty and places are toggled in visibility
|
||||
@GUI::Frame {
|
||||
name: "start_container"
|
||||
frame_style: "SunkenPanel"
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
@GUI::StackWidget {
|
||||
name: "stack_widget"
|
||||
|
||||
@GUI::Frame {
|
||||
name: "start_container"
|
||||
frame_style: "SunkenPanel"
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "Enter a search query to search for places..."
|
||||
text_alignment: "CenterLeft"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "Enter a search query to search for places..."
|
||||
text_alignment: "CenterLeft"
|
||||
}
|
||||
}
|
||||
@GUI::Frame {
|
||||
name: "empty_container"
|
||||
frame_style: "SunkenPanel"
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
}
|
||||
|
||||
@GUI::Frame {
|
||||
name: "empty_container"
|
||||
frame_style: "SunkenPanel"
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
@GUI::Label {
|
||||
text: "Can't find any places with the search query"
|
||||
text_alignment: "CenterLeft"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "Can't find any places with the search query"
|
||||
text_alignment: "CenterLeft"
|
||||
@GUI::ListView {
|
||||
name: "places_list"
|
||||
horizontal_padding: 6
|
||||
vertical_padding: 4
|
||||
should_hide_unnecessary_scrollbars: true
|
||||
alternating_row_colors: false
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::ListView {
|
||||
name: "places_list"
|
||||
horizontal_padding: 6
|
||||
vertical_padding: 4
|
||||
should_hide_unnecessary_scrollbars: true
|
||||
alternating_row_colors: false
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <LibGUI/Frame.h>
|
||||
#include <LibGUI/ItemListModel.h>
|
||||
#include <LibGUI/ListView.h>
|
||||
#include <LibGUI/StackWidget.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibMaps/MapWidget.h>
|
||||
#include <LibProtocol/Request.h>
|
||||
@@ -42,6 +43,7 @@ private:
|
||||
RefPtr<Protocol::Request> m_request;
|
||||
RefPtr<GUI::TextBox> m_search_textbox;
|
||||
RefPtr<GUI::Button> m_search_button;
|
||||
RefPtr<GUI::StackWidget> m_stack_widget;
|
||||
RefPtr<GUI::Frame> m_start_container;
|
||||
RefPtr<GUI::Frame> m_empty_container;
|
||||
RefPtr<GUI::ListView> m_places_list;
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
private:
|
||||
MapsSettingsWidget() = default;
|
||||
|
||||
void set_tile_provider(StringView url);
|
||||
void set_tile_provider(StringView tile_provider_url_format);
|
||||
|
||||
RefPtr<GUI::ComboBox> m_tile_provider_combobox;
|
||||
RefPtr<GUI::Widget> m_custom_tile_provider_group;
|
||||
|
||||
Reference in new issue
Block a user