mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Get the format part of the new control panel working.
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
using namespace hex;
|
using namespace hex;
|
||||||
|
|
||||||
|
static DynamicSettingFactory settings("fluxengine.settings");
|
||||||
|
|
||||||
SummaryView::SummaryView():
|
SummaryView::SummaryView():
|
||||||
View::Window("fluxengine.view.summary.name", ICON_VS_DEBUG_LINE_BY_LINE)
|
View::Window("fluxengine.view.summary.name", ICON_VS_DEBUG_LINE_BY_LINE)
|
||||||
{
|
{
|
||||||
@@ -44,12 +46,8 @@ static void loadFluxFile()
|
|||||||
{},
|
{},
|
||||||
[](const auto& path)
|
[](const auto& path)
|
||||||
{
|
{
|
||||||
hex::ContentRegistry::Settings::write<std::fs::path>(
|
settings.get<std::string>("device") = DEVICE_FLUXFILE;
|
||||||
FLUXENGINE_CONFIG,
|
settings.get<std::fs::path>("fluxfile") = path;
|
||||||
"fluxengine.settings.device",
|
|
||||||
DEVICE_FLUXFILE);
|
|
||||||
hex::ContentRegistry::Settings::write<std::fs::path>(
|
|
||||||
FLUXENGINE_CONFIG, "fluxengine.settings.fluxfile", path);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,8 +193,7 @@ static void drawDeviceBox()
|
|||||||
/* Device name */
|
/* Device name */
|
||||||
|
|
||||||
std::set<int> applicableOptions = {ANY_SOURCESINK};
|
std::set<int> applicableOptions = {ANY_SOURCESINK};
|
||||||
auto deviceNameSetting =
|
auto deviceNameSetting = settings.get<std::string>("device");
|
||||||
DynamicSetting<std::string>("fluxengine.settings", "device");
|
|
||||||
auto selectedDevice = findOrDefault(Datastore::getDevices(),
|
auto selectedDevice = findOrDefault(Datastore::getDevices(),
|
||||||
(std::string)deviceNameSetting,
|
(std::string)deviceNameSetting,
|
||||||
{.label = "No device configured"});
|
{.label = "No device configured"});
|
||||||
@@ -222,7 +219,7 @@ static void drawDeviceBox()
|
|||||||
applicableOptions.insert(HARDWARE_SOURCESINK);
|
applicableOptions.insert(HARDWARE_SOURCESINK);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::BeginCombo("##format", nullptr, ImGuiComboFlags_NoPreview))
|
if (ImGui::BeginCombo("##devices", nullptr, ImGuiComboFlags_NoPreview))
|
||||||
{
|
{
|
||||||
ON_SCOPE_EXIT
|
ON_SCOPE_EXIT
|
||||||
{
|
{
|
||||||
@@ -244,8 +241,7 @@ static void drawDeviceBox()
|
|||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
ImGui::Text(fmt::format("{}:", label));
|
ImGui::Text(fmt::format("{}:", label));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
auto pathSetting =
|
auto pathSetting = settings.get<std::string>(setting);
|
||||||
DynamicSetting<std::string>("fluxengine.settings", setting);
|
|
||||||
auto pathString = (std::string)pathSetting;
|
auto pathString = (std::string)pathSetting;
|
||||||
ImGui::SetNextItemWidth(-FLT_MIN);
|
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||||
if (ImGui::InputText(id.c_str(),
|
if (ImGui::InputText(id.c_str(),
|
||||||
@@ -288,31 +284,46 @@ void drawFormatBox()
|
|||||||
|
|
||||||
/* Format name */
|
/* Format name */
|
||||||
|
|
||||||
auto formatName =
|
auto formatSetting =
|
||||||
hex::ContentRegistry::Settings::read<std::string>(FLUXENGINE_CONFIG,
|
settings.get<std::string>("format.selected", "ibm");
|
||||||
"fluxengine.settings.format.selected",
|
auto selectedFormat =
|
||||||
DEVICE_FLUXFILE);
|
findOrDefault(formats, (std::string)formatSetting);
|
||||||
auto format = findOrDefault(formats, formatName);
|
if (!selectedFormat)
|
||||||
if (!format)
|
|
||||||
{
|
{
|
||||||
ImGui::Text("***bad***");
|
formatSetting = "ibm";
|
||||||
return;
|
selectedFormat = formats.at(formatSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Text(fmt::format("{}:", "fluxengine.view.summary.format"_lang));
|
ImGui::Text(fmt::format("{}:", "fluxengine.view.summary.format"_lang));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
ImGui::Text(format->shortname());
|
ImGui::TextWrapped(selectedFormat->shortname().c_str());
|
||||||
ImGui::Text(format->comment());
|
ImGui::TextWrapped(selectedFormat->comment().c_str());
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
|
|
||||||
auto formatOptionsSetting =
|
ImGui::SameLine();
|
||||||
DynamicSetting<std::string>("fluxengine.settings", formatName);
|
if (ImGui::BeginCombo("##formats", nullptr, ImGuiComboFlags_NoPreview))
|
||||||
emitOptions(formatOptionsSetting, format, {});
|
{
|
||||||
|
ON_SCOPE_EXIT
|
||||||
|
{
|
||||||
|
ImGui::EndCombo();
|
||||||
|
};
|
||||||
|
|
||||||
ImGui::Button(
|
for (auto& [name, format] : formats)
|
||||||
fmt::format("{}##format", "fluxengine.view.summary.edit"_lang)
|
if (!format->is_extension())
|
||||||
.c_str());
|
{
|
||||||
|
auto label = format->shortname();
|
||||||
|
if (label.empty())
|
||||||
|
label = name;
|
||||||
|
if (ImGui::Selectable(
|
||||||
|
fmt::format("{}##{}", label, name).c_str(), false))
|
||||||
|
formatSetting = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto formatOptionsSetting = DynamicSetting<std::string>(
|
||||||
|
"fluxengine.settings", (std::string)formatSetting);
|
||||||
|
emitOptions(formatOptionsSetting, selectedFormat, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,3 +56,18 @@ private:
|
|||||||
const T _defaultValue;
|
const T _defaultValue;
|
||||||
std::optional<T> _cachedValue;
|
std::optional<T> _cachedValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DynamicSettingFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DynamicSettingFactory(const std::string& path): _path(path) {}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
DynamicSetting<T> get(std::string_view leaf, T defaultValue = T())
|
||||||
|
{
|
||||||
|
return DynamicSetting<T>(_path, leaf, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string _path;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user