mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-06-03 18:36:58 -04:00
init mod menu + bem class + button presets
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include "ElementModMenu.h"
|
||||
#include "presets.h"
|
||||
#include "librecomp/mods.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace recompui {
|
||||
|
||||
static const BEM mod_menu_bem("mod-menu");
|
||||
|
||||
static const std::string cls_base = mod_menu_bem.get_block();
|
||||
static const std::string cls_modal_wrapper = mod_menu_bem.el("modal-wrapper");
|
||||
static const std::string cls_modal_header = mod_menu_bem.el("modal-header");
|
||||
static const std::string cls_modal_body = mod_menu_bem.el("modal-body");
|
||||
static const std::string cls_list = mod_menu_bem.el("list");
|
||||
static const std::string cls_list_scroll = mod_menu_bem.el("list-scroll");
|
||||
static const std::string cls_details = mod_menu_bem.el("details");
|
||||
|
||||
static Rml::Element *add_div_with_class(Rml::ElementDocument *doc, Rml::Element *parent_el, const std::string& cls) {
|
||||
Rml::Element *el = parent_el->AppendChild(doc->CreateElement("div"));
|
||||
el->SetClass(cls.c_str(), true);
|
||||
return el;
|
||||
}
|
||||
|
||||
ElementModMenu::ElementModMenu(const Rml::String& tag) : Rml::Element(tag)
|
||||
{
|
||||
SetAttribute("recomp-store-element", true);
|
||||
Rml::ElementDocument *doc = GetOwnerDocument();
|
||||
SetClass(mod_menu_bem.block, true);
|
||||
|
||||
{
|
||||
Rml::Element *modal_wrapper_el = add_div_with_class(doc, this, cls_modal_wrapper);
|
||||
{
|
||||
Rml::Element *header_el = add_div_with_class(doc, modal_wrapper_el, cls_modal_header);
|
||||
{
|
||||
add_button(doc, header_el, "Refresh", ButtonVariant::Primary);
|
||||
add_icon_button(doc, header_el, "icons/X.svg", ButtonVariant::Tertiary);
|
||||
}
|
||||
|
||||
Rml::Element *body_el = add_div_with_class(doc, modal_wrapper_el, cls_modal_body);
|
||||
{
|
||||
Rml::Element *list_el = add_div_with_class(doc, body_el, cls_list);
|
||||
{
|
||||
Rml::Element *list_el_scroll = add_div_with_class(doc, list_el, cls_list_scroll);
|
||||
{
|
||||
std::vector<recomp::mods::ModDetails> mods = recomp::mods::get_mod_details("mm");
|
||||
for (auto& mod : mods) {
|
||||
Rml::Element *mod_el = list_el_scroll->AppendChild(doc->CreateElement("div"));
|
||||
mod_el->SetInnerRML(mod.mod_id);
|
||||
}
|
||||
} // list_el_scroll
|
||||
} // list_el
|
||||
|
||||
Rml::Element *details_el = add_div_with_class(doc, body_el, cls_details);
|
||||
details_el->SetInnerRML("two");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ElementModMenu::~ElementModMenu()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Rml
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef RECOMPUI_ELEMENT_MOD_MENU_H
|
||||
#define RECOMPUI_ELEMENT_MOD_MENU_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace recompui {
|
||||
|
||||
class ElementModMenu : public Rml::Element {
|
||||
public:
|
||||
ElementModMenu(const Rml::String& tag);
|
||||
virtual ~ElementModMenu();
|
||||
};
|
||||
|
||||
} // namespace recompui
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "presets.h"
|
||||
|
||||
namespace recompui {
|
||||
|
||||
static const BEM button_bem("button");
|
||||
Rml::Element *add_button(Rml::ElementDocument *doc, Rml::Element *parent_el, const Rml::String contents, ButtonVariant variant, bool isLarge) {
|
||||
Rml::Element *button = parent_el->AppendChild(doc->CreateElement("button"));
|
||||
|
||||
button->SetClass(button_bem.get_block(), true);
|
||||
|
||||
button->SetClass(button_bem.mod(button_variants.at(variant)), true);
|
||||
if (isLarge) {
|
||||
button->SetClass(button_bem.mod("large"), true);
|
||||
}
|
||||
|
||||
if (contents != "") {
|
||||
button->SetInnerRML(contents);
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
static const BEM icon_button_bem("icon-button");
|
||||
Rml::Element *add_icon_button(Rml::ElementDocument *doc, Rml::Element *parent_el, const std::string &svg_src, ButtonVariant variant) {
|
||||
Rml::Element *button = parent_el->AppendChild(doc->CreateElement("button"));
|
||||
|
||||
button->SetClass(icon_button_bem.get_block(), true);
|
||||
button->SetClass(icon_button_bem.mod(button_variants.at(variant)), true);
|
||||
|
||||
{
|
||||
Rml::Element *icon = button->AppendChild(doc->CreateElement("svg"));
|
||||
icon->SetClass(icon_button_bem.el("icon"), true);
|
||||
icon->SetAttribute("src", svg_src);
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
} // namespace recompui
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef RECOMPUI_ELEMENTS_PRESETS
|
||||
#define RECOMPUI_ELEMENTS_PRESETS
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace recompui {
|
||||
Rml::Element *add_button(Rml::ElementDocument *doc, Rml::Element *parent_el, const Rml::String contents = "", ButtonVariant variant = ButtonVariant::Primary, bool isLarge = false);
|
||||
Rml::Element *add_icon_button(Rml::ElementDocument *doc, Rml::Element *parent_el, const std::string &svg_src, ButtonVariant variant = ButtonVariant::Tertiary);
|
||||
} // namespace recompui
|
||||
|
||||
#endif
|
||||
@@ -19,12 +19,10 @@ static RecompElementConfig custom_elements[] = {
|
||||
CUSTOM_ELEMENT("recomp-option-type-textfield", recompui::ElementOptionTypeTextField),
|
||||
CUSTOM_ELEMENT("recomp-option-type-radio-tabs", recompui::ElementOptionTypeRadioTabs),
|
||||
CUSTOM_ELEMENT("recomp-option-type-range", recompui::ElementOptionTypeRange),
|
||||
CUSTOM_ELEMENT("recomp-mod-menu", recompui::ElementModMenu),
|
||||
};
|
||||
|
||||
void recompui::register_custom_elements() {
|
||||
recomp::config::set_config_store_value_and_default("ligma_balls", "hello!", "whats up");
|
||||
recomp::config::set_config_store_default_value("ligma_balls2", "12345");
|
||||
recomp::config::set_config_store_value("ligma_balls3", "hello!");
|
||||
for (auto& element_config : custom_elements) {
|
||||
Rml::Factory::RegisterElementInstancer(element_config.tag, element_config.instancer.get());
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "elements/ElementOptionTypeRange.h"
|
||||
#include "elements/ElementOptionTypeTextField.h"
|
||||
#include "elements/ElementDescription.h"
|
||||
#include "elements/ElementModMenu.h"
|
||||
|
||||
namespace recompui {
|
||||
void register_custom_elements();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef RECOMPUI_ELEMENTS_BEM
|
||||
#define RECOMPUI_ELEMENTS_BEM
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace recompui {
|
||||
// BEM base class
|
||||
class BEM {
|
||||
public:
|
||||
std::string block;
|
||||
|
||||
BEM(const std::string &block) : block(block) {}
|
||||
virtual ~BEM() = default;
|
||||
|
||||
const std::string get_block() const {
|
||||
return block;
|
||||
}
|
||||
|
||||
const std::string el(const std::string &element) const {
|
||||
return block + "__" + element;
|
||||
}
|
||||
|
||||
const BEM bem_el(const std::string &element) const {
|
||||
return BEM(el(element));
|
||||
}
|
||||
|
||||
const std::string mod(const std::string &modifier) const {
|
||||
return block + "--" + modifier;
|
||||
}
|
||||
};
|
||||
} // namespace recompui
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user