Afegides les opcions a Service Menu
This commit is contained in:
@@ -216,4 +216,26 @@ class ActionListOption : public MenuOption {
|
||||
|
||||
void updateCurrentIndex();
|
||||
[[nodiscard]] auto findCurrentIndex() const -> size_t;
|
||||
};
|
||||
|
||||
// Opción genérica con callbacks: getter para mostrar, adjuster(bool up) para cambiar valor
|
||||
class CallbackOption : public MenuOption {
|
||||
public:
|
||||
CallbackOption(const std::string& cap, ServiceMenu::SettingsGroup grp, std::function<std::string()> getter, std::function<void(bool)> adjuster, std::function<int(Text*)> max_width_fn = nullptr)
|
||||
: MenuOption(cap, grp),
|
||||
getter_(std::move(getter)),
|
||||
adjuster_(std::move(adjuster)),
|
||||
max_width_fn_(std::move(max_width_fn)) {}
|
||||
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::ADJUST; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override { return getter_(); }
|
||||
void adjustValue(bool adjust_up) override { adjuster_(adjust_up); }
|
||||
auto getMaxValueWidth(Text* text_renderer) const -> int override {
|
||||
return max_width_fn_ ? max_width_fn_(text_renderer) : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<std::string()> getter_;
|
||||
std::function<void(bool)> adjuster_;
|
||||
std::function<int(Text*)> max_width_fn_;
|
||||
};
|
||||
Reference in New Issue
Block a user