Skip to content

Commit cd0e213

Browse files
authoredAug 11, 2020
Add font styling options to tables and textlists (#10203)
1 parent abfea69 commit cd0e213

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed
 

‎src/gui/guiFormSpecMenu.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element)
12251225

12261226
auto style = getDefaultStyleForElement("table", name);
12271227
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
1228+
e->setOverrideFont(style.getFont());
12281229

12291230
m_tables.emplace_back(spec, e);
12301231
m_fields.push_back(spec);
@@ -1302,6 +1303,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element
13021303

13031304
auto style = getDefaultStyleForElement("textlist", name);
13041305
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
1306+
e->setOverrideFont(style.getFont());
13051307

13061308
m_tables.emplace_back(spec, e);
13071309
m_fields.push_back(spec);

‎src/gui/guiTable.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
5656
m_font = skin->getFont();
5757
if (m_font) {
5858
m_font->grab();
59-
m_rowheight = m_font->getDimension(L"A").Height + 4;
59+
m_rowheight = m_font->getDimension(L"Ay").Height + 4;
6060
m_rowheight = MYMAX(m_rowheight, 1);
6161
}
6262

@@ -586,6 +586,31 @@ void GUITable::setSelected(s32 index)
586586
}
587587
}
588588

589+
void GUITable::setOverrideFont(IGUIFont *font)
590+
{
591+
if (m_font == font)
592+
return;
593+
594+
if (font == nullptr)
595+
font = Environment->getSkin()->getFont();
596+
597+
if (m_font)
598+
m_font->drop();
599+
600+
m_font = font;
601+
m_font->grab();
602+
603+
m_rowheight = m_font->getDimension(L"Ay").Height + 4;
604+
m_rowheight = MYMAX(m_rowheight, 1);
605+
606+
updateScrollBar();
607+
}
608+
609+
IGUIFont *GUITable::getOverrideFont() const
610+
{
611+
return m_font;
612+
}
613+
589614
GUITable::DynamicData GUITable::getDynamicData() const
590615
{
591616
DynamicData dyndata;

‎src/gui/guiTable.h

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class GUITable : public gui::IGUIElement
123123
// Autoscroll to make the selected row fully visible
124124
void setSelected(s32 index);
125125

126+
//! Sets another skin independent font. If this is set to zero, the button uses the font of the skin.
127+
virtual void setOverrideFont(gui::IGUIFont *font = nullptr);
128+
129+
//! Gets the override font (if any)
130+
virtual gui::IGUIFont *getOverrideFont() const;
131+
126132
/* Get selection, scroll position and opened (sub)trees */
127133
DynamicData getDynamicData() const;
128134

0 commit comments

Comments
 (0)
Please sign in to comment.