Skip to content

Commit ec11bde

Browse files
authored
EDG-3409 Check text boundaries on input (#716)
* [EDG-3409] Check text boundaries during input processing
1 parent e5d4dfc commit ec11bde

30 files changed

+991
-376
lines changed

module-gui/gui/input/Translator.cpp

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -158,77 +158,6 @@ namespace gui
158158
return evt;
159159
}
160160

161-
/// profiles cache - load once for all
162-
class Profiles
163-
{
164-
private:
165-
const char *profilesFolder = "assets/profiles";
166-
std::map<std::string, gui::Profile> profiles = {};
167-
168-
void loadProfile(const std::string &filepath)
169-
{
170-
LOG_INFO("Load profile: %s", filepath.c_str());
171-
auto p = Profile(filepath);
172-
if (p.getName() != std::string()) {
173-
profiles.insert({p.getName(), std::move(p)});
174-
}
175-
}
176-
177-
std::vector<std::string> getProfilesList(std::string ext)
178-
{
179-
std::vector<std::string> profileFiles;
180-
LOG_INFO("Scanning %s profiles folder: %s", ext.c_str(), profilesFolder);
181-
auto dirList = vfs.listdir(profilesFolder, ext);
182-
183-
for (vfs::DirectoryEntry ent : dirList) {
184-
if (ent.attributes != vfs::FileAttributes::Directory) {
185-
profileFiles.push_back(std::string(profilesFolder) + "/" + ent.fileName);
186-
}
187-
}
188-
189-
LOG_INFO("Total number of profiles: %u", static_cast<unsigned int>(profileFiles.size()));
190-
return profileFiles;
191-
}
192-
193-
void init()
194-
{
195-
std::vector<std::string> profileFiles = getProfilesList(".kprof");
196-
for (std::string mapName : profileFiles) {
197-
if (std::size(mapName)) {
198-
loadProfile(mapName);
199-
}
200-
}
201-
if (std::size(profiles) == 0) {
202-
LOG_ERROR("No keyboard profiles loaded");
203-
}
204-
}
205-
Profile empty;
206-
207-
public:
208-
static Profiles &get()
209-
{
210-
static Profiles *p;
211-
if (p == nullptr) {
212-
p = new Profiles();
213-
p->init();
214-
}
215-
return *p;
216-
}
217-
218-
static Profile &get(const std::string &name)
219-
{
220-
// if profile not in profile map -> load
221-
if (std::size(name) == 0) {
222-
LOG_ERROR("Request for non existend profile: %s", name.c_str());
223-
return get().empty;
224-
}
225-
if (get().profiles.find(name) == get().profiles.end()) {
226-
get().loadProfile(name);
227-
}
228-
return get().profiles[name];
229-
}
230-
};
231-
232161
uint32_t KeyInputMappedTranslation::handle(RawKey key, const std::string &keymap)
233162
{
234163
// get shortpress

module-gui/gui/input/Translator.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010
#include <vector>
1111
#include <common_data/RawKey.hpp>
12+
#include <vfs.hpp>
1213

1314
namespace gui
1415
{
@@ -61,4 +62,75 @@ namespace gui
6162
}
6263
};
6364

65+
/// profiles cache - load once for all
66+
class Profiles
67+
{
68+
private:
69+
const char *profilesFolder = "assets/profiles";
70+
std::map<std::string, gui::Profile> profiles = {};
71+
72+
void loadProfile(const std::string &filepath)
73+
{
74+
LOG_INFO("Load profile: %s", filepath.c_str());
75+
auto p = Profile(filepath);
76+
if (p.getName() != std::string()) {
77+
profiles.insert({p.getName(), std::move(p)});
78+
}
79+
}
80+
81+
std::vector<std::string> getProfilesList(std::string ext)
82+
{
83+
std::vector<std::string> profileFiles;
84+
LOG_INFO("Scanning %s profiles folder: %s", ext.c_str(), profilesFolder);
85+
auto dirList = vfs.listdir(profilesFolder, ext);
86+
87+
for (vfs::DirectoryEntry ent : dirList) {
88+
if (ent.attributes != vfs::FileAttributes::Directory) {
89+
profileFiles.push_back(std::string(profilesFolder) + "/" + ent.fileName);
90+
}
91+
}
92+
93+
LOG_INFO("Total number of profiles: %u", static_cast<unsigned int>(profileFiles.size()));
94+
return profileFiles;
95+
}
96+
97+
void init()
98+
{
99+
std::vector<std::string> profileFiles = getProfilesList(".kprof");
100+
for (std::string mapName : profileFiles) {
101+
if (std::size(mapName)) {
102+
loadProfile(mapName);
103+
}
104+
}
105+
if (std::size(profiles) == 0) {
106+
LOG_ERROR("No keyboard profiles loaded");
107+
}
108+
}
109+
Profile empty;
110+
111+
public:
112+
static Profiles &get()
113+
{
114+
static Profiles *p;
115+
if (p == nullptr) {
116+
p = new Profiles();
117+
p->init();
118+
}
119+
return *p;
120+
}
121+
122+
static Profile &get(const std::string &name)
123+
{
124+
// if profile not in profile map -> load
125+
if (std::size(name) == 0) {
126+
LOG_ERROR("Request for non existend profile: %s", name.c_str());
127+
return get().empty;
128+
}
129+
if (get().profiles.find(name) == get().profiles.end()) {
130+
get().loadProfile(name);
131+
}
132+
return get().profiles[name];
133+
}
134+
};
135+
64136
} /* namespace gui */

module-gui/gui/widgets/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ target_sources( ${PROJECT_NAME}
55
"${CMAKE_CURRENT_LIST_DIR}/Arc.cpp"
66
"${CMAKE_CURRENT_LIST_DIR}/BottomBar.cpp"
77
"${CMAKE_CURRENT_LIST_DIR}/CheckBox.cpp"
8-
"${CMAKE_CURRENT_LIST_DIR}/Circle.cpp"
8+
"${CMAKE_CURRENT_LIST_DIR}/Circle.cpp"
99
"${CMAKE_CURRENT_LIST_DIR}/Icon.cpp"
1010
"${CMAKE_CURRENT_LIST_DIR}/Image.cpp"
11-
"${CMAKE_CURRENT_LIST_DIR}/ImageBox.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/ImageBox.cpp"
1212
"${CMAKE_CURRENT_LIST_DIR}/Item.cpp"
1313
"${CMAKE_CURRENT_LIST_DIR}/Label.cpp"
1414
"${CMAKE_CURRENT_LIST_DIR}/ListItem.cpp"
@@ -36,6 +36,8 @@ target_sources( ${PROJECT_NAME}
3636
"${CMAKE_CURRENT_LIST_DIR}/Style.cpp"
3737
"${CMAKE_CURRENT_LIST_DIR}/InputMode.cpp"
3838
"${CMAKE_CURRENT_LIST_DIR}/GridLayout.cpp"
39+
"${CMAKE_CURRENT_LIST_DIR}/Lines.cpp"
40+
"${CMAKE_CURRENT_LIST_DIR}/TextLineCursor.cpp"
3941
"${CMAKE_CURRENT_LIST_DIR}/RichTextParser.cpp"
4042
"${CMAKE_CURRENT_LIST_DIR}/TextFormat.cpp"
4143
"${CMAKE_CURRENT_LIST_DIR}/CheckBoxWithLabel.cpp"
@@ -45,7 +47,8 @@ target_sources( ${PROJECT_NAME}
4547
"${CMAKE_CURRENT_LIST_DIR}/BottomBar.hpp"
4648
"${CMAKE_CURRENT_LIST_DIR}/Circle.hpp"
4749
"${CMAKE_CURRENT_LIST_DIR}/Image.hpp"
48-
"${CMAKE_CURRENT_LIST_DIR}/ImageBox.hpp"
50+
"${CMAKE_CURRENT_LIST_DIR}/ImageBox.hpp"
51+
"${CMAKE_CURRENT_LIST_DIR}/TextFixedSize.hpp"
4952
"${CMAKE_CURRENT_LIST_DIR}/Item.hpp"
5053
"${CMAKE_CURRENT_LIST_DIR}/Label.hpp"
5154
"${CMAKE_CURRENT_LIST_DIR}/ListItem.hpp"
@@ -62,5 +65,8 @@ target_sources( ${PROJECT_NAME}
6265
"${CMAKE_CURRENT_LIST_DIR}/TopBar.hpp"
6366
"${CMAKE_CURRENT_LIST_DIR}/Text.hpp"
6467
"${CMAKE_CURRENT_LIST_DIR}/CheckBoxWithLabel.hpp"
68+
"${CMAKE_CURRENT_LIST_DIR}/CheckBoxWithLabel.hpp"
69+
"${CMAKE_CURRENT_LIST_DIR}/Lines.hpp"
70+
"${CMAKE_CURRENT_LIST_DIR}/TextLineCursor.hpp"
6571
)
6672

module-gui/gui/widgets/Item.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace gui
274274
}
275275
}
276276

277-
Padding Item::getPadding()
277+
Padding Item::getPadding() const
278278
{
279279
return padding;
280280
}

module-gui/gui/widgets/Item.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ namespace gui
4545
HBOX
4646
};
4747

48-
NavigationDirection inputToNavigation(const InputEvent &evt);
49-
5048
class Item
5149
{
5250
private:
@@ -224,7 +222,7 @@ namespace gui
224222
[[nodiscard]] Margins getMargins();
225223

226224
virtual void setPadding(const Padding &value);
227-
[[nodiscard]] Padding getPadding();
225+
[[nodiscard]] Padding getPadding() const;
228226

229227
virtual void setAlignment(const Alignment &value);
230228
[[nodiscard]] Alignment &getAlignment();
@@ -293,6 +291,7 @@ namespace gui
293291
virtual void clearNavigationItem(gui::NavigationDirection direction);
294292

295293
Item();
294+
Item(Item &) = delete;
296295
virtual ~Item();
297296

298297
/// @defgroup inconsistent inconsistent size/offset accessors and setters
@@ -353,4 +352,6 @@ namespace gui
353352
gui::Navigation *navigationDirections = nullptr;
354353
};
355354

355+
NavigationDirection inputToNavigation(const InputEvent &evt);
356+
356357
} /* namespace gui */

0 commit comments

Comments
 (0)