1
0
mirror of synced 2025-01-31 03:53:44 +01:00

ui: Mae sure all theme scaling values are scaled correctly

This commit is contained in:
WerWolv 2023-03-18 10:52:50 +01:00
parent 1a1bf98905
commit 367bd76046
9 changed files with 86 additions and 86 deletions

View File

@ -21,6 +21,7 @@ namespace hex::api {
std::variant<ImVec2*, float*> value;
float min;
float max;
bool needsScaling;
};
using StyleMap = std::map<std::string, Style>;

View File

@ -154,15 +154,16 @@ namespace hex::api {
continue;
auto &style = handler.styleMap.at(key);
const float scale = style.needsScaling ? 1_scaled : 1.0F;
if (value.is_number_float()) {
if (auto newValue = std::get_if<float*>(&style.value); newValue != nullptr)
**newValue = value.get<float>();
**newValue = value.get<float>() * scale;
else
log::warn("Style variable '{}' was of type ImVec2 but a float was expected.", name);
} else if (value.is_array() && value.size() == 2 && value[0].is_number_float() && value[1].is_number_float()) {
if (auto newValue = std::get_if<ImVec2*>(&style.value); newValue != nullptr)
**newValue = ImVec2(value[0].get<float>(), value[1].get<float>());
**newValue = ImVec2(value[0].get<float>() * scale, value[1].get<float>() * scale);
else
log::warn("Style variable '{}' was of type float but a ImVec2 was expected.", name);
} else {
@ -170,8 +171,6 @@ namespace hex::api {
}
}
}
ImGui::GetStyle().ScaleAllSizes(ImHexApi::System::getGlobalScale());
}
if (theme.contains("image_postfix")) {

View File

@ -164,7 +164,7 @@
],
"child-border-size": 1.0,
"child-rounding": 0.0,
"disabled-alpha": 0.6000000238418579,
"disabled-alpha": 0.6,
"frame-border-size": 0.0,
"frame-padding": [
4.0,
@ -209,7 +209,7 @@
"imnodes": {
"grid-spacing": 24.0,
"link-hover-distance": 10.0,
"link-line-segments-per-length": 0.10000000149011612,
"link-line-segments-per-length": 0.1,
"link-thickness": 3.0,
"mini-map-offset": [
4.0,

View File

@ -164,7 +164,7 @@
],
"child-border-size": 1.0,
"child-rounding": 0.0,
"disabled-alpha": 0.6000000238418579,
"disabled-alpha": 0.6,
"frame-border-size": 0.0,
"frame-padding": [
4.0,
@ -209,7 +209,7 @@
"imnodes": {
"grid-spacing": 24.0,
"link-hover-distance": 10.0,
"link-line-segments-per-length": 0.10000000149011612,
"link-line-segments-per-length": 0.1,
"link-thickness": 3.0,
"mini-map-offset": [
4.0,

View File

@ -164,7 +164,7 @@
],
"child-border-size": 1.0,
"child-rounding": 0.0,
"disabled-alpha": 0.6000000238418579,
"disabled-alpha": 0.6,
"frame-border-size": 0.0,
"frame-padding": [
4.0,
@ -209,7 +209,7 @@
"imnodes": {
"grid-spacing": 24.0,
"link-hover-distance": 10.0,
"link-line-segments-per-length": 0.10000000149011612,
"link-line-segments-per-length": 0.1,
"link-thickness": 3.0,
"mini-map-offset": [
4.0,

View File

@ -236,31 +236,31 @@ namespace hex::plugin::builtin {
{
auto &style = ImGui::GetStyle();
const static api::ThemeManager::StyleMap ImGuiStyleMap = {
{ "alpha", { &style.Alpha, 0.001F, 1.0F } },
{ "disabled-alpha", { &style.DisabledAlpha, 0.0F, 1.0F } },
{ "window-padding", { &style.WindowPadding, 0.0F, 20.0F } },
{ "window-rounding", { &style.WindowRounding, 0.0F, 12.0F } },
{ "window-border-size", { &style.WindowBorderSize, 0.0F, 1.0F } },
{ "window-min-size", { &style.WindowMinSize, 0.0F, 1000.0F } },
{ "window-title-align", { &style.WindowTitleAlign, 0.0F, 1.0F } },
{ "child-rounding", { &style.ChildRounding, 0.0F, 12.0F } },
{ "child-border-size", { &style.ChildBorderSize, 0.0F, 1.0F } },
{ "popup-rounding", { &style.PopupRounding, 0.0F, 12.0F } },
{ "popup-border-size", { &style.PopupBorderSize, 0.0F, 1.0F } },
{ "frame-padding", { &style.FramePadding, 0.0F, 20.0F } },
{ "frame-rounding", { &style.FrameRounding, 0.0F, 12.0F } },
{ "frame-border-size", { &style.FrameBorderSize, 0.0F, 1.0F } },
{ "item-spacing", { &style.ItemSpacing, 0.0F, 20.0F } },
{ "item-inner-spacing", { &style.ItemInnerSpacing, 0.0F, 20.0F } },
{ "indent-spacing", { &style.IndentSpacing, 0.0F, 30.0F } },
{ "cell-padding", { &style.CellPadding, 0.0F, 20.0F } },
{ "scrollbar-size", { &style.ScrollbarSize, 0.0F, 20.0F } },
{ "scrollbar-rounding", { &style.ScrollbarRounding, 0.0F, 12.0F } },
{ "grab-min-size", { &style.GrabMinSize, 0.0F, 20.0F } },
{ "grab-rounding", { &style.GrabRounding, 0.0F, 12.0F } },
{ "tab-rounding", { &style.TabRounding, 0.0F, 12.0F } },
{ "button-text-align", { &style.ButtonTextAlign, 0.0F, 1.0F } },
{ "selectable-text-align", { &style.SelectableTextAlign, 0.0F, 1.0F } },
{ "alpha", { &style.Alpha, 0.001F, 1.0F, false } },
{ "disabled-alpha", { &style.DisabledAlpha, 0.0F, 1.0F, false } },
{ "window-padding", { &style.WindowPadding, 0.0F, 20.0F, true } },
{ "window-rounding", { &style.WindowRounding, 0.0F, 12.0F, true } },
{ "window-border-size", { &style.WindowBorderSize, 0.0F, 1.0F, true } },
{ "window-min-size", { &style.WindowMinSize, 0.0F, 1000.0F, true } },
{ "window-title-align", { &style.WindowTitleAlign, 0.0F, 1.0F , false } },
{ "child-rounding", { &style.ChildRounding, 0.0F, 12.0F, true } },
{ "child-border-size", { &style.ChildBorderSize, 0.0F, 1.0F , true } },
{ "popup-rounding", { &style.PopupRounding, 0.0F, 12.0F, true } },
{ "popup-border-size", { &style.PopupBorderSize, 0.0F, 1.0F, true } },
{ "frame-padding", { &style.FramePadding, 0.0F, 20.0F, true } },
{ "frame-rounding", { &style.FrameRounding, 0.0F, 12.0F, true } },
{ "frame-border-size", { &style.FrameBorderSize, 0.0F, 1.0F, true } },
{ "item-spacing", { &style.ItemSpacing, 0.0F, 20.0F, true } },
{ "item-inner-spacing", { &style.ItemInnerSpacing, 0.0F, 20.0F, true } },
{ "indent-spacing", { &style.IndentSpacing, 0.0F, 30.0F, true } },
{ "cell-padding", { &style.CellPadding, 0.0F, 20.0F, true } },
{ "scrollbar-size", { &style.ScrollbarSize, 0.0F, 20.0F, true } },
{ "scrollbar-rounding", { &style.ScrollbarRounding, 0.0F, 12.0F, true } },
{ "grab-min-size", { &style.GrabMinSize, 0.0F, 20.0F, true } },
{ "grab-rounding", { &style.GrabRounding, 0.0F, 12.0F, true } },
{ "tab-rounding", { &style.TabRounding, 0.0F, 12.0F, true } },
{ "button-text-align", { &style.ButtonTextAlign, 0.0F, 1.0F, false } },
{ "selectable-text-align", { &style.SelectableTextAlign, 0.0F, 1.0F, false } },
};
api::ThemeManager::addStyleHandler("imgui", ImGuiStyleMap);
@ -269,32 +269,32 @@ namespace hex::plugin::builtin {
{
auto &style = ImPlot::GetStyle();
const static api::ThemeManager::StyleMap ImPlotStyleMap = {
{ "line-weight", { &style.LineWeight, 0.0F, 5.0F } },
{ "marker-size", { &style.MarkerSize, 2.0F, 10.0F } },
{ "marker-weight", { &style.MarkerWeight, 0.0F, 5.0F } },
{ "fill-alpha", { &style.FillAlpha, 0.0F, 1.0F } },
{ "error-bar-size", { &style.ErrorBarSize, 0.0F, 10.0F } },
{ "error-bar-weight", { &style.ErrorBarWeight, 0.0F, 5.0F } },
{ "digital-bit-height", { &style.DigitalBitHeight, 0.0F, 20.0F } },
{ "digital-bit-gap", { &style.DigitalBitGap, 0.0F, 20.0F } },
{ "plot-border-size", { &style.PlotBorderSize, 0.0F, 2.0F } },
{ "minor-alpha", { &style.MinorAlpha, 0.0F, 1.0F } },
{ "major-tick-len", { &style.MajorTickLen, 0.0F, 20.0F } },
{ "minor-tick-len", { &style.MinorTickLen, 0.0F, 20.0F } },
{ "major-tick-size", { &style.MajorTickSize, 0.0F, 2.0F } },
{ "minor-tick-size", { &style.MinorTickSize, 0.0F, 2.0F } },
{ "major-grid-size", { &style.MajorGridSize, 0.0F, 2.0F } },
{ "minor-grid-size", { &style.MinorGridSize, 0.0F, 2.0F } },
{ "plot-padding", { &style.PlotPadding, 0.0F, 20.0F } },
{ "label-padding", { &style.LabelPadding, 0.0F, 20.0F } },
{ "legend-padding", { &style.LegendPadding, 0.0F, 20.0F } },
{ "legend-inner-padding", { &style.LegendInnerPadding, 0.0F, 10.0F } },
{ "legend-spacing", { &style.LegendSpacing, 0.0F, 5.0F } },
{ "mouse-pos-padding", { &style.MousePosPadding, 0.0F, 20.0F } },
{ "annotation-padding", { &style.AnnotationPadding, 0.0F, 5.0F } },
{ "fit-padding", { &style.FitPadding, 0.0F, 0.2F } },
{ "plot-default-size", { &style.PlotDefaultSize, 0.0F, 1000.0F } },
{ "plot-min-size", { &style.PlotMinSize, 0.0F, 300.0F } },
{ "line-weight", { &style.LineWeight, 0.0F, 5.0F, true } },
{ "marker-size", { &style.MarkerSize, 2.0F, 10.0F, true } },
{ "marker-weight", { &style.MarkerWeight, 0.0F, 5.0F, true } },
{ "fill-alpha", { &style.FillAlpha, 0.0F, 1.0F, false } },
{ "error-bar-size", { &style.ErrorBarSize, 0.0F, 10.0F, true } },
{ "error-bar-weight", { &style.ErrorBarWeight, 0.0F, 5.0F, true } },
{ "digital-bit-height", { &style.DigitalBitHeight, 0.0F, 20.0F, true } },
{ "digital-bit-gap", { &style.DigitalBitGap, 0.0F, 20.0F, true } },
{ "plot-border-size", { &style.PlotBorderSize, 0.0F, 2.0F, true } },
{ "minor-alpha", { &style.MinorAlpha, 0.0F, 1.0F, false } },
{ "major-tick-len", { &style.MajorTickLen, 0.0F, 20.0F, true } },
{ "minor-tick-len", { &style.MinorTickLen, 0.0F, 20.0F, true } },
{ "major-tick-size", { &style.MajorTickSize, 0.0F, 2.0F, true } },
{ "minor-tick-size", { &style.MinorTickSize, 0.0F, 2.0F, true } },
{ "major-grid-size", { &style.MajorGridSize, 0.0F, 2.0F, true } },
{ "minor-grid-size", { &style.MinorGridSize, 0.0F, 2.0F, true } },
{ "plot-padding", { &style.PlotPadding, 0.0F, 20.0F, true } },
{ "label-padding", { &style.LabelPadding, 0.0F, 20.0F, true } },
{ "legend-padding", { &style.LegendPadding, 0.0F, 20.0F, true } },
{ "legend-inner-padding", { &style.LegendInnerPadding, 0.0F, 10.0F, true } },
{ "legend-spacing", { &style.LegendSpacing, 0.0F, 5.0F, true } },
{ "mouse-pos-padding", { &style.MousePosPadding, 0.0F, 20.0F, true } },
{ "annotation-padding", { &style.AnnotationPadding, 0.0F, 5.0F, true } },
{ "fit-padding", { &style.FitPadding, 0.0F, 0.2F, true } },
{ "plot-default-size", { &style.PlotDefaultSize, 0.0F, 1000.0F, true } },
{ "plot-min-size", { &style.PlotMinSize, 0.0F, 300.0F, true } },
};
api::ThemeManager::addStyleHandler("implot", ImPlotStyleMap);
@ -303,21 +303,21 @@ namespace hex::plugin::builtin {
{
auto &style = ImNodes::GetStyle();
const static api::ThemeManager::StyleMap ImNodesStyleMap = {
{ "grid-spacing", { &style.GridSpacing, 0.0F, 100.0F } },
{ "node-corner-rounding", { &style.NodeCornerRounding, 0.0F, 12.0F } },
{ "node-padding", { &style.NodePadding, 0.0F, 20.0F } },
{ "node-border-thickness", { &style.NodeBorderThickness, 0.0F, 1.0F } },
{ "link-thickness", { &style.LinkThickness, 0.0F, 10.0F } },
{ "link-line-segments-per-length", { &style.LinkLineSegmentsPerLength, 0.0F, 2.0F } },
{ "link-hover-distance", { &style.LinkHoverDistance, 0.0F, 20.0F } },
{ "pin-circle-radius", { &style.PinCircleRadius, 0.0F, 20.0F } },
{ "pin-quad-side-length", { &style.PinQuadSideLength, 0.0F, 20.0F } },
{ "pin-triangle-side-length", { &style.PinTriangleSideLength, 0.0F, 20.0F } },
{ "pin-line-thickness", { &style.PinLineThickness, 0.0F, 5.0F } },
{ "pin-hover-radius", { &style.PinHoverRadius, 0.0F, 20.0F } },
{ "pin-offset", { &style.PinOffset, -10.0F, 10.0F } },
{ "mini-map-padding", { &style.MiniMapPadding, 0.0F, 20.0F } },
{ "mini-map-offset", { &style.MiniMapOffset, -10.0F, 10.0F } },
{ "grid-spacing", { &style.GridSpacing, 0.0F, 100.0F, true } },
{ "node-corner-rounding", { &style.NodeCornerRounding, 0.0F, 12.0F, true } },
{ "node-padding", { &style.NodePadding, 0.0F, 20.0F, true } },
{ "node-border-thickness", { &style.NodeBorderThickness, 0.0F, 1.0F, true } },
{ "link-thickness", { &style.LinkThickness, 0.0F, 10.0F, true } },
{ "link-line-segments-per-length", { &style.LinkLineSegmentsPerLength, 0.0F, 2.0F, true } },
{ "link-hover-distance", { &style.LinkHoverDistance, 0.0F, 20.0F, true } },
{ "pin-circle-radius", { &style.PinCircleRadius, 0.0F, 20.0F, true } },
{ "pin-quad-side-length", { &style.PinQuadSideLength, 0.0F, 20.0F, true } },
{ "pin-triangle-side-length", { &style.PinTriangleSideLength, 0.0F, 20.0F, true } },
{ "pin-line-thickness", { &style.PinLineThickness, 0.0F, 5.0F, true } },
{ "pin-hover-radius", { &style.PinHoverRadius, 0.0F, 20.0F, true } },
{ "pin-offset", { &style.PinOffset, -10.0F, 10.0F, true } },
{ "mini-map-padding", { &style.MiniMapPadding, 0.0F, 20.0F, true } },
{ "mini-map-offset", { &style.MiniMapOffset, -10.0F, 10.0F, true } },
};
api::ThemeManager::addStyleHandler("imnodes", ImNodesStyleMap);

View File

@ -91,7 +91,7 @@ namespace hex::plugin::builtin {
}
{
this->m_blockSize = std::max<u32>(std::ceil(provider->getSize() / 2048.0F), 256);
this->m_blockSize = std::max<u32>(std::ceil(provider->getActualSize() / 2048.0F), 256);
this->m_averageEntropy = -1.0;
this->m_highestBlockEntropy = -1.0;
@ -103,9 +103,9 @@ namespace hex::plugin::builtin {
this->m_digram.reset(this->m_inputEndAddress - this->m_inputStartAddress);
this->m_layeredDistribution.reset(this->m_inputEndAddress - this->m_inputStartAddress);
this->m_byteTypesDistribution.reset(this->m_inputStartAddress, this->m_inputEndAddress,
provider->getBaseAddress(), provider->getSize());
provider->getBaseAddress(), provider->getActualSize());
this->m_chunkBasedEntropy.reset(this->m_inputChunkSize, this->m_inputStartAddress, this->m_inputEndAddress,
provider->getBaseAddress(), provider->getSize());
provider->getBaseAddress(), provider->getActualSize());
// Create a handle to the file
auto reader = prv::ProviderReader(provider);

View File

@ -42,7 +42,7 @@ namespace hex::plugin::builtin {
for (auto &[name, handler] : api::ThemeManager::getStyleHandlers()) {
if (ImGui::CollapsingHeader(name.c_str())) {
for (auto &[styleName, style] : handler.styleMap) {
auto &[value, min, max] = style;
auto &[value, min, max, needsScaling] = style;
if (auto floatValue = std::get_if<float*>(&value); floatValue != nullptr)
ImGui::SliderFloat(styleName.c_str(), *floatValue, min, max, "%.1f");

View File

@ -344,19 +344,19 @@ namespace hex::plugin::builtin::ui {
// Draw vertical line at the left of first byte and the start of the line
if (x == 0 || byteAddress == selection.getStartAddress())
drawList->AddLine(cellPos, cellPos + ImVec2(0, cellSize.y), ImColor(SelectionFrameColor), 1.0F);
drawList->AddLine(cellPos, cellPos + ImVec2(0, cellSize.y), ImColor(SelectionFrameColor), 1_scaled);
// Draw vertical line at the right of the last byte and the end of the line
if (x == u16((this->m_bytesPerRow / bytesPerCell) - 1) || (byteAddress + bytesPerCell) > selection.getEndAddress())
drawList->AddLine(cellPos + ImVec2(cellSize.x, -1), cellPos + cellSize, ImColor(SelectionFrameColor), 1.0F);
drawList->AddLine(cellPos + ImVec2(cellSize.x, -1), cellPos + cellSize, ImColor(SelectionFrameColor), 1_scaled);
// Draw horizontal line at the top of the bytes
if (y == 0 || (byteAddress - this->m_bytesPerRow) < selection.getStartAddress())
drawList->AddLine(cellPos, cellPos + ImVec2(cellSize.x + 1, 0), ImColor(SelectionFrameColor), 1.0F);
drawList->AddLine(cellPos, cellPos + ImVec2(cellSize.x + 1, 0), ImColor(SelectionFrameColor), 1_scaled);
// Draw horizontal line at the bottom of the bytes
if ((byteAddress + this->m_bytesPerRow) > selection.getEndAddress())
drawList->AddLine(cellPos + ImVec2(0, cellSize.y), cellPos + cellSize + ImVec2(1, 0), ImColor(SelectionFrameColor), 1.0F);
drawList->AddLine(cellPos + ImVec2(0, cellSize.y), cellPos + cellSize + ImVec2(1, 0), ImColor(SelectionFrameColor), 1_scaled);
}
void HexEditor::drawEditor(const ImVec2 &size) {
@ -457,7 +457,7 @@ namespace hex::plugin::builtin::ui {
}
// Draw byte columns
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(3, 0));
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, scaled(ImVec2(2.75F, 0.0F)));
for (u64 x = 0; x < columnCount; x++) {
const u64 byteAddress = y * this->m_bytesPerRow + x * bytesPerCell + this->m_provider->getBaseAddress() + this->m_provider->getCurrentPageAddress();
@ -468,7 +468,7 @@ namespace hex::plugin::builtin::ui {
if (x < std::ceil(float(validBytes) / bytesPerCell)) {
auto cellStartPos = getCellPosition();
auto cellSize = (CharacterSize * ImVec2(this->m_currDataVisualizer->getMaxCharsPerCell(), 1) + (ImVec2(3, 2) * ImGui::GetStyle().CellPadding) - ImVec2(1, 0) * ImGui::GetStyle().CellPadding) + scaled(ImVec2(1 + this->m_byteCellPadding, 0));
auto cellSize = (CharacterSize * ImVec2(this->m_currDataVisualizer->getMaxCharsPerCell(), 1)) + (ImVec2(2, 2) * ImGui::GetStyle().CellPadding) + scaled(ImVec2(1 + this->m_byteCellPadding, 0));
auto maxCharsPerCell = this->m_currDataVisualizer->getMaxCharsPerCell();
auto [foregroundColor, backgroundColor] = cellColors[x];