diff --git a/data/gui/window/help_browser.cfg b/data/gui/window/help_browser.cfg index 4e4a143c4920..ffd8af1077d6 100644 --- a/data/gui/window/help_browser.cfg +++ b/data/gui/window/help_browser.cfg @@ -28,6 +28,7 @@ [row] [column] + grow_factor = 0 border = "all" border_size = 5 @@ -38,16 +39,20 @@ [/column] [column] + grow_factor = 1 border = "all" border_size = 5 + horizontal_grow = true [label] id = "topic_name" linked_group = "names" + definition = "default_small" [/label] [/column] [column] + grow_factor = 0 border = "all" border_size = 5 @@ -128,9 +133,9 @@ [grid] [row] - grow_factor = 0 [column] + grow_factor = 0 border = "all" border_size = 5 horizontal_grow = true @@ -141,6 +146,8 @@ [column] grow_factor = 1 + horizontal_grow = true + vertical_grow = true [multi_page] id = "topic_text_pages" diff --git a/src/gui/dialogs/help_browser.cpp b/src/gui/dialogs/help_browser.cpp index 5543efda6172..2a3dcbddb34d 100644 --- a/src/gui/dialogs/help_browser.cpp +++ b/src/gui/dialogs/help_browser.cpp @@ -61,33 +61,44 @@ void help_browser::pre_show(window& window) window.keyboard_capture(&topic_tree); - for(const help::section* section : help::default_toplevel.sections) { - add_topic(window, section->id, section->title, true); - } + add_topics_for_section(help::default_toplevel, topic_tree.get_root_node()); + + on_topic_select(window); +} + +void help_browser::add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node) +{ + for(const help::section* section : parent_section.sections) { + tree_view_node& section_node = add_topic(section->id, section->title, true, parent_node); - for(const help::topic& topic : help::default_toplevel.topics) { - add_topic(window, topic.id, topic.title, false); + add_topics_for_section(*section, section_node); } - on_topic_select(window); + for(const help::topic& topic : parent_section.topics) { + add_topic(topic.id, topic.title, false, parent_node); + } } -void help_browser::add_topic(window& window, const std::string& topic_id, const std::string& topic_title, bool expands, tree_view_node*) { - tree_view& topic_tree = find_widget(&window, "topic_tree", false); +tree_view_node& help_browser::add_topic(const std::string& topic_id, const std::string& topic_title, + bool expands, tree_view_node& parent) +{ std::map data; string_map item; item["label"] = topic_title; data.emplace("topic_name", item); - item.clear(); item["label"] = expands ? help::closed_section_img : help::topic_img; data.emplace("topic_icon", item); - topic_tree.add_node("topic", data).set_id(std::string(expands ? "+" : "-") + topic_id); + tree_view_node& new_node = parent.add_child("topic", data); + new_node.set_id(std::string(expands ? "+" : "-") + topic_id); + + return new_node; } -static std::string format_help_text(const config& cfg) { +static std::string format_help_text(const config& cfg) +{ std::stringstream ss; for(auto& item : cfg.all_children_range()) { if(item.key == "text") { @@ -100,7 +111,7 @@ static std::string format_help_text(const config& cfg) { throw help::parse_error(msg.str()); }; // TODO: Get the proper link shade from somewhere - ss << font::format_as_link(font::escape_text(item.cfg["text"]), "#aaaa00"); + ss << font::format_as_link(font::escape_text(item.cfg["text"]), "#ffff00"); } else if(item.key == "img") { if(item.cfg["src"].empty()) { throw help::parse_error("Img markup must have src attribute."); @@ -131,19 +142,24 @@ static std::string format_help_text(const config& cfg) { if(item.cfg["text"].empty()) { throw help::parse_error("Header markup must have text attribute."); } + ss << "' << font::escape_text(item.cfg["text"]) << ""; } } @@ -159,8 +175,17 @@ void help_browser::on_topic_select(window& window) return; } - assert(topic_tree.selected_item()); - std::string topic_id = topic_tree.selected_item()->id(); + tree_view_node* selected = topic_tree.selected_item(); + assert(selected); + + // FIXME: should we be manually doing this? + if(selected->is_folded()) { + selected->unfold(); + } else { + selected->fold(); + } + + std::string topic_id = selected->id(); if(topic_id.empty()) { return; @@ -173,6 +198,7 @@ void help_browser::on_topic_select(window& window) } help::section& sec = help::default_toplevel; + auto iter = parsed_pages_.find(topic_id); if(iter == parsed_pages_.end()) { const help::topic* topic = help::find_topic(sec, topic_id); @@ -188,12 +214,12 @@ void help_browser::on_topic_select(window& window) parsed_pages_.emplace(topic_id, topic_pages.get_page_count()); topic_pages.add_page(data); + window.invalidate_layout(); } const unsigned topic_i = parsed_pages_.at(topic_id); topic_pages.select_page(topic_i); - } } // namespace dialogs diff --git a/src/gui/dialogs/help_browser.hpp b/src/gui/dialogs/help_browser.hpp index f01ab71dbb1d..f53b4de2611a 100644 --- a/src/gui/dialogs/help_browser.hpp +++ b/src/gui/dialogs/help_browser.hpp @@ -15,12 +15,15 @@ #pragma once #include "gui/dialogs/modal_dialog.hpp" +#include "help/help_impl.hpp" #include class config; namespace gui2 { +class tree_view_node; + namespace dialogs { @@ -45,7 +48,9 @@ class help_browser : public modal_dialog void on_topic_select(window& window); - void add_topic(window& window, const std::string& topic_id, const std::string& topic_title, bool expands, class tree_view_node* parent = nullptr); + void add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node); + tree_view_node& add_topic(const std::string& topic_id, const std::string& topic_title, + bool expands, tree_view_node& parent); }; } // namespace dialogs