Skip to content

Commit

Permalink
Improve view menu
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Aug 10, 2024
1 parent 67164de commit bb9edc5
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 2 deletions.
2 changes: 2 additions & 0 deletions assets/lang/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/en_GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions source/core/inc/tactile/core/event/view_events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions source/core/inc/tactile/core/ui/i18n/string_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum class StringID : usize
kTileHeight,
kLightThemes,
kDarkThemes,
kFont,
kDefault,

// Generic verbs.
kCancel,
Expand Down
9 changes: 9 additions & 0 deletions source/core/inc/tactile/core/ui/menu/view_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class EventDispatcher;

namespace ui {

class Language;

/**
* Represents the "View" menu.
*/
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions source/core/src/tactile/core/ui/i18n/language_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ auto _get_noun_names() -> HashMap<StringView, StringID>
{"tile_height", StringID::kTileHeight},
{"light_themes", StringID::kLightThemes},
{"dark_themes", StringID::kDarkThemes},
{"font", StringID::kFont},
{"default", StringID::kDefault},
};
}

Expand Down
184 changes: 182 additions & 2 deletions source/core/src/tactile/core/ui/menu/view_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,198 @@

#include <imgui.h>

#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<CDocumentInfo>().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<ToggleUiEvent>();
}

ImGui::Separator();

_push_theme_menu(language, dispatcher);

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kIncreaseFontSize),
kIncreaseFontSizeShortcut.hint)) {
dispatcher.push<IncreaseFontSizeEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kDecreaseFontSize),
kDecreaseFontSizeShortcut.hint)) {
dispatcher.push<DecreaseFontSizeEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kResetFontSize))) {
dispatcher.push<ResetFontSizeEvent>();
}

_push_font_menu(language, dispatcher);

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kIncreaseZoom),
kIncreaseZoomShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<IncreaseViewportZoomEvent>(root_entity);
}

if (ImGui::MenuItem(language.get(StringID::kDecreaseZoom),
kDecreaseZoomShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<DecreaseViewportZoomEvent>(root_entity);
}

if (ImGui::MenuItem(language.get(StringID::kResetZoom),
nullptr,
false,
document != nullptr)) {
dispatcher.push<ResetViewportZoomEvent>(root_entity);
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kCenterViewport),
kCenterViewportShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<CenterViewportEvent>(root_entity, content_size);
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kToggleGrid), kToggleGridShortcut.hint)) {
dispatcher.push<ToggleGridEvent>();
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kPanUp),
kPanUpShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<PanViewportUpEvent>(root_entity);
}

if (ImGui::MenuItem(language.get(StringID::kPanDown),
kPanDownShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<PanViewportDownEvent>(root_entity);
}

if (ImGui::MenuItem(language.get(StringID::kPanLeft),
kPanLeftShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<PanViewportLeftEvent>(root_entity);
}

if (ImGui::MenuItem(language.get(StringID::kPanRight),
kPanRightShortcut.hint,
false,
document != nullptr)) {
dispatcher.push<PanViewportRightEvent>(root_entity);
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kHighlightActiveLayer))) {
dispatcher.push<ToggleLayerHighlightEvent>();
}
}
}

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<ResetLayoutEvent>();
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kPropertyDock), nullptr, true)) {
dispatcher.push<TogglePropertyDockEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kComponentDock), nullptr, true)) {
dispatcher.push<ToggleComponentDockEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kLayerDock), nullptr, true)) {
dispatcher.push<ToggleLayerDockEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kTilesetDock), nullptr, true)) {
dispatcher.push<ToggleTilesetDockEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kAnimationDock), nullptr, true)) {
dispatcher.push<ToggleAnimationDockEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kLogDock), nullptr, true)) {
dispatcher.push<ToggleLogDockEvent>();
}
}
}

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<SetFontEvent>(FontID::kDefault);
}

ImGui::Separator();

if (ImGui::MenuItem("Roboto")) {
dispatcher.push<SetFontEvent>(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<SetThemeEvent>(Theme::kDearImGuiLight);
}

ImGui::Separator();

if (ImGui::MenuItem("Dear ImGui##Dark")) {
ImGui::StyleColorsDark(&ImGui::GetStyle());
dispatcher.push<SetThemeEvent>(Theme::kDearImGuiDark);
}
}
}

Expand Down

0 comments on commit bb9edc5

Please sign in to comment.