summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/settings_gui.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index e4ebff0c2..9fc9d2934 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1011,9 +1011,20 @@ struct SettingEntry {
uint Length() const;
SettingEntry *FindEntry(uint row, uint *cur_row);
+ uint GetMaxHelpHeight(int maxw);
uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last);
+ /**
+ * Get the help text of a single setting.
+ * @return The requested help text.
+ */
+ inline StringID GetHelpText()
+ {
+ assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
+ return this->d.entry.setting->desc.str_help;
+ }
+
private:
void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state);
};
@@ -1028,6 +1039,7 @@ struct SettingsPage {
uint Length() const;
SettingEntry *FindEntry(uint row, uint *cur_row) const;
+ uint GetMaxHelpHeight(int maxw);
uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
};
@@ -1154,6 +1166,20 @@ SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
}
/**
+ * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
+ * @param maxw Maximal width of a line help text.
+ * @return Biggest height needed to display any help text of this node (and its descendants).
+ */
+uint SettingEntry::GetMaxHelpHeight(int maxw)
+{
+ switch (this->flags & SEF_KIND_MASK) {
+ case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw);
+ case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw);
+ default: NOT_REACHED();
+ }
+}
+
+/**
* Draw a row in the settings panel.
*
* See SettingsPage::Draw() for an explanation about how drawing is performed.
@@ -1352,6 +1378,20 @@ SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
}
/**
+ * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
+ * @param maxw Maximal width of a line help text.
+ * @return Biggest height needed to display any help text of this (sub-)tree.
+ */
+uint SettingsPage::GetMaxHelpHeight(int maxw)
+{
+ uint biggest = 0;
+ for (uint field = 0; field < this->num; field++) {
+ biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw));
+ }
+ return biggest;
+}
+
+/**
* Draw a selected part of the settings page.
*
* The scrollbar uses rows of the page, while the page data strucure is a tree of #SettingsPage and #SettingEntry objects.