UI: Mobile keyboard fixes, safe area padding, & more

This commit is contained in:
Luke Street
2026-04-30 00:06:27 -06:00
parent b86d6e90e2
commit 4a12554bf4
8 changed files with 152 additions and 11 deletions
+28 -6
View File
@@ -1,5 +1,7 @@
#include "string_button.hpp"
#include <aurora/rmlui.hpp>
namespace dusk::ui {
BaseStringButton::BaseStringButton(Rml::Element* parent, Props props)
@@ -12,6 +14,12 @@ void BaseStringButton::update() {
if (mPendingStopEditing) {
stop_editing(mPendingCommit, mPendingRefocusRoot);
}
if (mPendingInputFocusFrames > 0) {
--mPendingInputFocusFrames;
if (mPendingInputFocusFrames == 0) {
focus_input();
}
}
ControlledSelectButton::update();
}
@@ -37,10 +45,9 @@ void BaseStringButton::start_editing() {
// Hide value element
mValueElem->SetProperty(Rml::PropertyId::Visibility, Rml::Style::Visibility::Hidden);
// Focus and select text within input
mInputElem->Focus(true);
const int end = static_cast<int>(Rml::StringUtilities::LengthUTF8(mInputElem->GetValue()));
mInputElem->SetSelectionRange(0, end);
// RmlUi lays out the new input during render. Wait one full frame before focusing it so
// mobile keyboard placement gets a valid caret rectangle.
mPendingInputFocusFrames = 2;
// Mark button as selected to indicate "active"
set_selected(true);
@@ -84,11 +91,26 @@ bool BaseStringButton::handle_nav_command(NavCommand cmd) {
return false;
}
void BaseStringButton::stop_editing(bool commit, bool refocusRoot) {
void BaseStringButton::focus_input() {
if (mInputElem == nullptr) {
return;
}
aurora::rmlui::set_input_type(
mType == "number" ? aurora::rmlui::InputType::Number : aurora::rmlui::InputType::Text);
if (mInputElem->Focus(true)) {
const int end = static_cast<int>(Rml::StringUtilities::LengthUTF8(mInputElem->GetValue()));
mInputElem->SetSelectionRange(0, end);
}
}
void BaseStringButton::stop_editing(bool commit, bool refocusRoot) {
mPendingStopEditing = false;
mPendingInputFocusFrames = 0;
if (mInputElem == nullptr) {
return;
}
if (commit) {
set_value(mInputElem->GetValue());
}
@@ -109,4 +131,4 @@ StringButton::StringButton(Rml::Element* parent, Props props)
: BaseStringButton(parent, {.key = std::move(props.key), .maxLength = props.maxLength}),
mGetValue(std::move(props.getValue)), mSetValue(std::move(props.setValue)) {}
} // namespace dusk::ui
} // namespace dusk::ui