Skip to content

Commit

Permalink
Adv: Style fixes, logic simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 11, 2023
1 parent 8c7e201 commit abf6460
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 124 deletions.
27 changes: 21 additions & 6 deletions src/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,9 @@ void Framework::draw_ui() {
ImGui::Columns(1);

// Mods:
sidebar_entries.insert(sidebar_entries.begin(), {"About", false});
auto& sidebar_entries = m_sidebar_state.entries;
sidebar_entries.clear();
sidebar_entries.emplace_back("About", false);

if (ImGui::BeginTable("UEVRTable", 2, ImGuiTableFlags_::ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_::ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_::ImGuiTableFlags_SizingFixedFit)) {
ImGui::TableSetupColumn("UEVRLeftPaneColumn", ImGuiTableColumnFlags_WidthFixed, 150.0f);
Expand Down Expand Up @@ -1219,14 +1221,29 @@ void Framework::draw_ui() {
std::vector<Info> mod_sidebar_ranges{};

for (auto& mod : m_mods->get_mods()) {
if (mod->is_advanced_mod() && !m_advanced_view_enabled) {
continue;
}

auto entries = mod->get_sidebar_entries();

if (!entries.empty()) {
mod_sidebar_ranges.push_back(Info{sidebar_entries.size(), sidebar_entries.size() + entries.size(), mod, true});
sidebar_entries.insert(sidebar_entries.end(), entries.begin(), entries.end());
size_t displayed_entries = 0;
for (auto& entry : entries) {
if (entry.m_advanced_entry && !m_advanced_view_enabled) {
continue;
}

sidebar_entries.emplace_back(entry.m_label.c_str(), entry.m_advanced_entry);
++displayed_entries;
}

if (displayed_entries > 0) {
mod_sidebar_ranges.push_back(Info{sidebar_entries.size() - displayed_entries, sidebar_entries.size(), mod, true});
}
} else {
mod_sidebar_ranges.push_back(Info{sidebar_entries.size(), sidebar_entries.size() + 1, mod, false});
sidebar_entries.push_back({mod->get_name().data(), mod->is_advanced_mod()} );
sidebar_entries.emplace_back(mod->get_name().data(), mod->is_advanced_mod());
}
}

Expand Down Expand Up @@ -1348,8 +1365,6 @@ void Framework::draw_ui() {
if (m_last_draw_ui && !m_draw_ui) {
m_windows_message_hook->window_toggle_cursor(m_cursor_state);
}

sidebar_entries.clear();
}

void Framework::draw_about() {
Expand Down
31 changes: 10 additions & 21 deletions src/Framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class UEVRSharedMemory {
Data* m_data{};
};


struct SidebarEntryInfo {
SidebarEntryInfo(std::string_view label, bool advanced) : m_label(label), m_advanced_entry(advanced) {}

std::string m_label{};
bool m_advanced_entry{false};
};
Expand Down Expand Up @@ -196,14 +197,8 @@ class Framework {
if (delta < std::chrono::milliseconds(100)) {
return;
}
int32_t selected_entry_local = m_sidebar_state.selected_entry + 1;
if (!m_advanced_view_enabled) {
while (sidebar_entries[selected_entry_local].m_advanced_entry) {
++selected_entry_local;
}
}
m_sidebar_state.selected_entry = selected_entry_local;

++m_sidebar_state.selected_entry;
m_last_page_inc_time = now;
}

Expand All @@ -213,27 +208,20 @@ class Framework {
if (delta < std::chrono::milliseconds(100)) {
return;
}
int32_t selected_entry_local = m_sidebar_state.selected_entry - 1;
if (!m_advanced_view_enabled) {
while (sidebar_entries[selected_entry_local].m_advanced_entry) {
--selected_entry_local;
}
}
m_sidebar_state.selected_entry = selected_entry_local;

--m_sidebar_state.selected_entry;
m_last_page_dec_time = now;
}

bool is_advanced_view_enabled() const {
return m_advanced_view_enabled;
}

private:
void consume_input();
void update_fonts();
void invalidate_device_objects();

public:
bool is_advanced_view_enabled() {
return m_advanced_view_enabled;
}

private:
void draw_ui();
void draw_about();
Expand Down Expand Up @@ -273,7 +261,6 @@ class Framework {
bool m_cursor_state_changed{true};
bool m_ui_option_transparent{true};
bool m_ui_passthrough{false};
std::vector<SidebarEntryInfo> sidebar_entries{};

ImVec2 m_last_window_pos{};
ImVec2 m_last_window_size{};
Expand Down Expand Up @@ -339,6 +326,8 @@ class Framework {
struct {
int32_t selected_entry{0};
bool initialized{false};

std::vector<SidebarEntryInfo> entries{};
} m_sidebar_state{};

template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>;
Expand Down
Loading

0 comments on commit abf6460

Please sign in to comment.