forked from romaonishuk/LexI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
122 lines (100 loc) · 4.29 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Created by romaonishuk on 27.10.19.
//
#include "i_command.hpp"
#include "config.hpp"
#include "button.hpp"
#include "decorator.hpp"
#include "event_manager.hpp"
#include "font.hpp"
#include "i_glyph.hpp"
#include "menu.hpp"
#include "menu_item.hpp"
#include "page.hpp"
#include "scroller.hpp"
#include "text_label.hpp"
#include "text_view.hpp"
#include "window.hpp"
#include <array>
const std::array supportedFontSizes = {
"10", "10,5", "11", "12", "14", "16", "18", "20", "22", "32", "48", "54", "72", "96"};
int main(int argc, char *argv[])
{
using Lexi::FontManager;
using Lexi::Config;
// Create window
GlyphParams initial_window_params;
initial_window_params.x = 0;
initial_window_params.y = 0;
initial_window_params.width = 1920;
initial_window_params.height = 1080;
Gui::Window window(initial_window_params);
EventManager eventManager(&window);
eventManager.addWindow(&window);
FontManager::Get().Init(&window);
const auto defaultFont = "clean"; //"Ubuntu Mono";
FontManager::Get().SetFont(defaultFont);
auto top_panel =
std::make_shared<BorderDecorator>(GlyphParams{0, 0, initial_window_params.width, 50}, Color::kWhite);
window.Add(top_panel);
auto fileMenu = std::make_shared<Gui::Menu>(GlyphParams{5, 5, 80, 40}, "File", &window);
auto openMenuItem = std::make_shared<Gui::MenuItem>("Open");
auto quitMenuItem = std::make_shared<Gui::MenuItem>("Quit");
fileMenu->Add(openMenuItem);
fileMenu->Add(quitMenuItem);
top_panel->Add(fileMenu);
eventManager.addWindow(fileMenu->getMenuWindow());
top_panel->Add(std::make_shared<Button>(GlyphParams{95, 5, 80, 40}, "Edit"));
top_panel->Add(std::make_shared<Button>(GlyphParams{275, 5, 80, 40}, "Symbol"));
auto text_view = std::make_shared<TextView>(GlyphParams{360, 100, 1200, 800}, &window);
window.Add(text_view);
eventManager.addWindow(text_view.get());
auto scroll_board = std::make_shared<Scroller>(GlyphParams{1895, 100, 20, 800}, text_view);
window.Add(scroll_board);
auto fontsMenu = std::make_shared<Gui::Menu>(GlyphParams{185, 5, 80, 40}, "Fonts", &window);
top_panel->Add(fontsMenu);
eventManager.addWindow(fontsMenu->getMenuWindow());
auto fontSizeMenu = std::make_shared<Gui::DropDownMenu>(GlyphParams{365, 10, 80, 20}, "12", &window);
top_panel->Add(fontSizeMenu);
eventManager.addWindow(fontSizeMenu->getMenuWindow());
auto bottom_panel =
std::make_shared<BorderDecorator>(GlyphParams{0, 940, initial_window_params.width, 20}, Color::kBlack);
auto status_line = std::make_shared<TextLabel>(GlyphParams{10, 955, 100, 20}, Config::get().GetSoftInfo());
bottom_panel->Add(status_line);
window.Add(bottom_panel);
// Actions
openMenuItem->SetOnFocusedAction([&] {
bottom_panel->ClearGlyph(&window);
status_line->ChangeText("Open file", &window);
bottom_panel->Draw(&window);
});
quitMenuItem->SetCommand(std::make_unique<QuitCommand>(&eventManager));
quitMenuItem->SetOnFocusedAction([&] {
bottom_panel->ClearGlyph(&window);
status_line->ChangeText("Close application", &window);
bottom_panel->Draw(&window);
});
for(const auto& it: FontManager::Get().GetFontList()) {
auto menuItem = std::make_shared<Gui::MenuItem>(it);
fontsMenu->Add(menuItem);
menuItem->SetOnFocusedAction([&, it] {
bottom_panel->ClearGlyph(&window);
status_line->ChangeText(it, &window);
bottom_panel->Draw(&window);
});
menuItem->SetOnButtonPressedAction([&, it] { FontManager::Get().SetFont(it); });
}
for(const auto& it: supportedFontSizes) {
auto item = std::make_shared<Gui::MenuItem>(it);
item->SetOnButtonPressedAction([it] { FontManager::Get().SetFontSize(it); });
fontSizeMenu->Add(std::move(item));
}
text_view->SetOnPageAddedAction([&]() {
scroll_board->UpdateScaling();
scroll_board->UpdateScrollerPosition(&window);
});
// TODO(rmn): think about textView/ScrollBar dependency!
text_view->SetOnVisibleAreaUpdateAction([&] { scroll_board->UpdateScrollerPosition(&window); });
text_view->SetOnScrollAction([&](const Lexi::Event& event) { scroll_board->ProcessEvent(&window, event); });
eventManager.RunLoop();
}