Commit 3886e67e authored by Supernature2k's avatar Supernature2k Committed by OyyoDams

menu size and align property for datetime

parent c98a7555
......@@ -137,12 +137,12 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, _("MAIN M
addChild(&mVersion);
setSize(mMenu.getSize());
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, Renderer::getScreenHeight() * 0.3f);
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2);
// Animation
auto fadeFunc = [this](float t) {
setOpacity(lerp<float>(0, 255, t));
setPosition(getPosition().x(), lerp<float>(getPosition().y(), Renderer::getScreenHeight() * .15f, t));
setPosition(getPosition().x(), lerp<float>(getPosition().y(), (Renderer::getScreenHeight() - mSize.y()) / 2, t));
};
setOpacity(0);
......
......@@ -102,6 +102,7 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::
("color", COLOR)
("fontPath", PATH)
("fontSize", FLOAT)
("alignment", STRING)
("forceUppercase", BOOLEAN)
("zIndex", FLOAT)))
("rating", makeMap(boost::assign::map_list_of
......
......@@ -222,7 +222,7 @@ std::string DateTimeComponent::getDisplayString(DisplayMode mode) const
std::stringstream ss;
ss.imbue(loc);
ss << "" << second_clock::local_time();
ss << "" << second_clock::local_time() << " ";
return ss.str();
}
case DISP_RELATIVE_TO_NOW:
......@@ -288,7 +288,7 @@ void DateTimeComponent::updateTextCache()
DisplayMode mode = getCurrentDisplayMode();
const std::string dispString = mUppercase ? strToUpper(getDisplayString(mode)) : getDisplayString(mode);
std::shared_ptr<Font> font = getFont();
mTextCache = std::unique_ptr<TextCache>(font->buildTextCache(dispString, 0, 0, mColor));
mTextCache = std::unique_ptr<TextCache>(font->buildTextCache(dispString, Eigen::Vector2f(0, 0), mColor, mSize.x(), mHorizontalAlignment));
if(mAutoSize)
{
......@@ -339,6 +339,12 @@ void DateTimeComponent::setFont(std::shared_ptr<Font> font)
updateTextCache();
}
void DateTimeComponent::setHorizontalAlignment(Alignment align)
{
mHorizontalAlignment = align;
updateTextCache();
}
void DateTimeComponent::onSizeChanged()
{
mAutoSize = false;
......@@ -370,6 +376,19 @@ void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, cons
if(properties & COLOR && elem->has("color"))
setColor(elem->get<unsigned int>("color"));
if(properties & ALIGNMENT && elem->has("alignment"))
{
std::string str = elem->get<std::string>("alignment");
if(str == "left")
setHorizontalAlignment(ALIGN_LEFT);
else if(str == "center")
setHorizontalAlignment(ALIGN_CENTER);
else if(str == "right")
setHorizontalAlignment(ALIGN_RIGHT);
else
LOG(LogError) << "Unknown text alignment string: " << str;
}
if(properties & FORCE_UPPERCASE && elem->has("forceUppercase"))
setUppercase(elem->get<bool>("forceUppercase"));
......
......@@ -38,6 +38,7 @@ public:
inline unsigned int getOriginColor() override{return mOriginColor;};
void setFont(std::shared_ptr<Font> font); // Font to display with. Default is Font::get(FONT_SIZE_MEDIUM).
void setUppercase(bool uppercase); // Force text to be uppercase when in DISP_RELATIVE_TO_NOW mode.
void setHorizontalAlignment(Alignment align);
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
......@@ -64,6 +65,7 @@ private:
unsigned int mColor;
unsigned int mOriginColor;
std::shared_ptr<Font> mFont;
Alignment mHorizontalAlignment = ALIGN_RIGHT;
bool mUppercase;
bool mAutoSize;
......
......@@ -41,7 +41,7 @@ MenuComponent::MenuComponent(Window* window, const char* title, const std::share
if (title == _("MAIN MENU") ) {
auto headerGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(7, 1));
auto headerGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(3, 1));
std::string arch = Settings::getInstance()->getString("Arch");
if (arch == "x86" || arch == "x86_64") {
......@@ -54,8 +54,8 @@ MenuComponent::MenuComponent(Window* window, const char* title, const std::share
batDisplay->setColor(0xFF0000FF);
else
batDisplay->setColor(menuTheme->menuText.color);
batDisplay->setText(batt.first + " " + std::to_string(batt.second) + "%");
batDisplay->setHorizontalAlignment(ALIGN_CENTER);
batDisplay->setText(" " + batt.first + " " + std::to_string(batt.second) + "%");
batDisplay->setHorizontalAlignment(ALIGN_LEFT);
headerGrid->setEntry(batDisplay, Vector2i(0, 0), false);
}
......@@ -65,9 +65,10 @@ MenuComponent::MenuComponent(Window* window, const char* title, const std::share
mDateTime = std::make_shared<DateTimeComponent>(mWindow);
mDateTime->setDisplayMode(DateTimeComponent::DISP_TIME);
mDateTime->setHorizontalAlignment(ALIGN_RIGHT);
mDateTime->setFont(menuTheme->menuText.font);
mDateTime->setColor(menuTheme->menuText.color);
headerGrid->setEntry(mDateTime, Vector2i(6, 0), false);
headerGrid->setEntry(mDateTime, Vector2i(2, 0), false);
}
mGrid.setEntry(headerGrid, Vector2i(0, 0), false);
......@@ -117,7 +118,7 @@ float MenuComponent::getButtonGridHeight() const
void MenuComponent::updateSize()
{
const float maxHeight = Renderer::getScreenHeight() * 0.7f;
const float maxHeight = Renderer::getScreenHeight() * 0.85f;
float height = TITLE_HEIGHT + mList->getTotalRowHeight() + getButtonGridHeight() + 2;
if(height > maxHeight)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment