mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-10-24 15:38:30 -04:00
Added line feature for label widget.
This commit is contained in:
1 parent
884705a716
commit
cc76e4f278
6 files changed
+75
-21
No files matched your search
@@ -31,6 +31,7 @@ MenuPage::MenuPage( gui::Item* parent, int32_t x, int32_t y, uint32_t w, uint32_
|
||||
title->setFont("gt_pressura_regular_24");
|
||||
title->setAlignement( gui::Alignment(gui::Alignment::ALIGN_HORIZONTAL_CENTER, gui::Alignment::ALIGN_VERTICAL_CENTER));
|
||||
title->setText( titleName );
|
||||
title->setLineMode(true);
|
||||
|
||||
uint32_t rowCount = tilesDescription.size()/3;
|
||||
|
||||
|
||||
@@ -312,6 +312,15 @@ uint32_t Font::getCharPixelWidth( uint32_t charCode ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Font::getCharPixelHeight( uint32_t charCode ) {
|
||||
FontGlyph* glyph = glyphs.find(charCode)->second;
|
||||
|
||||
if( glyph != NULL)
|
||||
return glyph->height ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FontManager::FontManager() {
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,14 @@ public:
|
||||
* @return Number of pixels in width occupied by string.
|
||||
*/
|
||||
uint32_t getPixelWidth( const UTF8& str );
|
||||
/**
|
||||
* @brief returns number of pixels occupied by character horizontally.
|
||||
*/
|
||||
uint32_t getCharPixelWidth( uint32_t charCode );
|
||||
/**
|
||||
* @brief Returns number of pixels occupied by the character vertically.
|
||||
*/
|
||||
uint32_t getCharPixelHeight( uint32_t charCode );
|
||||
|
||||
const std::string getName() {
|
||||
return info.face;
|
||||
|
||||
@@ -115,21 +115,13 @@ void Label::calculateDisplayText() {
|
||||
textArea.y =
|
||||
(widgetArea.h - font->info.line_height )/2 +
|
||||
font->info.base;
|
||||
// textArea.y =
|
||||
// (drawArea.h - font->info.line_height )/2 +
|
||||
// font->info.base;
|
||||
}
|
||||
else if( alignment.isAligned(Alignment::ALIGN_VERTICAL_TOP ))
|
||||
{
|
||||
// textArea.y = font->info.base + margins.top;
|
||||
textArea.y = font->info.base + margins.top;
|
||||
}
|
||||
else if( alignment.isAligned(Alignment::ALIGN_VERTICAL_BOTTOM ))
|
||||
{
|
||||
// textArea.y =
|
||||
// drawArea.h -
|
||||
// font->info.line_height + font->info.base -
|
||||
// margins.bottom;
|
||||
textArea.y =
|
||||
widgetArea.h -
|
||||
font->info.line_height + font->info.base -
|
||||
@@ -139,7 +131,6 @@ void Label::calculateDisplayText() {
|
||||
//calculate horizontal position o text
|
||||
if( alignment.isAligned(Alignment::ALIGN_HORIZONTAL_CENTER ))
|
||||
{
|
||||
// textArea.x =( drawArea.w - textArea.w )/2;
|
||||
textArea.x =( widgetArea.w - textArea.w )/2;
|
||||
}
|
||||
else if( alignment.isAligned(Alignment::ALIGN_HORIZONTAL_LEFT ))
|
||||
@@ -148,9 +139,36 @@ void Label::calculateDisplayText() {
|
||||
}
|
||||
else if( alignment.isAligned(Alignment::ALIGN_HORIZONTAL_RIGHT ))
|
||||
{
|
||||
// textArea.x = drawArea.w - textArea.w - margins.right;
|
||||
textArea.x = widgetArea.w - textArea.w - margins.right;
|
||||
}
|
||||
|
||||
//if dots mode is disabled and line mode is enabled calculate positiona and width of the line
|
||||
if( (!dotsMode) && (lineMode) && (lineFront!=nullptr) ) {
|
||||
uint32_t spaceWidth = font->getCharPixelWidth(' ');
|
||||
int32_t lineW = availableSpace - stringPixelWidth ;
|
||||
uint32_t lineY = textArea.y - font->getCharPixelHeight('a')/2;
|
||||
if( lineW < 0 ) lineW = 0;
|
||||
|
||||
lineFront->setVisible(true);
|
||||
lineBack->setVisible(true);
|
||||
//both lines are visible
|
||||
if( alignment.isAligned(Alignment::ALIGN_HORIZONTAL_CENTER )) {
|
||||
lineFront->setPosition( 0, lineY );
|
||||
lineFront->setSize( lineW/2 - spaceWidth, 2 );
|
||||
lineBack->setPosition( lineW/2 + stringPixelWidth +spaceWidth, lineY);
|
||||
lineBack->setSize( lineW/2 -spaceWidth, 2 );
|
||||
}
|
||||
else if( alignment.isAligned(Alignment::ALIGN_HORIZONTAL_RIGHT)) {
|
||||
lineFront->setPosition( 0, lineY );
|
||||
lineFront->setSize( lineW-spaceWidth, 2 );
|
||||
lineBack->setVisible(false);
|
||||
}
|
||||
else if( alignment.isAligned(Alignment::ALIGN_HORIZONTAL_LEFT )) {
|
||||
lineBack->setPosition( stringPixelWidth +spaceWidth, lineY);
|
||||
lineBack->setSize( lineW-spaceWidth, 2 );
|
||||
lineFront->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Label::setText( const UTF8& text ) {
|
||||
@@ -181,6 +199,27 @@ void Label::setDotsMode( const bool val ) {
|
||||
calculateDisplayText();
|
||||
}
|
||||
|
||||
void Label::setLineMode( const bool& val ) {
|
||||
//if line mode is disable remove the line if it was previously created
|
||||
if( val == false ) {
|
||||
if( lineFront != nullptr ) {
|
||||
this->removeWidget( lineFront );
|
||||
this->removeWidget( lineBack );
|
||||
delete lineFront;
|
||||
delete lineBack;
|
||||
lineFront = nullptr;
|
||||
lineBack = nullptr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( lineFront == nullptr ) {
|
||||
lineFront = new Rect( this, 0,0,0,0 );
|
||||
lineBack = new Rect( this, 0,0,0,0 );
|
||||
}
|
||||
}
|
||||
calculateDisplayText();
|
||||
}
|
||||
|
||||
std::list<DrawCommand*> Label::buildDrawList() {
|
||||
|
||||
std::list<DrawCommand*> commands;
|
||||
|
||||
@@ -42,10 +42,15 @@ protected:
|
||||
Alignment alignment;
|
||||
//flag that defines if 3 dots are to be displayed at the end of label's text.
|
||||
bool dotsMode;
|
||||
bool lineMode;
|
||||
//area specified in pixels occupied by text inside label space.
|
||||
//This defines also position of the text considering alignment and margins.
|
||||
BoundingBox textArea;
|
||||
|
||||
//widgets to add line
|
||||
Rect* lineFront = nullptr;
|
||||
Rect* lineBack = nullptr;
|
||||
|
||||
void calculateDisplayText();
|
||||
public:
|
||||
|
||||
@@ -60,6 +65,10 @@ public:
|
||||
virtual void setAlignement( const Alignment& alignment );
|
||||
virtual void setMargins( const Margins& margins );
|
||||
void setDotsMode( const bool val );
|
||||
/**
|
||||
* @brief Defines if remaining area of the label has a horizontal line.
|
||||
*/
|
||||
void setLineMode( const bool& val );
|
||||
void setTextColor( Color color );
|
||||
void setFont( const UTF8& fontName );
|
||||
|
||||
|
||||
@@ -145,22 +145,11 @@ int main() {
|
||||
|
||||
//vector with launchers to applications
|
||||
std::vector<std::unique_ptr<app::ApplicationLauncher> > applications;
|
||||
//launcher for viewer
|
||||
applications.push_back(std::unique_ptr<app::ApplicationViewerLauncher>(new app::ApplicationViewerLauncher()));
|
||||
|
||||
//launcher for desktop application
|
||||
applications.push_back(std::unique_ptr<app::ApplicationDesktopLauncher>(new app::ApplicationDesktopLauncher()));
|
||||
|
||||
//launcher for call application
|
||||
applications.push_back(std::unique_ptr<app::ApplicationCallLauncher>(new app::ApplicationCallLauncher()));
|
||||
|
||||
//launcher for settings application
|
||||
applications.push_back(std::unique_ptr<app::ApplicationSettingsLauncher>(new app::ApplicationSettingsLauncher()));
|
||||
|
||||
//launcher for notes application
|
||||
applications.push_back(std::unique_ptr<app::ApplicationNotesLauncher>(new app::ApplicationNotesLauncher()));
|
||||
|
||||
// create launcher for phonebook, all launchers could be created like that
|
||||
applications.push_back(app::CreateLauncher<app::ApplicationPhonebook>("ApplicationPhonebook"));
|
||||
|
||||
//start application manager
|
||||
|
||||
Reference in new issue
Block a user