ui: Added global running tasks progress bar

This commit is contained in:
WerWolv
2021-12-16 23:48:52 +01:00
parent 677036fb9c
commit 891cc42f08
18 changed files with 193 additions and 29 deletions

View File

@@ -9,10 +9,6 @@
namespace hex {
void ImHexApi::Common::sayHello() {
log::warn("Hello!");
}
void ImHexApi::Common::closeImHex(bool noQuestions) {
EventManager::post<RequestCloseImHex>(noQuestions);
}
@@ -85,4 +81,9 @@ namespace hex {
delete provider;
}
Task ImHexApi::Tasks::createTask(const std::string &unlocalizedName, u64 maxValue) {
return Task(unlocalizedName, maxValue);
}
}

View File

@@ -0,0 +1,32 @@
#include <hex/api/task.hpp>
#include <hex/helpers/shared_data.hpp>
namespace hex {
Task::Task(const std::string& unlocalizedName, u64 maxValue) : m_name(LangEntry(unlocalizedName)), m_maxValue(maxValue), m_currValue(0) {
SharedData::runningTasks.push_back(this);
}
Task::~Task() {
this->finish();
}
void Task::finish() {
SharedData::runningTasks.remove(this);
}
void Task::update(u64 currValue) {
if (this->m_currValue < this->m_maxValue)
this->m_currValue = currValue;
}
double Task::getProgress() const {
return static_cast<double>(this->m_currValue) / static_cast<double>(this->m_maxValue);
}
const std::string& Task::getName() const {
return this->m_name;
}
}

View File

@@ -29,6 +29,9 @@ namespace hex {
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::footerItems;
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::toolbarItems;
std::mutex SharedData::tasksMutex;
std::list<Task*> SharedData::runningTasks;
std::vector<std::string> SharedData::providerNames;
std::vector<ContentRegistry::DataProcessorNode::impl::Entry> SharedData::dataProcessorNodes;