MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextRow.cpp
Go to the documentation of this file.
1#include "TextRow.hpp"
2
3#include "Atelier.hpp"
4
6
8
9glm::vec4 row_idle_color() { return { 0.18F, 0.18F, 0.20F, 1.F }; }
10
11glm::vec4 row_hover_color() { return { 0.32F, 0.32F, 0.36F, 1.F }; }
12
13std::string row_caption(std::string_view label)
14{
15 return " " + std::string(label);
16}
17
18Text::PressParams row_press_params(glm::uvec2 dims, glm::vec4 background)
19{
20 return {
21 .color = { 1.F, 1.F, 1.F, 1.F },
22 .background = background,
23 .render_bounds = dims,
24 .budget_h = dims.y,
25 };
26}
27
28std::pair<uint32_t, std::shared_ptr<Element>> add_text_row(
29 Surface& surface,
30 std::string_view label,
31 Kinesis::AABB2D bounds,
32 glm::uvec2 dims,
33 const std::shared_ptr<Buffers::FormaBuffer>& batch)
34{
35 FormaTarget buf = batch
38 surface.render_config({ .additional_textures = { { "text", nullptr } } })));
39
40 auto row = std::make_shared<Element>();
41 row->with_name(std::string(label))
42 .with_bounds(bounds)
43 .with_buffer(buf)
44 .with_text(row_caption(label), row_press_params(dims, row_idle_color()), bounds);
45
46 return { surface.add(*row), row };
47}
48
50 Surface& surface,
51 uint32_t id,
52 const std::shared_ptr<Element>& row,
53 std::string_view label,
54 const std::shared_ptr<glm::uvec2>& dims)
55{
56 const std::string caption = row_caption(label);
57
58 surface.ctx().on_enter(id, [row, caption, dims](uint32_t) {
59 row->set_text(caption, row_press_params(*dims, row_hover_color()));
60 });
61 surface.ctx().on_leave(id, [row, caption, dims](uint32_t) {
62 row->set_text(caption, row_press_params(*dims, row_idle_color()));
63 });
64}
65
66} // namespace MayaFlux::Portal::Forma::internal
uint32_t label
Definition Contours.cpp:16
void on_enter(uint32_t id, EnterFn fn)
Called once when the cursor enters an element's region.
Definition Context.cpp:58
void on_leave(uint32_t id, LeaveFn fn)
Called once when the cursor leaves an element's region.
Definition Context.cpp:63
static FormaTarget slice_of(const std::shared_ptr< Buffers::FormaBuffer > &buffer, std::optional< Graphics::PrimitiveTopology > topology=std::nullopt)
A new empty slice of buffer, drawn after the others.
Definition Target.cpp:19
Where an element's geometry and texture are written.
Definition Target.hpp:22
Portal::Graphics::RenderConfig render_config(Portal::Graphics::RenderConfig base={}) const
base targeting this Surface's window.
Definition Surface.hpp:227
Context & ctx() noexcept
Access the event router.
Definition Surface.hpp:170
Named owner of a (Window, Layer, Context) triple: the Forma canvas.
Definition Surface.hpp:121
Text::PressParams row_press_params(glm::uvec2 dims, glm::vec4 background)
White text over background, laid out at dims pixels.
Definition TextRow.cpp:18
std::pair< uint32_t, std::shared_ptr< Element > > add_text_row(Surface &surface, std::string_view label, Kinesis::AABB2D bounds, glm::uvec2 dims, const std::shared_ptr< Buffers::FormaBuffer > &batch)
Register a clickable text row on surface.
Definition TextRow.cpp:28
Atelier & atelier()
Accessor for the process-wide Atelier.
Definition Atelier.hpp:304
void hover_text_row(Surface &surface, uint32_t id, const std::shared_ptr< Element > &row, std::string_view label, const std::shared_ptr< glm::uvec2 > &dims)
Highlight a row's background while the cursor is over it.
Definition TextRow.cpp:49
std::string row_caption(std::string_view label)
Caption drawn for a row labelled label.
Definition TextRow.cpp:13
std::shared_ptr< Buffers::FormaBuffer > create_buffer(Graphics::RenderConfig render)
Construct and register a FormaBuffer without creating a Mapped<T>.
Definition Forma.cpp:103
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
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