Skip to content

Element Factory Functions

Joel de Guzman edited this page Feb 18, 2020 · 4 revisions

Element Factories

Trivial Elements

The empty element is an infinitely resizable element that does nothing. It is good for filling up empty spaces.

element empty();

Simple box that just fills its area with solid color.

box_element box(color color_);

A blank element which uses supplied function object as the implementation for drawing. f must match void (context const&).

template <typename F>
basic_element<F> basic(F f);

Example:

auto golden_box = basic(
   [](context const& ctx)
   {
      auto& c = ctx.canvas;
      c.begin_path();
      c.round_rect(ctx.bounds, 4);
      c.fill_style(colors::gold.opacity(0.8));
      c.fill();
   }
);

Buttons

Toggle button stays pressed after being clicked. Clicking it again releases it.

Latching button stays pressed after being clicked. Can be released only programatically.

template <typename Button, typename Label>
Button make_button(Label&& label, color body_color = get_theme().default_button_color);

template <typename Button>
Button make_button(
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

template <typename Button>
Button make_button(
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

template <typename Button>
Button make_button(
    std::uint32_t icon_code,
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

template <typename Button>
Button make_button(
    std::string_view text,
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

template <typename Button, typename Label>
Button text_button(Label&& label, bool no_frame = false);

template <typename Button>
Button text_button(
    std::string_view text,
    float size = 1.0,
    bool no_frame = false);

template <typename Button>
Button text_button(
    std::uint32_t icon_code,
    float size = 1.0,
    bool no_frame = false);

template <typename Button>
Button text_button(
    std::uint32_t icon_code,
    std::string_view text,
    float size = 1.0,
    bool no_frame = false);

template <typename Button>
Button text_button(
    std::string_view text,
    std::uint32_t icon_code,
    float size = 1.0,
    bool no_frame = false);

layered_button button(
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

layered_button button(
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

layered_button button(
    std::uint32_t icon_code,
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

layered_button button(
    std::string_view text,
    std::uint32_t icon_code,
    float size,
    color body_color = get_theme().default_button_color);

basic_toggle_button<> toggle_button(
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_toggle_button<> toggle_button(
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_toggle_button<>
toggle_button(
    std::uint32_t icon_code,
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_toggle_button<> toggle_button(
    std::string_view text,
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_latching_button<> latching_button(
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_latching_button<> latching_button(
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_latching_button<> latching_button(
    std::uint32_t icon_code,
    std::string_view text,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

basic_latching_button<> latching_button(
    std::string_view text,
    std::uint32_t icon_code,
    float size = 1.0,
    color body_color = get_theme().default_button_color);

template <typename Subject>
basic_toggle_button<proxy<Subject, basic_button>> toggle_button(Subject&& subject);

template <typename Subject>
proxy<Subject, basic_button> momentary_button(Subject&& subject);

Decorator Elements

template <std::size_t size, typename Subject>
radial_marks_element<size, Subject> radial_marks(Subject&& subject);
   
// s... can be anything accepted by std::string ctor
template <std::size_t size, typename Subject, typename... S>
radial_labels_element<size, Subject, sizeof...(S)> radial_labels(Subject&& subject, float font_size, S&&... s);

Layout and Size Control

Alignment

Align an element verically or horizontally.

template <typename Subject>
halign_element<Subject> halign(float align, Subject&& subject);

// equivalent to halign(0.0, subject)
template <typename Subject>
halign_element<Subject> align_left(Subject&& subject);

// equivalent to halign(0.5, subject)
template <typename Subject>
halign_element<Subject> align_center(Subject&& subject);

// equivalent to halign(1.0, subject)
template <typename Subject>
halign_element<Subject> align_right(Subject&& subject);

template <typename Subject>
valign_element<Subject> valign(float align, Subject&& subject);

// equivalent to valign(0.0, subject)
template <typename Subject>
valign_element<Subject> align_top(Subject&& subject);

// equivalent to valign(0.5, subject)
template <typename Subject>
valign_element<Subject> align_middle(Subject&& subject);

// equivalent to valign(1.0, subject)
template <typename Subject>
valign_element<Subject> align_bottom(Subject&& subject);

Extra Alignment Wrappers:

auto align_left_top(Subject&& subject);
auto align_center_top(Subject&& subject);
auto align_right_top(Subject&& subject);
auto align_left_middle(Subject&& subject);
auto align_center_middle(Subject&& subject);
auto align_right_middle(Subject&& subject);
auto align_left_bottom(Subject&& subject);
auto align_center_bottom(Subject&& subject);
auto align_right_bottom(Subject&& subject);

Margins

Add a margin {left, top, right, bottom} around supplied subject.

template <typename Subject>
margin_element<rect, Subject> margin(rect margin_, Subject&& subject)

Extra margin wrappers (default margin is 0):

//     left_margin_rect(x)    == rect(x, 0, 0, 0)
//    right_margin_rect(x)    == rect(0, 0, x, 0)
//      top_margin_rect(y)    == rect(0, y, 0, 0)
//   bottom_margin_rect(y)    == rect(0, 0, 0, y)
// left_top_margin_rect(x, y) == rect(x, y, 0, 0)
//    xside_margin_rect(x)    == rect(x, 0, x, 0)
//    xside_margin_rect(l, r) == rect(l, 0, r, 0)
//    yside_margin_rect(y)    == rect(0, y, 0, y)
//    yside_margin_rect(t, b) == rect(0, t, 0, b)

template <typename Subject>
margin_element<left_margin_rect, Subject> left_margin(left_margin_rect margin_, Subject&& subject);

template <typename Subject>
margin_element<right_margin_rect, Subject> right_margin(right_margin_rect margin_, Subject&& subject);

template <typename Subject>
margin_element<top_margin_rect, Subject> top_margin(top_margin_rect margin_, Subject&& subject);

template <typename Subject>
margin_element<bottom_margin_rect, Subject> bottom_margin(bottom_margin_rect margin_, Subject&& subject);

template <typename Subject>
margin_element<left_top_margin_rect, Subject> left_top_margin(left_top_margin_rect margin_, Subject&& subject);

template <typename Subject>
margin_element<xside_margin_rect, Subject> xside_margin(xside_margin_rect margin_, Subject&& subject);

template <typename Subject>
margin_element<yside_margin_rect, Subject> yside_margin(yside_margin_rect margin_, Subject&& subject);

Size Control

template <typename Subject>
size_element<Subject> fixed_size(point size, Subject&& subject);

template <typename Subject>
hsize_element<Subject> hsize(float width, Subject&& subject);

template <typename Subject>
vsize_element<Subject> vsize(float height, Subject&& subject);

template <typename Subject>
min_size_element<Subject> min_size(point size, Subject&& subject);

template <typename Subject>
hmin_size_element<Subject> hmin_size(float width, Subject&& subject);

template <typename Subject>
vmin_size_element<Subject> vmin_size(float height, Subject&& subject);

template <typename Subject>
vmin_size_element<Subject> vmin_size(float height, Subject&& subject);

template <typename Subject>
hstretch_element<Subject> hstretch(float stretch, Subject&& subject);

template <typename Subject>
vstretch_element<Subject> vstretch(float stretch, Subject&& subject);

template <typename Subject>
limit_element<Subject> limit(view_limits limits, Subject&& subject);

template <typename Subject>
scale_element<Subject> scale(float scale_, Subject&& subject);

Lifetime Management

For share(), the element must be allocated as if by std::make_shared; otherwise it will throw std::bad_weak_ptr.

template <typename Element>
std::shared_ptr<std::decay_t<Element>> share(Element&& e);

template <typename Element>
std::weak_ptr<Element> get(std::shared_ptr<Element> const& ptr);

Type Management

Transform a type into a different type which offers element type interface.

template <typename Element>
indirect<reference<std::remove_reference_t<Element>>> link(Element& rhs);

template <typename Element>
indirect<shared_element<Element>> hold(std::shared_ptr<Element> rhs);

indirect<shared_element<element>> hold_any(std::shared_ptr<element> rhs);

Behavior Management

Create an element which will intercept key events before the supplied subject handles them. Has public std::function<bool(key_info)> on_key member. If this handler returns true, the subject element will not receive the event.

template <typename Subject>
key_intercept_element<Subject> key_intercept(Subject&& subject);