Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/avnd/concepts/dynamic_items.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

/* SPDX-License-Identifier: GPL-3.0-or-later */

#include <avnd/concepts/parameter.hpp>

#include <functional>
#include <string>
#include <vector>

namespace avnd
{
// enum-ish parameter carrying an update_items callback for runtime item lists.
template <typename T>
concept dynamic_items_parameter = enum_ish_parameter<T> && requires(T t) {
{
t.update_items
} -> std::convertible_to<std::function<void(std::vector<std::string>)>>;
};
}
19 changes: 19 additions & 0 deletions include/avnd/concepts/folder_items.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

/* SPDX-License-Identifier: GPL-3.0-or-later */

#include <avnd/concepts/parameter.hpp>

#include <string_view>

namespace avnd
{
// A combobox whose items are the files of a sibling folder port, populated by
// the host at edit time. The port exposes folder_port() (the sibling port's
// name) and extensions() (accepted suffixes).
template <typename T>
concept folder_items_parameter = enum_ish_parameter<T> && requires {
{ T::folder_port() } -> std::convertible_to<std::string_view>;
{ T::extensions() } -> std::convertible_to<std::string_view>;
};
}
46 changes: 46 additions & 0 deletions include/halp/dynamic_combobox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

/* SPDX-License-Identifier: GPL-3.0-or-later */

#include <halp/polyfill.hpp>
#include <halp/static_string.hpp>

#include <array>
#include <functional>
#include <string>
#include <string_view>
#include <vector>

namespace halp
{
// Combobox whose items are set at runtime via update_items. Bindings without
// support leave update_items empty and use the static range() fallback.
template <static_string lit>
struct dynamic_combobox
{
enum widget
{
combobox
};

struct range
{
std::array<std::string_view, 1> values{"-"};
int init{0};
};

static clang_buggy_consteval auto name() { return std::string_view{lit.value}; }

int value{0};

std::function<void(std::vector<std::string>)> update_items;

operator int&() noexcept { return value; }
operator const int&() const noexcept { return value; }
auto& operator=(int t) noexcept
{
value = t;
return *this;
}
};
}
52 changes: 52 additions & 0 deletions include/halp/folder_combobox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

/* SPDX-License-Identifier: GPL-3.0-or-later */

#include <halp/polyfill.hpp>
#include <halp/static_string.hpp>

#include <array>
#include <string>
#include <string_view>

namespace halp
{
// Combobox whose items are the files of a sibling folder port, listed by the
// host at edit time (and refreshed when the folder changes) — no execution
// needed. The VALUE is the selected file name (a string), so an object can use
// it directly as a file name. `folder_port` names the sibling path/folder
// port; `extensions` is a space-separated list of accepted suffixes (empty =
// all files); `init` is the initially selected file name — it stays selected
// even while the file does not exist yet, so chains of processes that write
// then read conventionally-named files keep working with default values.
template <
static_string lit, static_string folder = "Folder", static_string exts = "",
static_string init_value = "-">
struct folder_combobox
{
enum widget
{
combobox
};

struct range
{
std::array<std::string_view, 1> values{init_value.value};
std::string_view init{init_value.value};
};

static clang_buggy_consteval auto name() { return std::string_view{lit.value}; }
static clang_buggy_consteval auto folder_port() { return std::string_view{folder.value}; }
static clang_buggy_consteval auto extensions() { return std::string_view{exts.value}; }

std::string value{};

operator std::string&() noexcept { return value; }
operator const std::string&() const noexcept { return value; }
auto& operator=(std::string t) noexcept
{
value = std::move(t);
return *this;
}
};
}
Loading