Make sure long messages overlaid on framebuffer don't overflow display surface.

This commit is contained in:
Stephen Anthony 2020-06-19 19:55:27 -02:30
parent fcff01df3c
commit eafa29a520
2 changed files with 5 additions and 4 deletions

View File

@ -513,7 +513,8 @@ void FrameBuffer::showMessage(const string& message, MessagePosition position,
myMsg.text = message;
myMsg.color = kBtnTextColor;
myMsg.showGauge = false;
myMsg.w = font().getStringWidth(myMsg.text) + HBORDER * 2;
myMsg.w = std::min(fontWidth * (MESSAGE_WIDTH) - HBORDER * 2,
font().getStringWidth(myMsg.text) + HBORDER * 2);
myMsg.h = fontHeight + VBORDER * 2;
myMsg.position = position;
myMsg.enabled = true;
@ -533,7 +534,7 @@ void FrameBuffer::showMessage(const string& message, const string& valueText,
return;
const int fontWidth = font().getMaxCharWidth(),
fontHeight = font().getFontHeight();
fontHeight = font().getFontHeight();
const int VBORDER = fontHeight / 4;
const int HBORDER = fontWidth * 1.25 / 2.0;
@ -565,7 +566,7 @@ void FrameBuffer::showMessage(const string& message, const string& valueText,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBuffer::messageShown()
bool FrameBuffer::messageShown() const
{
#ifdef GUI_SUPPORT
return myMsg.enabled;

View File

@ -166,7 +166,7 @@ class FrameBuffer
void showMessage(const string& message, const string& valueText,
float value, float minValue = 0.F, float maxValue = 100.F);
bool messageShown();
bool messageShown() const;
/**
Toggles showing or hiding framerate statistics.