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

◆ place_label()

MAYAFLUX_API uint32_t MayaFlux::Portal::Forma::Plot::place_label ( Surface &  surface,
FormaTarget  buf,
const LabelSpec &  spec,
uint32_t  relate_to = 0 
)

Place a text label element onto surface using a text-capable target.

buf must have been created with an additional_textures slot named "text" (or equivalent). Buffer construction is the caller's responsibility; Portal::Forma::plot() handles this automatically.

Parameters
surfaceTarget surface.
bufTRIANGLE_LIST slice of a text-capable buffer. Labels may share that buffer.
specLabel geometry and style.
relate_toIf non-zero, the produced element is related to this id.
Returns
Element id of the produced label element.

Definition at line 15 of file Plot.cpp.

20{
21 const bool auto_render_bounds = spec.render_bounds.x <= 0 || spec.render_bounds.y <= 0;
22
23 const auto render_bounds = auto_render_bounds
24 ? Kinesis::ndc_size_to_pixels(
25 { spec.bounds.width(), spec.bounds.height() },
26 surface.window()->get_state().current_width,
27 surface.window()->get_state().current_height)
28 : spec.render_bounds;
29
30 Element el;
31 el.with_buffer(buf)
32 .with_bounds(spec.bounds)
33 .with_name(spec.name)
34 .with_text(spec.text,
36 .color = spec.color,
37 .render_bounds = render_bounds,
38 },
39 spec.bounds);
40
41 if (!spec.interactive)
42 el.non_interactive();
43
44 const uint32_t id = surface.layer().add(std::move(el));
45 if (relate_to != 0)
46 surface.layer().relate(relate_to, id);
47
48 if (auto_render_bounds) {
49 surface.ctx().on_resize(id,
50 [surface, id, text = spec.text, color = spec.color, bounds = spec.bounds](uint32_t, uint32_t) mutable {
51 const auto dims = Kinesis::ndc_size_to_pixels(
52 { bounds.width(), bounds.height() },
53 surface.window()->get_state().current_width,
54 surface.window()->get_state().current_height);
55
56 if (auto* element = surface.layer().get(id))
57 element->set_text(text, Portal::Text::PressParams { .color = color, .render_bounds = dims });
58 });
59 }
60
61 return id;
62}
glm::vec3 color
Definition Decoder.cpp:97
void on_resize(uint32_t id, ResizeFn fn)
Called on every window resize.
Definition Context.cpp:136
bool relate(uint32_t primary_id, uint32_t related_id)
Record that related_id belongs with primary_id.
Definition Layer.cpp:205
const Element * get(uint32_t id) const
Definition Layer.cpp:272
Slot add(Element element)
Add an element to the layer.
Definition Layer.cpp:9
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:178
Context & ctx() noexcept
Access the event router.
Definition Surface.hpp:170
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:159
float height() const noexcept
Definition Bounds.hpp:80
float width() const noexcept
Definition Bounds.hpp:79
Element & with_bounds(Kinesis::AABB2D b)
Set the fast-reject AABB.
Definition Element.hpp:109
Element & non_interactive()
Exclude from hit testing.
Definition Element.hpp:279
Element & with_buffer(FormaTarget target)
Attach a FormaBuffer, or a slice of one, as the rendered output for this region.
Definition Element.hpp:195
Element & with_text(std::string_view text, std::optional< Portal::Text::PressParams > params, Kinesis::AABB2D region={ .min=glm::vec2(-1.F),.max=glm::vec2(1.F) })
Draw text as glyph quads into the attached buffer.
Definition Element.cpp:41
Element & with_name(std::string n)
Set the human-readable name used in Lila introspection and debug output.
Definition Element.hpp:304
A bounded, renderable region on a window surface.
Definition Element.hpp:61
std::string name
Optional logical name for the eventual Element.
Definition PlotSpec.hpp:43
glm::uvec2 render_bounds
Optional text pixel/render size override.
Definition PlotSpec.hpp:56
bool interactive
Whether the eventual Element should participate in hit testing.
Definition PlotSpec.hpp:49
glm::vec4 color
RGBA color applied to all glyphs not covered by a span in spans.
Definition InkPress.hpp:70
Construction parameters for press().
Definition InkPress.hpp:65

References MayaFlux::Portal::Forma::Layer::add(), MayaFlux::Portal::Forma::Plot::LabelSpec::bounds, color, MayaFlux::Portal::Forma::Plot::LabelSpec::color, MayaFlux::Portal::Text::PressParams::color, MayaFlux::Portal::Forma::Surface::ctx(), MayaFlux::Portal::Forma::Layer::get(), MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Portal::Forma::Plot::LabelSpec::interactive, MayaFlux::Portal::Forma::Surface::layer(), MayaFlux::Portal::Forma::Plot::LabelSpec::name, MayaFlux::Kinesis::ndc_size_to_pixels(), MayaFlux::Portal::Forma::Element::non_interactive(), MayaFlux::Portal::Forma::Context::on_resize(), MayaFlux::Portal::Forma::Layer::relate(), MayaFlux::Portal::Forma::Plot::LabelSpec::render_bounds, MayaFlux::Portal::Forma::Plot::LabelSpec::text, MayaFlux::Kinesis::AABB2D::width(), MayaFlux::Portal::Forma::Surface::window(), MayaFlux::Portal::Forma::Element::with_bounds(), MayaFlux::Portal::Forma::Element::with_buffer(), MayaFlux::Portal::Forma::Element::with_name(), and MayaFlux::Portal::Forma::Element::with_text().

Referenced by MayaFlux::Portal::Forma::internal::Atelier::place_adornments().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: