Skip to content

Commit

Permalink
Anchor menu help text to the screen bottom to fix cropping of long text
Browse files Browse the repository at this point in the history
Fix cropping of more than 4 line menu item help texts by anchoring
the bottom of the help text display to the bottom of the screen.
This prevents the help text from growing off of the screen when
the help text is long.
  • Loading branch information
James De Ricco committed Nov 26, 2023
1 parent 6ed9aec commit a254832
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/gui/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,12 @@ Menu::draw(DrawingContext& context)
const int text_width = static_cast<int>(Resources::normal_font->get_text_width(m_items[m_active_item]->get_help()));
const int text_height = static_cast<int>(Resources::normal_font->get_text_height(m_items[m_active_item]->get_help()));

const float margin_y = 16.0f;

const Rectf text_rect(m_pos.x - static_cast<float>(text_width) / 2.0f - 8.0f,
static_cast<float>(SCREEN_HEIGHT) - 48.0f - static_cast<float>(text_height) / 2.0f - 4.0f,
static_cast<float>(SCREEN_HEIGHT) - margin_y - static_cast<float>(text_height) - 4.0f,
m_pos.x + static_cast<float>(text_width) / 2.0f + 8.0f,
static_cast<float>(SCREEN_HEIGHT) - 48.0f + static_cast<float>(text_height) / 2.0f + 4.0f);
static_cast<float>(SCREEN_HEIGHT) - margin_y + 4.0f);

context.color().draw_filled_rect(Rectf(text_rect.p1() - Vector(4,4),
text_rect.p2() + Vector(4,4)),
Expand All @@ -614,7 +616,7 @@ Menu::draw(DrawingContext& context)
LAYER_GUI);

context.color().draw_text(Resources::normal_font, m_items[m_active_item]->get_help(),
Vector(m_pos.x, static_cast<float>(SCREEN_HEIGHT) - 48.0f - static_cast<float>(text_height) / 2.0f),
Vector(m_pos.x, static_cast<float>(SCREEN_HEIGHT) - margin_y - static_cast<float>(text_height)),
ALIGN_CENTER, LAYER_GUI);
}
}
Expand Down

0 comments on commit a254832

Please sign in to comment.