mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:27:35 +00:00
Maps: Add toolbar and frame border to map widget
This commit is contained in:
parent
b5f91e3365
commit
048e8d7744
3 changed files with 54 additions and 26 deletions
|
@ -9,10 +9,14 @@
|
|||
#include <LibCore/System.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/ToolbarContainer.h>
|
||||
#include <LibGUI/Window.h>
|
||||
|
||||
static int constexpr MAP_ZOOM_DEFAULT = 3;
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
||||
|
@ -31,29 +35,52 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->restore_size_and_position("Maps"sv, "Window"sv, { { 640, 480 } });
|
||||
window->save_size_and_position_on_close("Maps"sv, "Window"sv);
|
||||
|
||||
// Root widget
|
||||
auto root_widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
root_widget->set_fill_with_background_color(true);
|
||||
root_widget->set_layout<GUI::VerticalBoxLayout>(GUI::Margins {}, 2);
|
||||
|
||||
// Toolbar
|
||||
auto toolbar_container = TRY(root_widget->try_add<GUI::ToolbarContainer>());
|
||||
auto toolbar = TRY(toolbar_container->try_add<GUI::Toolbar>());
|
||||
|
||||
// Map widget
|
||||
MapWidget::Options options {};
|
||||
options.center.latitude = Config::read_string("Maps"sv, "MapView"sv, "CenterLatitude"sv, "30"sv).to_double().value_or(30.0);
|
||||
options.center.longitude = Config::read_string("Maps"sv, "MapView"sv, "CenterLongitude"sv, "0"sv).to_double().value_or(0.0);
|
||||
options.zoom = Config::read_i32("Maps"sv, "MapView"sv, "Zoom"sv, 3);
|
||||
auto maps = TRY(MapWidget::try_create(options));
|
||||
window->set_main_widget(maps);
|
||||
options.zoom = Config::read_i32("Maps"sv, "MapView"sv, "Zoom"sv, MAP_ZOOM_DEFAULT);
|
||||
auto maps = TRY(root_widget->try_add<MapWidget>(options));
|
||||
maps->set_frame_style(Gfx::FrameStyle::SunkenContainer);
|
||||
|
||||
// Main menu
|
||||
// Main menu actions
|
||||
auto file_menu = window->add_menu("&File"_string);
|
||||
file_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the()->quit(); }));
|
||||
|
||||
auto view_menu = window->add_menu("&View"_string);
|
||||
view_menu->add_action(GUI::CommonActions::make_zoom_in_action([maps](auto&) { maps->set_zoom(maps->zoom() + 1); }, window));
|
||||
view_menu->add_action(GUI::CommonActions::make_zoom_out_action([maps](auto&) { maps->set_zoom(maps->zoom() - 1); }, window));
|
||||
view_menu->add_action(GUI::CommonActions::make_reset_zoom_action([maps](auto&) { maps->set_zoom(3); }, window));
|
||||
auto zoom_in_action = GUI::CommonActions::make_zoom_in_action([maps](auto&) { maps->set_zoom(maps->zoom() + 1); }, window);
|
||||
auto zoom_out_action = GUI::CommonActions::make_zoom_out_action([maps](auto&) { maps->set_zoom(maps->zoom() - 1); }, window);
|
||||
auto reset_zoom_action = GUI::CommonActions::make_reset_zoom_action([maps](auto&) { maps->set_zoom(MAP_ZOOM_DEFAULT); }, window);
|
||||
auto fullscreen_action = GUI::CommonActions::make_fullscreen_action([window, toolbar_container, maps](auto&) {
|
||||
window->set_fullscreen(!window->is_fullscreen());
|
||||
toolbar_container->set_visible(!window->is_fullscreen());
|
||||
maps->set_frame_style(window->is_fullscreen() ? Gfx::FrameStyle::NoFrame : Gfx::FrameStyle::SunkenContainer);
|
||||
},
|
||||
window);
|
||||
view_menu->add_action(zoom_in_action);
|
||||
view_menu->add_action(zoom_out_action);
|
||||
view_menu->add_action(reset_zoom_action);
|
||||
view_menu->add_separator();
|
||||
view_menu->add_action(GUI::CommonActions::make_fullscreen_action([window](auto&) { window->set_fullscreen(!window->is_fullscreen()); }, window));
|
||||
view_menu->add_action(fullscreen_action);
|
||||
|
||||
auto help_menu = window->add_menu("&Help"_string);
|
||||
help_menu->add_action(GUI::CommonActions::make_command_palette_action(window));
|
||||
help_menu->add_action(GUI::CommonActions::make_about_action("Maps", app_icon, window));
|
||||
|
||||
// Main toolbar actions
|
||||
toolbar->add_action(zoom_in_action);
|
||||
toolbar->add_action(zoom_out_action);
|
||||
toolbar->add_action(reset_zoom_action);
|
||||
|
||||
window->show();
|
||||
|
||||
// Remember last map position
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue