16 constexpr uint32_t k_max_visible_rows = 10;
17 constexpr uint32_t k_width_px = 520;
18 constexpr uint32_t k_min_row_px = 48;
19 constexpr uint32_t k_row_padding_px = 16;
26 void finish(std::optional<size_t>
index)
34 if (
auto w =
window.lock()) {
48 std::vector<std::string> labels,
53 "Forma::pick: empty list");
60 uint32_t row_px = k_min_row_px;
62 row_px = std::max(row_px,
static_cast<uint32_t
>(atlas->pixel_size()) + k_row_padding_px);
65 const auto rows =
static_cast<uint32_t
>(labels.size());
66 const uint32_t visible = std::min(
rows, k_max_visible_rows);
67 const bool scrolling =
rows > visible;
68 const uint32_t window_h = row_px * visible + (scrolling ? row_px / 2 : 0);
73 .
title = std::move(title),
79 auto state = std::make_shared<PickerState>();
80 state->callback = std::move(
callback);
85 .name =
window->get_create_info().title,
86 .on_close = [state] { state->finish(std::nullopt); },
90 surface.
render_config({ .additional_textures = { {
"text", nullptr } } }));
92 std::optional<Scrollable> panel;
93 std::function<void(uint32_t, glm::vec2,
double,
double)> wheel;
97 wheel = panel->wheel_handler(surface);
100 const auto row_dims = std::make_shared<glm::uvec2>(k_width_px, row_px);
102 const float row_h = 2.F *
static_cast<float>(row_px) /
static_cast<float>(window_h);
103 const float gap = 2.F /
static_cast<float>(window_h);
105 for (uint32_t i = 0; i <
rows; ++i) {
106 const float top = 1.F - row_h *
static_cast<float>(i);
108 .
min = { -1.F, top - row_h + gap },
109 .max = { 1.F, top - gap },
113 const uint32_t
id = made.first;
114 const auto& row = made.second;
122 surface.ctx().on_scroll(
id, wheel);
124 surface.layer(),
id, bounds,
125 [row](Kinesis::AABB2D shifted) { row->retarget(shifted); },
#define MF_WARN(comp, ctx,...)
std::weak_ptr< Core::Window > window
static TypeFaceFoundry & instance()
@ API
API calls from external code.
@ Portal
High-level user-facing API layer.
std::string title
Window title/identifier.
Configuration for creating a single window instance.
Axis-aligned bounding rectangle in a 2D coordinate space.