Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-28 01:54:37 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-28 01:54:37 +1000
commit326bc7266d38eb94d75e8f08d2b5733c3d051c2e (patch)
tree3664941a9a6cdb1d4f20477e93f14a2189501547
parentcd497bbcf399bcfa17694725583cefd93bff65d9 (diff)
Fix text box cursor offset with hidden text
-rw-r--r--assets/opensb/interface/windowconfig/multiplayer.config.patch3
-rw-r--r--source/windowing/StarGuiContext.cpp1
-rw-r--r--source/windowing/StarTextBoxWidget.cpp18
3 files changed, 18 insertions, 4 deletions
diff --git a/assets/opensb/interface/windowconfig/multiplayer.config.patch b/assets/opensb/interface/windowconfig/multiplayer.config.patch
index 8830e54..b32d8c8 100644
--- a/assets/opensb/interface/windowconfig/multiplayer.config.patch
+++ b/assets/opensb/interface/windowconfig/multiplayer.config.patch
@@ -1,5 +1,6 @@
{
"password" : {
- "hidden" : true
+ "hidden" : true,
+ "hAnchor" : "right"
}
} \ No newline at end of file
diff --git a/source/windowing/StarGuiContext.cpp b/source/windowing/StarGuiContext.cpp
index a19d684..e080ecf 100644
--- a/source/windowing/StarGuiContext.cpp
+++ b/source/windowing/StarGuiContext.cpp
@@ -385,6 +385,7 @@ int GuiContext::stringWidth(String const& s) {
return textPainter()->stringWidth(s);
}
+//TODO: Make this use StringView
int GuiContext::stringInterfaceWidth(String const& s) {
if (interfaceScale()) {
// font size is already adjusted UP by interfaceScale, so we have to adjust
diff --git a/source/windowing/StarTextBoxWidget.cpp b/source/windowing/StarTextBoxWidget.cpp
index 0622d89..03d2ae9 100644
--- a/source/windowing/StarTextBoxWidget.cpp
+++ b/source/windowing/StarTextBoxWidget.cpp
@@ -102,14 +102,26 @@ int TextBoxWidget::getCursorOffset() { // horizontal only
scale = 0.5;
} else if (m_hAnchor == HorizontalAnchor::RightAnchor) {
scale = -1.0;
- return context()->stringInterfaceWidth(m_text) * scale
- + context()->stringInterfaceWidth(m_text.substr(m_cursorOffset, m_text.size()));
+ if (m_textHidden) {
+ int width = context()->stringInterfaceWidth("*");
+ size_t chars = m_text.size();
+ return (width * chars) * scale + (width * (chars - m_cursorOffset));
+ } else {
+ return context()->stringInterfaceWidth(m_text) * scale
+ + context()->stringInterfaceWidth(m_text.substr(m_cursorOffset, m_text.size()));
+ }
} else {
throw GuiException("Somehow, the value of m_hAnchor became bad");
}
+ if (m_textHidden) {
+ int width = context()->stringInterfaceWidth("*");
+ size_t chars = m_text.size();
+ return (int)std::ceil((width * chars) * scale - (width * (chars - m_cursorOffset)));
+ } else {
return (int)std::ceil(context()->stringInterfaceWidth(m_text) * scale
- - context()->stringInterfaceWidth(m_text.substr(m_cursorOffset, m_text.size())));
+ - context()->stringInterfaceWidth(m_text.substr(m_cursorOffset, m_text.size())));
+ }
}
void TextBoxWidget::update() {