mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-11 05:04:40 -04:00
Add dusk::ui::append_text
This commit is contained in:
@@ -121,6 +121,7 @@ mod-entry .mod-entry-desc {
|
||||
color: rgba(224, 219, 200, 65%);
|
||||
max-height: 2.6em;
|
||||
overflow: hidden;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
mod-entry .mod-entry-sub {
|
||||
|
||||
@@ -72,15 +72,10 @@ std::string format_time(int64_t timeMs) {
|
||||
return fmt::format("{}.{:03}", buffer.data(), timeMs % 1000);
|
||||
}
|
||||
|
||||
void append_text(Rml::ElementDocument* doc, Rml::Element* parent, const Rml::String& text) {
|
||||
parent->AppendChild(doc->CreateTextNode(text));
|
||||
}
|
||||
|
||||
Rml::Element* append_span(Rml::ElementDocument* doc, Rml::Element* parent, const char* className,
|
||||
const Rml::String& text) {
|
||||
auto span = doc->CreateElement("span");
|
||||
Rml::Element* append_span(Rml::Element* parent, const char* className, const Rml::String& text) {
|
||||
auto span = parent->GetOwnerDocument()->CreateElement("span");
|
||||
span->SetClass(className, true);
|
||||
append_text(doc, span.get(), text);
|
||||
append_text(span.get(), text);
|
||||
return parent->AppendChild(std::move(span));
|
||||
}
|
||||
|
||||
@@ -270,11 +265,11 @@ Rml::Element* LogsWindow::append_log_line(const mods::log::Line& line) {
|
||||
elem->SetClass(level_class(line.level), true);
|
||||
|
||||
constexpr const char* kNbsp = "\xc2\xa0";
|
||||
append_span(mDocument, elem.get(), "log-time", format_time(line.timeMs));
|
||||
append_text(mDocument, elem.get(), kNbsp);
|
||||
append_span(mDocument, elem.get(), "log-mod", fmt::format("[{}]", modId));
|
||||
append_text(mDocument, elem.get(), kNbsp);
|
||||
append_span(mDocument, elem.get(), "log-msg", line.message);
|
||||
append_span(elem.get(), "log-time", format_time(line.timeMs));
|
||||
append_text(elem.get(), kNbsp);
|
||||
append_span(elem.get(), "log-mod", fmt::format("[{}]", modId));
|
||||
append_text(elem.get(), kNbsp);
|
||||
append_span(elem.get(), "log-msg", line.message);
|
||||
|
||||
return mLinesElem->AppendChild(std::move(elem));
|
||||
}
|
||||
|
||||
@@ -166,13 +166,13 @@ bool Pane::focus() {
|
||||
Rml::Element* Pane::add_section(const Rml::String& text) {
|
||||
auto* elem = append(mRoot, "div");
|
||||
elem->SetClass("section-heading", true);
|
||||
elem->SetInnerRML(escape(text));
|
||||
append_text(elem, text);
|
||||
return elem;
|
||||
}
|
||||
|
||||
Rml::Element* Pane::add_text(const Rml::String& text) {
|
||||
auto* elem = append(mRoot, "div");
|
||||
elem->SetInnerRML(escape(text));
|
||||
append_text(elem, text);
|
||||
return elem;
|
||||
}
|
||||
|
||||
|
||||
+19
-6
@@ -31,9 +31,9 @@ void load_font(const char* filename, bool fallback = false) {
|
||||
}
|
||||
|
||||
bool sInitialized = false;
|
||||
std::vector<std::unique_ptr<Document> > sDocumentStack;
|
||||
std::vector<std::unique_ptr<Document>> sDocumentStack;
|
||||
// Documents that don't participate in the focus stack
|
||||
std::vector<std::unique_ptr<Document> > sPassiveDocuments;
|
||||
std::vector<std::unique_ptr<Document>> sPassiveDocuments;
|
||||
|
||||
struct ScopedStyles {
|
||||
DocumentScope scope;
|
||||
@@ -173,10 +173,12 @@ void handle_event(const SDL_Event& event) noexcept {
|
||||
const char* name = SDL_GetGamepadName(gamepad);
|
||||
Rml::String content = fmt::format("<span>{}</span>", name ? name : "[Unknown]");
|
||||
Rml::String title = "Device Connected";
|
||||
if (const char* icon = connection_state_icon(SDL_GetGamepadConnectionState(gamepad))) {
|
||||
if (const char* icon =
|
||||
connection_state_icon(SDL_GetGamepadConnectionState(gamepad)))
|
||||
{
|
||||
title = fmt::format(
|
||||
"<row><span>{}</span> <icon class=\"connection\">&#x{};</icon></row>", title,
|
||||
icon);
|
||||
"<row><span>{}</span> <icon class=\"connection\">&#x{};</icon></row>",
|
||||
title, icon);
|
||||
}
|
||||
int batteryLevel = -1;
|
||||
const auto powerState = SDL_GetGamepadPowerInfo(gamepad, &batteryLevel);
|
||||
@@ -382,6 +384,17 @@ Rml::Element* append(Rml::Element* parent, const Rml::String& tag) noexcept {
|
||||
return parent->AppendChild(doc->CreateElement(tag));
|
||||
}
|
||||
|
||||
Rml::Element* append_text(Rml::Element* parent, const Rml::String& text) noexcept {
|
||||
if (parent == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
auto* doc = parent->GetOwnerDocument();
|
||||
if (doc == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return parent->AppendChild(doc->CreateTextNode(text));
|
||||
}
|
||||
|
||||
NavCommand map_nav_event(const Rml::Event& event) noexcept {
|
||||
const auto key = static_cast<Rml::Input::KeyIdentifier>(
|
||||
event.GetParameter<int>("key_identifier", Rml::Input::KI_UNKNOWN));
|
||||
@@ -448,7 +461,7 @@ void push_toast(Toast toast) noexcept {
|
||||
sToasts.push_back(std::move(toast));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Document> >& get_document_stack() noexcept {
|
||||
std::vector<std::unique_ptr<Document>>& get_document_stack() noexcept {
|
||||
return sDocumentStack;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ Document* top_document() noexcept;
|
||||
std::filesystem::path resource_path(const std::filesystem::path& filename) noexcept;
|
||||
std::string escape(std::string_view str) noexcept;
|
||||
Rml::Element* append(Rml::Element* parent, const Rml::String& tag) noexcept;
|
||||
Rml::Element* append_text(Rml::Element* parent, const Rml::String& text) noexcept;
|
||||
|
||||
NavCommand map_nav_event(const Rml::Event& event) noexcept;
|
||||
Insets safe_area_insets(Rml::Context* context) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user