From bb9edc53c645be37f572accb7501abde15c9d614 Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Sun, 11 Aug 2024 01:56:20 +0200 Subject: [PATCH] Improve view menu --- assets/lang/en.ini | 2 + assets/lang/en_GB.ini | 2 + assets/lang/sv.ini | 2 + .../inc/tactile/core/event/view_events.hpp | 6 + .../inc/tactile/core/ui/i18n/string_id.hpp | 2 + .../inc/tactile/core/ui/menu/view_menu.hpp | 9 + .../tactile/core/ui/i18n/language_parser.cpp | 2 + .../src/tactile/core/ui/menu/view_menu.cpp | 184 +++++++++++++++++- 8 files changed, 207 insertions(+), 2 deletions(-) diff --git a/assets/lang/en.ini b/assets/lang/en.ini index bf0c7b3060..489b6b00fa 100644 --- a/assets/lang/en.ini +++ b/assets/lang/en.ini @@ -38,6 +38,8 @@ tile_width = Tile width tile_height = Tile height light_themes = Light themes dark_themes = Dark themes +font = Font +default = Default [adjective] orthogonal = Orthogonal diff --git a/assets/lang/en_GB.ini b/assets/lang/en_GB.ini index a9c3ab12ff..5cb3efaad0 100644 --- a/assets/lang/en_GB.ini +++ b/assets/lang/en_GB.ini @@ -38,6 +38,8 @@ tile_width = Tile width tile_height = Tile height light_themes = Light themes dark_themes = Dark themes +font = Font +default = Default [adjective] orthogonal = Orthogonal diff --git a/assets/lang/sv.ini b/assets/lang/sv.ini index d7da046bd7..cb2740d1d0 100644 --- a/assets/lang/sv.ini +++ b/assets/lang/sv.ini @@ -38,6 +38,8 @@ tile_width = Tilebredd tile_height = Tilehöjd light_themes = Ljusa teman dark_themes = Mörka teman +font = Typsnitt +default = Standard [adjective] orthogonal = Ortogonal diff --git a/source/core/inc/tactile/core/event/view_events.hpp b/source/core/inc/tactile/core/event/view_events.hpp index 7f83f0a3fd..ef8ed4a940 100644 --- a/source/core/inc/tactile/core/event/view_events.hpp +++ b/source/core/inc/tactile/core/event/view_events.hpp @@ -14,6 +14,12 @@ namespace tactile { struct ResetLayoutEvent final {}; +/** + * Event for toggling the visibility of dock widgets. + */ +struct ToggleUiEvent final +{}; + /** * Event for toggling the visibility of the property dock widget. */ diff --git a/source/core/inc/tactile/core/ui/i18n/string_id.hpp b/source/core/inc/tactile/core/ui/i18n/string_id.hpp index 4c61dd398d..73c9b9cc29 100644 --- a/source/core/inc/tactile/core/ui/i18n/string_id.hpp +++ b/source/core/inc/tactile/core/ui/i18n/string_id.hpp @@ -48,6 +48,8 @@ enum class StringID : usize kTileHeight, kLightThemes, kDarkThemes, + kFont, + kDefault, // Generic verbs. kCancel, diff --git a/source/core/inc/tactile/core/ui/menu/view_menu.hpp b/source/core/inc/tactile/core/ui/menu/view_menu.hpp index 797ebed4f7..a55b154564 100644 --- a/source/core/inc/tactile/core/ui/menu/view_menu.hpp +++ b/source/core/inc/tactile/core/ui/menu/view_menu.hpp @@ -11,6 +11,8 @@ class EventDispatcher; namespace ui { +class Language; + /** * Represents the "View" menu. */ @@ -24,6 +26,13 @@ class ViewMenu final * \param dispatcher The event dispatcher to use. */ void push(const Model& model, EventDispatcher& dispatcher); + + private: + static void _push_widgets_menu(const Language& language, EventDispatcher& dispatcher); + + static void _push_font_menu(const Language& language, EventDispatcher& dispatcher); + + static void _push_theme_menu(const Language& language, EventDispatcher& dispatcher); }; } // namespace ui diff --git a/source/core/src/tactile/core/ui/i18n/language_parser.cpp b/source/core/src/tactile/core/ui/i18n/language_parser.cpp index 1886c3faba..d8dfefb2bc 100644 --- a/source/core/src/tactile/core/ui/i18n/language_parser.cpp +++ b/source/core/src/tactile/core/ui/i18n/language_parser.cpp @@ -70,6 +70,8 @@ auto _get_noun_names() -> HashMap {"tile_height", StringID::kTileHeight}, {"light_themes", StringID::kLightThemes}, {"dark_themes", StringID::kDarkThemes}, + {"font", StringID::kFont}, + {"default", StringID::kDefault}, }; } diff --git a/source/core/src/tactile/core/ui/menu/view_menu.cpp b/source/core/src/tactile/core/ui/menu/view_menu.cpp index 3401df4b95..c1a8937b3f 100644 --- a/source/core/src/tactile/core/ui/menu/view_menu.cpp +++ b/source/core/src/tactile/core/ui/menu/view_menu.cpp @@ -4,18 +4,198 @@ #include +#include "tactile/core/document/document_info.hpp" +#include "tactile/core/entity/registry.hpp" #include "tactile/core/event/event_dispatcher.hpp" +#include "tactile/core/event/view_events.hpp" +#include "tactile/core/event/viewport_events.hpp" #include "tactile/core/model/model.hpp" #include "tactile/core/ui/common/menus.hpp" #include "tactile/core/ui/i18n/language.hpp" +#include "tactile/core/ui/shortcuts.hpp" namespace tactile::ui { void ViewMenu::push(const Model& model, EventDispatcher& dispatcher) { const auto& language = model.get_language(); - const MenuScope menu {language.get(StringID::kViewMenu)}; - if (menu.is_open()) { + const auto* document = model.get_current_document(); + + const auto root_entity = (document != nullptr) + ? document->get_registry().get().root + : kInvalidEntity; + const auto content_size = (document != nullptr) ? document->get_content_size() : Float2 {}; + + if (const MenuScope menu {language.get(StringID::kViewMenu)}; menu.is_open()) { + _push_widgets_menu(language, dispatcher); + + if (ImGui::MenuItem(language.get(StringID::kToggleUi))) { + dispatcher.push(); + } + + ImGui::Separator(); + + _push_theme_menu(language, dispatcher); + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kIncreaseFontSize), + kIncreaseFontSizeShortcut.hint)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kDecreaseFontSize), + kDecreaseFontSizeShortcut.hint)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kResetFontSize))) { + dispatcher.push(); + } + + _push_font_menu(language, dispatcher); + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kIncreaseZoom), + kIncreaseZoomShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + if (ImGui::MenuItem(language.get(StringID::kDecreaseZoom), + kDecreaseZoomShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + if (ImGui::MenuItem(language.get(StringID::kResetZoom), + nullptr, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kCenterViewport), + kCenterViewportShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity, content_size); + } + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kToggleGrid), kToggleGridShortcut.hint)) { + dispatcher.push(); + } + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kPanUp), + kPanUpShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + if (ImGui::MenuItem(language.get(StringID::kPanDown), + kPanDownShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + if (ImGui::MenuItem(language.get(StringID::kPanLeft), + kPanLeftShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + if (ImGui::MenuItem(language.get(StringID::kPanRight), + kPanRightShortcut.hint, + false, + document != nullptr)) { + dispatcher.push(root_entity); + } + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kHighlightActiveLayer))) { + dispatcher.push(); + } + } +} + +void ViewMenu::_push_widgets_menu(const Language& language, EventDispatcher& dispatcher) +{ + if (const MenuScope widgets_menu {language.get(StringID::kWidgetsMenu)}; + widgets_menu.is_open()) { + if (ImGui::MenuItem(language.get(StringID::kResetLayout))) { + dispatcher.push(); + } + + ImGui::Separator(); + + if (ImGui::MenuItem(language.get(StringID::kPropertyDock), nullptr, true)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kComponentDock), nullptr, true)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kLayerDock), nullptr, true)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kTilesetDock), nullptr, true)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kAnimationDock), nullptr, true)) { + dispatcher.push(); + } + + if (ImGui::MenuItem(language.get(StringID::kLogDock), nullptr, true)) { + dispatcher.push(); + } + } +} + +void ViewMenu::_push_font_menu(const Language& language, EventDispatcher& dispatcher) +{ + if (const MenuScope font_menu {language.get(StringID::kFont)}; font_menu.is_open()) { + if (ImGui::MenuItem(language.get(StringID::kDefault))) { + dispatcher.push(FontID::kDefault); + } + + ImGui::Separator(); + + if (ImGui::MenuItem("Roboto")) { + dispatcher.push(FontID::kRoboto); + } + } +} + +void ViewMenu::_push_theme_menu(const Language& language, EventDispatcher& dispatcher) +{ + if (const MenuScope theme_menu {language.get(StringID::kThemeMenu)}; theme_menu.is_open()) { + if (ImGui::MenuItem("Dear ImGui##Light")) { + ImGui::StyleColorsLight(&ImGui::GetStyle()); + dispatcher.push(Theme::kDearImGuiLight); + } + + ImGui::Separator(); + + if (ImGui::MenuItem("Dear ImGui##Dark")) { + ImGui::StyleColorsDark(&ImGui::GetStyle()); + dispatcher.push(Theme::kDearImGuiDark); + } } }