mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-18 07:05:39 +00:00
Can now specify font for MenuComponent's title.
This commit is contained in:
parent
c7434c52fd
commit
d0416f8634
|
@ -4,9 +4,11 @@
|
||||||
#define BUTTON_GRID_VERT_PADDING 32
|
#define BUTTON_GRID_VERT_PADDING 32
|
||||||
#define BUTTON_GRID_HORIZ_PADDING 10
|
#define BUTTON_GRID_HORIZ_PADDING 10
|
||||||
|
|
||||||
|
#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight()*0.0637f)
|
||||||
|
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
|
|
||||||
MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(window),
|
MenuComponent::MenuComponent(Window* window, const char* title, const std::shared_ptr<Font>& titleFont) : GuiComponent(window),
|
||||||
mBackground(window), mGrid(window, Vector2i(1, 3))
|
mBackground(window), mGrid(window, Vector2i(1, 3))
|
||||||
{
|
{
|
||||||
addChild(&mBackground);
|
addChild(&mBackground);
|
||||||
|
@ -14,8 +16,11 @@ MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(w
|
||||||
|
|
||||||
mBackground.setImagePath(":/frame.png");
|
mBackground.setImagePath(":/frame.png");
|
||||||
|
|
||||||
// set up title which will never change
|
// set up title
|
||||||
mTitle = std::make_shared<TextComponent>(mWindow, strToUpper(title), Font::get(FONT_SIZE_LARGE), 0x555555FF, TextComponent::ALIGN_CENTER);
|
mTitle = std::make_shared<TextComponent>(mWindow);
|
||||||
|
mTitle->setAlignment(TextComponent::ALIGN_CENTER);
|
||||||
|
mTitle->setColor(0x555555FF);
|
||||||
|
setTitle(title, titleFont);
|
||||||
mGrid.setEntry(mTitle, Vector2i(0, 0), false);
|
mGrid.setEntry(mTitle, Vector2i(0, 0), false);
|
||||||
|
|
||||||
// set up list which will never change (externally, anyway)
|
// set up list which will never change (externally, anyway)
|
||||||
|
@ -28,6 +33,12 @@ MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(w
|
||||||
mGrid.resetCursor();
|
mGrid.resetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuComponent::setTitle(const char* title, const std::shared_ptr<Font>& font)
|
||||||
|
{
|
||||||
|
mTitle->setText(strToUpper(title));
|
||||||
|
mTitle->setFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
float MenuComponent::getButtonGridHeight() const
|
float MenuComponent::getButtonGridHeight() const
|
||||||
{
|
{
|
||||||
return (mButtonGrid ? mButtonGrid->getSize().y() : Font::get(FONT_SIZE_MEDIUM)->getHeight() + BUTTON_GRID_VERT_PADDING);
|
return (mButtonGrid ? mButtonGrid->getSize().y() : Font::get(FONT_SIZE_MEDIUM)->getHeight() + BUTTON_GRID_VERT_PADDING);
|
||||||
|
@ -35,7 +46,7 @@ float MenuComponent::getButtonGridHeight() const
|
||||||
|
|
||||||
void MenuComponent::updateSize()
|
void MenuComponent::updateSize()
|
||||||
{
|
{
|
||||||
float height = mTitle->getSize().y() + mList->getTotalRowHeight() + getButtonGridHeight() + 2;
|
float height = TITLE_HEIGHT + mList->getTotalRowHeight() + getButtonGridHeight() + 2;
|
||||||
if(height > Renderer::getScreenHeight() * 0.7f)
|
if(height > Renderer::getScreenHeight() * 0.7f)
|
||||||
height = Renderer::getScreenHeight() * 0.7f;
|
height = Renderer::getScreenHeight() * 0.7f;
|
||||||
|
|
||||||
|
@ -47,7 +58,7 @@ void MenuComponent::onSizeChanged()
|
||||||
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32));
|
||||||
|
|
||||||
// update grid row/col sizes
|
// update grid row/col sizes
|
||||||
mGrid.setRowHeightPerc(0, mTitle->getSize().y() / mSize.y());
|
mGrid.setRowHeightPerc(0, TITLE_HEIGHT / mSize.y());
|
||||||
mGrid.setRowHeightPerc(2, getButtonGridHeight() / mSize.y());
|
mGrid.setRowHeightPerc(2, getButtonGridHeight() / mSize.y());
|
||||||
|
|
||||||
mGrid.setSize(mSize);
|
mGrid.setSize(mSize);
|
||||||
|
|
|
@ -15,7 +15,7 @@ std::shared_ptr<ImageComponent> makeArrow(Window* window);
|
||||||
class MenuComponent : public GuiComponent
|
class MenuComponent : public GuiComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MenuComponent(Window* window, const char* title);
|
MenuComponent(Window* window, const char* title, const std::shared_ptr<Font>& titleFont = Font::get(FONT_SIZE_LARGE));
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ public:
|
||||||
|
|
||||||
void addButton(const std::string& label, const std::string& helpText, const std::function<void()>& callback);
|
void addButton(const std::string& label, const std::string& helpText, const std::function<void()>& callback);
|
||||||
|
|
||||||
|
void setTitle(const char* title, const std::shared_ptr<Font>& font);
|
||||||
|
|
||||||
inline void setCursorToList() { mGrid.setCursorTo(mList); }
|
inline void setCursorToList() { mGrid.setCursorTo(mList); }
|
||||||
inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); }
|
inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue