forked from Mirror/libstarlight
InputHandler backend for onscreen keyboards, app:/ asset loading
This commit is contained in:
parent
abc3eac3e1
commit
588817acc6
@ -13,6 +13,8 @@
|
||||
|
||||
#include "starlight/ConfigManager.h"
|
||||
|
||||
#include "starlight/Application.h"
|
||||
|
||||
#include "starlight/gfx/DrawableImage.h"
|
||||
#include "starlight/gfx/DrawableNinePatch.h"
|
||||
#include "starlight/gfx/DrawableTest.h"
|
||||
@ -263,6 +265,19 @@ string ThemeManager::ResolveAssetPath(const string& id) {
|
||||
if (id.compare(0, pfxLocal.length(), pfxLocal) == 0) {
|
||||
// app-local asset
|
||||
// check if present in theme/app/[appname]/, else check in romfs
|
||||
for (auto thm : themeData) {
|
||||
Path bp = thm.basePath.Combine("app").Combine(Application::AppName());
|
||||
Path p = bp.Combine(id+".json");
|
||||
if (p.IsFile()) return p;
|
||||
p = bp.Combine(id+".png");
|
||||
if (p.IsFile()) return p;
|
||||
}
|
||||
// TBD - directly in romfs, or in an assets folder?
|
||||
Path bp = Path("romfs:");
|
||||
Path p = bp.Combine(id+".json");
|
||||
if (p.IsFile()) return p;
|
||||
p = bp.Combine(id+".png");
|
||||
if (p.IsFile()) return p;
|
||||
}
|
||||
else {
|
||||
// theme asset; check in each theme from selected to most-fallback
|
||||
|
@ -23,10 +23,9 @@ using starlight::ui::Form;
|
||||
|
||||
using starlight::dialog::OSK;
|
||||
|
||||
OSK::OSK(std::string* textptr, std::function<void()> onModify) : Form(true) {
|
||||
OSK::OSK(osk::InputHandler* handler) : Form(true), handler(handler) {
|
||||
priority = 1000; // probably don't want all that much displaying above the keyboard
|
||||
eOnModify = onModify;
|
||||
pText = textptr;
|
||||
handler->parent = this;
|
||||
|
||||
auto cover = std::make_shared<Image>(touchScreen->rect.Expand(4), "decorations/dialog.modal-cover");
|
||||
cover->blockTouch = true;
|
||||
@ -38,7 +37,7 @@ OSK::OSK(std::string* textptr, std::function<void()> onModify) : Form(true) {
|
||||
touchScreen->Add(setContainer);
|
||||
|
||||
auto actSym = [this](Button& key){
|
||||
this->OnSymKey(key.label);
|
||||
this->handler->InputSymbol(key.label);
|
||||
};
|
||||
|
||||
Vector2 bs(24, 32);
|
||||
@ -80,19 +79,21 @@ OSK::OSK(std::string* textptr, std::function<void()> onModify) : Form(true) {
|
||||
auto key = std::make_shared<Button>(VRect(bpen, bs));
|
||||
key->rect.size.x *= 1.25;
|
||||
key->SetText("< <");
|
||||
key->eOnTap = [this](auto& btn){ this->handler->Backspace(); };
|
||||
touchScreen->Add(key);
|
||||
|
||||
bpen = bpstart + bs * Vector2(linestart[4] + 8, 4);
|
||||
key = std::make_shared<Button>(VRect(bpen, bs));
|
||||
key->rect.size.x *= 2.5;
|
||||
key->SetText("Enter");
|
||||
key->eOnTap = [this](auto& btn){ this->handler->Enter(); };
|
||||
touchScreen->Add(key);
|
||||
|
||||
}
|
||||
|
||||
void OSK::Update(bool focused) {
|
||||
if (focused) {
|
||||
if (InputManager::Pressed(Keys::B)) Close();
|
||||
if (InputManager::Pressed(Keys::B)) handler->Done();
|
||||
|
||||
float& s = setContainer->scrollOffset.y;
|
||||
float ts = 0;
|
||||
@ -107,10 +108,10 @@ void OSK::Update(bool focused) {
|
||||
}
|
||||
|
||||
void OSK::OnSymKey(const string& chr) {
|
||||
pText->append(chr);
|
||||
//pText->append(chr);
|
||||
//pText->append("sackboy ");
|
||||
//auto& tx = *pText;
|
||||
//ConfigManager::Get("user").Json()["log"].push_back(*pText);
|
||||
//tx.assign("shickaxe");
|
||||
if (eOnModify) eOnModify();
|
||||
//if (eOnModify) eOnModify();
|
||||
}
|
||||
|
@ -3,9 +3,12 @@
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "starlight/ui/Form.h"
|
||||
|
||||
#include "starlight/dialog/osk/InputHandler.h"
|
||||
|
||||
namespace starlight {
|
||||
namespace dialog {
|
||||
class OSK : public ui::Form, public ui::FormCreator<OSK> {
|
||||
@ -13,11 +16,9 @@ namespace starlight {
|
||||
std::shared_ptr<ui::UIContainer> setContainer;
|
||||
|
||||
public:
|
||||
std::string* pText = nullptr;
|
||||
std::unique_ptr<osk::InputHandler> handler;
|
||||
|
||||
std::function<void()> eOnModify;
|
||||
|
||||
OSK(std::string* textptr, std::function<void()> onModify = {});
|
||||
OSK(osk::InputHandler* handler);
|
||||
~OSK() override { };
|
||||
|
||||
void Update(bool focused) override;
|
||||
|
53
libstarlight/source/starlight/dialog/osk/InputHandler.cpp
Normal file
53
libstarlight/source/starlight/dialog/osk/InputHandler.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "InputHandler.h"
|
||||
|
||||
#include "starlight/ui/Form.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
using starlight::dialog::osk::InputHandler;
|
||||
using starlight::dialog::osk::InputHandlerDirectEdit;
|
||||
using starlight::dialog::osk::InputHandlerBuffered;
|
||||
|
||||
// DirectEdit
|
||||
|
||||
void InputHandlerDirectEdit::InputSymbol(const string& sym) {
|
||||
pText->append(sym);
|
||||
if (eOnModify) eOnModify();
|
||||
}
|
||||
|
||||
void InputHandlerDirectEdit::Backspace() {
|
||||
if (pText->length() > minIndex) {
|
||||
pText->pop_back();
|
||||
if (eOnModify) eOnModify();
|
||||
}
|
||||
}
|
||||
|
||||
void InputHandlerDirectEdit::Enter() {
|
||||
if (multiLine) InputSymbol("\n");
|
||||
else Done();
|
||||
}
|
||||
|
||||
void InputHandlerDirectEdit::Done() {
|
||||
if (eOnFinalize) eOnFinalize();
|
||||
parent->Close();
|
||||
}
|
||||
|
||||
// Buffered
|
||||
|
||||
void InputHandlerBuffered::InputSymbol(const string& sym) {
|
||||
buffer.append(sym);
|
||||
}
|
||||
|
||||
void InputHandlerBuffered::Backspace() {
|
||||
buffer.pop_back();
|
||||
}
|
||||
|
||||
void InputHandlerBuffered::Enter() {
|
||||
if (multiLine) InputSymbol("\n");
|
||||
else Done();
|
||||
}
|
||||
|
||||
void InputHandlerBuffered::Done() {
|
||||
if (eOnFinalize) eOnFinalize(buffer);
|
||||
parent->Close();
|
||||
}
|
72
libstarlight/source/starlight/dialog/osk/InputHandler.h
Normal file
72
libstarlight/source/starlight/dialog/osk/InputHandler.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include "starlight/_global.h"
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace starlight {
|
||||
// forward declare...
|
||||
namespace ui {
|
||||
class Form;
|
||||
}
|
||||
|
||||
namespace dialog {
|
||||
namespace osk {
|
||||
|
||||
class InputHandler {
|
||||
public:
|
||||
bool showPreview = false;
|
||||
ui::Form* parent;
|
||||
|
||||
InputHandler() = default;
|
||||
virtual ~InputHandler() = default;
|
||||
|
||||
virtual void InputSymbol(const std::string& sym) { }
|
||||
virtual void Backspace() { }
|
||||
virtual void Enter() { }
|
||||
|
||||
virtual void Done() { }
|
||||
};
|
||||
|
||||
class InputHandlerDirectEdit : public InputHandler {
|
||||
public:
|
||||
bool multiLine = false;
|
||||
|
||||
std::string* pText;
|
||||
unsigned int minIndex = 0;
|
||||
|
||||
std::function<void()> eOnModify = {};
|
||||
std::function<void()> eOnFinalize = {};
|
||||
|
||||
InputHandlerDirectEdit(std::string* textptr, bool multiLine = false, unsigned int minIndex = 0, std::function<void()> onModify = {}, std::function<void()> onFinalize = {})
|
||||
: multiLine(multiLine), pText(textptr), minIndex(minIndex), eOnModify(onModify), eOnFinalize(onFinalize) { }
|
||||
~InputHandlerDirectEdit() override { }
|
||||
|
||||
void InputSymbol(const std::string& sym) override;
|
||||
void Backspace() override;
|
||||
void Enter() override;
|
||||
|
||||
void Done() override;
|
||||
};
|
||||
|
||||
class InputHandlerBuffered : public InputHandler {
|
||||
std::string buffer = "";
|
||||
public:
|
||||
bool multiLine = false;
|
||||
|
||||
std::function<void(const std::string&)> eOnFinalize = { };
|
||||
|
||||
InputHandlerBuffered(const std::string& text = "", bool multiLine = false, std::function<void(const std::string&)> onFinalize = {})
|
||||
: showPreview(true), buffer(text), multiLine(multiLine), eOnFinalize(onFinalize) { }
|
||||
~InputHandlerBuffered() override { }
|
||||
|
||||
void InputSymbol(const std::string& sym) override;
|
||||
void Backspace() override;
|
||||
void Enter() override;
|
||||
|
||||
void Done() override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -2,15 +2,15 @@
|
||||
|
||||
|
||||
roadmap to first release, in no particular order {
|
||||
make more stuff use theme metrics {
|
||||
dialog layouts(...?)
|
||||
}
|
||||
- implement app:/ asset loading
|
||||
finish implementing OSK! {
|
||||
make backspace and enter actually do something
|
||||
abstract osk input actions into a separate object/class heirarchy
|
||||
- make backspace and enter actually do something
|
||||
- abstract osk input actions into a separate object/class heirarchy
|
||||
preview where applicable
|
||||
polish!
|
||||
InputManager::OpenKeyboard
|
||||
}
|
||||
textbox widget
|
||||
|
||||
add license!! (MIT?)
|
||||
ADD README.MD PLS
|
||||
|
@ -72,7 +72,8 @@ void Core::Init() {
|
||||
tlbl->textConfig.borderColor = Color::black;
|
||||
tlbl->SetText("3DS:~# ");
|
||||
form->topScreen->Add(tlbl);
|
||||
auto kb = sl::dialog::OSK::New(&(tlbl->text), [tlbl](){tlbl->Refresh();});
|
||||
auto kb = sl::dialog::OSK::New(new sl::dialog::osk::InputHandlerDirectEdit(&(tlbl->text), true, 7, [tlbl](){tlbl->Refresh();}));
|
||||
//&(tlbl->text), [tlbl](){tlbl->Refresh();});
|
||||
kb->Open();
|
||||
|
||||
/*label->SetFont("default.16");
|
||||
|
Loading…
x
Reference in New Issue
Block a user