MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ layout_legend()

MAYAFLUX_API LegendLayout MayaFlux::Portal::Forma::Plot::layout_legend ( const LegendSpec spec)

Expand a legend spec into swatch rectangle specs and text label specs.

Definition at line 346 of file PlotSpec.cpp.

347{
348 LegendLayout layout;
349 layout.swatches.reserve(spec.entries.size());
350 layout.labels.reserve(spec.entries.size());
351
352 for (size_t i = 0; i < spec.entries.size(); ++i) {
353 const float y_top = spec.origin.y
354 - static_cast<float>(i) * (spec.row_h + spec.gap);
355 const float y_bot = y_top - spec.row_h;
356
357 const Kinesis::AABB2D swatch_bounds {
358 .min = { spec.origin.x, y_bot },
359 .max = { spec.origin.x + spec.swatch_w, y_top },
360 };
361
362 const Kinesis::AABB2D text_bounds {
363 .min = { spec.origin.x + spec.swatch_w + spec.gap, y_bot },
364 .max = { spec.origin.x + spec.swatch_w + spec.gap + spec.text_w, y_top },
365 };
366
367 layout.swatches.push_back(RectSpec {
368 .bounds = swatch_bounds,
369 .color = spec.entries[i].color,
370 .name = spec.name_prefix + "_swatch_" + std::to_string(i),
371 .interactive = spec.interactive,
372 });
373
374 layout.labels.push_back(LabelSpec {
375 .text = spec.entries[i].label,
376 .bounds = text_bounds,
377 .color = spec.text_color,
378 .name = spec.name_prefix + "_label_" + std::to_string(i),
379 .interactive = spec.interactive,
380 });
381 }
382
383 return layout;
384}
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
Expanded construction-free legend layout.
Definition PlotSpec.hpp:128
std::vector< LegendEntry > entries
Definition PlotSpec.hpp:109

References MayaFlux::Portal::Forma::Plot::RectSpec::bounds, MayaFlux::Portal::Forma::Plot::LegendSpec::entries, MayaFlux::Portal::Forma::Plot::LegendSpec::gap, MayaFlux::Portal::Forma::Plot::LegendSpec::interactive, MayaFlux::Portal::Forma::Plot::LegendLayout::labels, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Plot::LegendSpec::name_prefix, MayaFlux::Portal::Forma::Plot::LegendSpec::origin, MayaFlux::Portal::Forma::Plot::LegendSpec::row_h, MayaFlux::Portal::Forma::Plot::LegendSpec::swatch_w, MayaFlux::Portal::Forma::Plot::LegendLayout::swatches, MayaFlux::Portal::Forma::Plot::LabelSpec::text, MayaFlux::Portal::Forma::Plot::LegendSpec::text_color, and MayaFlux::Portal::Forma::Plot::LegendSpec::text_w.