mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 20:27:31 +08:00
Fix input. (#188)
Instead of wrapping WideInputBase by composition, wrap it by inheritance. This resolve the focus that was broken.
This commit is contained in:
parent
79b8928f6e
commit
70cf088d6a
@ -181,36 +181,33 @@ class WideInputBase : public ComponentBase {
|
|||||||
// WideInputBase.
|
// WideInputBase.
|
||||||
// TODO(arthursonzogni): Provide an implementation handling std::string natively
|
// TODO(arthursonzogni): Provide an implementation handling std::string natively
|
||||||
// and adds better support for combining characters.
|
// and adds better support for combining characters.
|
||||||
class InputBase : public ComponentBase {
|
class InputBase : public WideInputBase {
|
||||||
public:
|
public:
|
||||||
InputBase(StringRef content,
|
InputBase(StringRef content,
|
||||||
ConstStringRef placeholder,
|
ConstStringRef placeholder,
|
||||||
Ref<InputOption> option)
|
Ref<InputOption> option)
|
||||||
: content_(std::move(content)),
|
: WideInputBase(&wrapped_content_,
|
||||||
wrapped_content_(to_wstring(*content_)),
|
std::move(placeholder),
|
||||||
wrapped_input_(&wrapped_content_,
|
std::move(option)),
|
||||||
std::move(placeholder),
|
content_(std::move(content)),
|
||||||
std::move(option)) {}
|
wrapped_content_(to_wstring(*content_)) {}
|
||||||
|
|
||||||
Element Render() override {
|
Element Render() override {
|
||||||
wrapped_content_ = to_wstring(*content_);
|
wrapped_content_ = to_wstring(*content_);
|
||||||
return wrapped_input_.Render();
|
return WideInputBase::Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnEvent(Event event) override {
|
bool OnEvent(Event event) override {
|
||||||
wrapped_content_ = to_wstring(*content_);
|
wrapped_content_ = to_wstring(*content_);
|
||||||
if (wrapped_input_.OnEvent(event)) {
|
if (WideInputBase::OnEvent(event)) {
|
||||||
*content_ = to_string(wrapped_content_);
|
*content_ = to_string(wrapped_content_);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Focusable() const final { return true; }
|
|
||||||
|
|
||||||
StringRef content_;
|
StringRef content_;
|
||||||
std::wstring wrapped_content_;
|
std::wstring wrapped_content_;
|
||||||
WideInputBase wrapped_input_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief An input box for editing text.
|
/// @brief An input box for editing text.
|
||||||
|
Loading…
Reference in New Issue
Block a user