Skip to content

Commit

Permalink
Goodbye ucs2 and byte-slice-cast
Browse files Browse the repository at this point in the history
I woke up in the middle of the night last night aware
that this code was useless.
  • Loading branch information
ceejbot committed Jan 10, 2024
1 parent 6fc18bf commit 0758980
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ crate-type = ["staticlib"]

[dependencies]
bincode = "2.0.0-rc.3"
byte-slice-cast = "1.2.2"
chardet = "0.2.4"
cxx = { version = "1.0.111", features = ["c++20"] }
enumset = "1.1.3"
Expand All @@ -30,7 +29,6 @@ strfmt = "0.2.4"
strum = { version = "0.25.0", features = ["derive"] }
textcode = "0.2.2"
toml = "0.8.6"
ucs2 = "0.3.2"

[build-dependencies]
cxx-build = "1.0.111"
Expand Down
14 changes: 1 addition & 13 deletions src/controller/strings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Character encoding shenanigans. Bethesda is very bad at utf-8, I am told.
use byte_slice_cast::AsSliceOf;
use cxx::CxxVector;
use textcode::{iso8859_15, iso8859_9};

Expand Down Expand Up @@ -48,17 +46,7 @@ pub fn convert_to_utf8(bytes: Vec<u8>) -> String {
iso8859_15::decode(bytes.as_slice(), &mut dst);
dst
}
_ => {
let Ok(widebytes) = bytes.as_slice_of::<u16>() else {
return String::from_utf8_lossy(bytes.as_slice()).to_string();
};
let mut utf8bytes: Vec<u8> = vec![0; widebytes.len()];
let Ok(_c) = ucs2::decode(widebytes, &mut utf8bytes) else {
return String::from_utf8_lossy(bytes.as_slice()).to_string();
};
String::from_utf8(utf8bytes.clone())
.unwrap_or_else(|_| String::from_utf8_lossy(utf8bytes.as_slice()).to_string())
}
_ => String::from_utf8_lossy(&bytes).to_string(),
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/renderer/ui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ namespace ui
auto entry_name = std::string(entry->name());
const auto hotkey = settings->hotkey_for(slotLayout.element);
const auto slot_center = ImVec2(slotLayout.center.x, slotLayout.center.y);
const bool skipItem = entry_name.empty() && entry->icon_key().empty();

const auto slotbg = std::string(slotLayout.bg_image);
if (slotLayout.bg_color.a > 0 && ui_renderer::lazyLoadHudImage(slotbg))
Expand All @@ -552,7 +553,7 @@ namespace ui
}

// now draw the icon over the background...
if (slotLayout.icon_color.a > 0)
if (slotLayout.icon_color.a > 0 && !skipItem)
{
const auto iconColor = colorizeIcons ? entry->color() : slotLayout.icon_color;
auto iconkey = std::string(entry->icon_key());
Expand All @@ -570,15 +571,18 @@ namespace ui
}

// Loop through the text elements of this slot.
for (auto label : slotLayout.text)
if (!skipItem)
{
if (label.color.a == 0) { continue; }
const auto textPos = ImVec2(label.anchor.x, label.anchor.y);
auto entrytxt = std::string(entry->fmtstr(label.contents));
// Let's try a wrap width here. This is going to be wrong, but we'll experiment.
if (!entrytxt.empty())
for (auto label : slotLayout.text)
{
drawText(entrytxt, textPos, label.font_size, label.color, label.alignment, label.wrap_width);
if (label.color.a == 0) { continue; }
const auto textPos = ImVec2(label.anchor.x, label.anchor.y);
auto entrytxt = std::string(entry->fmtstr(label.contents));
// Let's try a wrap width here. This is going to be wrong, but we'll experiment.
if (!entrytxt.empty())
{
drawText(entrytxt, textPos, label.font_size, label.color, label.alignment, label.wrap_width);
}
}
}

Expand Down

0 comments on commit 0758980

Please sign in to comment.