Fix text overflowing in select and text box

This commit is contained in:
TotallyNotElite 2019-04-28 14:37:48 +02:00
parent 4cbeaa6e64
commit 22bd69f415
2 changed files with 48 additions and 4 deletions

View File

@ -34,7 +34,28 @@ void zerokernel::Select::render()
}
renderBorder(*color_border);
text.set(found ? found->name : "<?>");
std::string t;
if (found)
{
float x, y;
t = found->name;
resource::font::base.stringSize(t, &x, &y);
if (x + 5 > bb.getBorderBox().width)
{
while (true)
{
resource::font::base.stringSize(t, &x, &y);
if (x + 13 > bb.getBorderBox().width)
{
t = t.substr(0, t.size() - 1);
}
else
break;
}
t.append("..");
}
}
text.set(found ? t : "<?>");
text.render();
}
else
@ -67,11 +88,17 @@ void zerokernel::Select::openModal()
object->setParent(Menu::instance->wm.get());
object->move(bb.getBorderBox().x, bb.getBorderBox().y);
object->addMessageHandler(*this);
object->resize(bb.getBorderBox().width, -1);
int size = bb.getBorderBox().width;
for (auto &p : options)
{
object->addOption(p.name, p.value, p.tooltip);
float x, y;
resource::font::base.stringSize(p.name, &x, &y);
x += 10;
if (x > size)
size = x;
}
object->resize(size, -1);
debug::UiTreeGraph(object.get(), 0);
Menu::instance->addModalObject(std::move(object));
}
@ -118,7 +145,7 @@ void zerokernel::Select::loadFromXml(const tinyxml2::XMLElement *data)
printf("adding %s: %s\n", name, value);
auto has_tooltip = !(child->QueryStringAttribute("tooltip", &tooltip));
options.push_back(option{ name, value, has_tooltip ? std::optional<std::string>(tooltip) : std::nullopt });
};
}
child = child->NextSiblingElement(nullptr);
}
}

View File

@ -94,7 +94,24 @@ void zerokernel::TextInput::render()
else
{
text_object.setColorText(&*color_text);
text_object.set(getValue());
float x, y;
std::string t = getValue();
resource::font::base.stringSize(t, &x, &y);
if (x + 5 > bb.getBorderBox().width)
{
while (true)
{
resource::font::base.stringSize(t, &x, &y);
if (x + 13 > bb.getBorderBox().width)
{
t = t.substr(0, t.size() - 1);
}
else
break;
}
t.append("..");
}
text_object.set(t);
}
text_object.render();
}