From 6e19d28ba3f9e0e67de7aa56be2bbf1c24eee9ef Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Tue, 8 Apr 2025 18:56:49 -0400 Subject: [PATCH] Apply recomp.rcss to mod UI contexts (fixes scrolls) --- include/recomp_ui.h | 1 + src/ui/core/ui_context.cpp | 32 +++++++++++++++++++------------- src/ui/ui_state.cpp | 1 + 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/recomp_ui.h b/include/recomp_ui.h index ea6cec3..9f23bec 100644 --- a/include/recomp_ui.h +++ b/include/recomp_ui.h @@ -80,6 +80,7 @@ namespace recompui { NumVariants, }; + void init_styling(const std::filesystem::path& rcss_file); void init_prompt_context(); void open_choice_prompt( const std::string& header_text, diff --git a/src/ui/core/ui_context.cpp b/src/ui/core/ui_context.cpp index d24559d..165c382 100644 --- a/src/ui/core/ui_context.cpp +++ b/src/ui/core/ui_context.cpp @@ -1,8 +1,10 @@ #include #include #include +#include #include "slot_map.h" +#include "RmlUi/Core/StreamMemory.h" #include "ultramodern/error_handling.hpp" #include "recomp_ui.h" @@ -47,6 +49,7 @@ static struct { context_slotmap all_contexts; std::unordered_set opened_contexts; std::unordered_map documents_to_contexts; + Rml::SharedPtr style_sheet; } context_state; thread_local recompui::Context* opened_context = nullptr; @@ -168,6 +171,21 @@ recompui::ContextId create_context_impl(Rml::ElementDocument* document) { return ret; } +void recompui::init_styling(const std::filesystem::path& rcss_file) { + std::string style{}; + { + std::ifstream style_stream{rcss_file}; + style_stream.seekg(0, std::ios::end); + style.resize(style_stream.tellg()); + style_stream.seekg(0, std::ios::beg); + + style_stream.read(style.data(), style.size()); + } + std::unique_ptr rml_stream = std::make_unique(reinterpret_cast(style.data()), style.size()); + rml_stream->SetSourceURL(rcss_file.filename().string()); + context_state.style_sheet = Rml::Factory::InstanceStyleSheetStream(rml_stream.get()); +} + recompui::ContextId recompui::create_context(const std::filesystem::path& path) { ContextId new_context = create_context_impl(nullptr); @@ -195,28 +213,16 @@ recompui::ContextId recompui::create_context(Rml::ElementDocument* document) { recompui::ContextId recompui::create_context() { Rml::ElementDocument* doc = create_empty_document(); + doc->SetStyleSheetContainer(context_state.style_sheet); ContextId ret = create_context_impl(doc); Element* root = ret.get_root_element(); // Mark the root element as not being a shim, as that's only needed for elements that were parented to Rml ones manually. root->shim = false; - // TODO move these defaults elsewhere. Copied from the existing rcss. ret.open(); root->set_width(100.0f, Unit::Percent); root->set_height(100.0f, Unit::Percent); root->set_display(Display::Flex); - root->set_opacity(1.0f); - root->set_color(Color{ 242, 242, 242, 255 }); - root->set_font_family("chiaro"); - root->set_font_style(FontStyle::Normal); - root->set_font_weight(400); - - float sz = 16.0f; - float spacing = 0.0f; - float sz_add = sz + 4; - root->set_font_size(sz_add, Unit::Dp); - root->set_letter_spacing(sz_add * spacing, Unit::Dp); - root->set_line_height(sz_add, Unit::Dp); ret.close(); doc->Hide(); diff --git a/src/ui/ui_state.cpp b/src/ui/ui_state.cpp index 115f378..a985fbd 100644 --- a/src/ui/ui_state.cpp +++ b/src/ui/ui_state.cpp @@ -233,6 +233,7 @@ public: } void create_menus() { + recompui::init_styling(zelda64::get_asset_path("recomp.rcss")); launcher_menu_controller->load_document(); config_menu_controller->load_document(); recompui::init_prompt_context();