1.10
form.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_FORM_H
7#define EGT_FORM_H
8
14#include <egt/detail/meta.h>
15#include <egt/frame.h>
16#include <egt/sizer.h>
17#include <memory>
18#include <string>
19#include <vector>
20
21namespace egt
22{
23inline namespace v1
24{
25
26namespace experimental
27{
28
32class EGT_API Form : public Frame
33{
34public:
35
39 explicit Form(const std::string& title = {}) noexcept;
40
45 explicit Form(Frame& parent, const std::string& title = {}) noexcept;
46
50 explicit Form(Serializer::Properties& props) noexcept
51 : Form(props, false)
52 {
53 }
54
55protected:
56
57 explicit Form(Serializer::Properties& props, bool is_derived) noexcept;
58
59public:
60
64 void add_group(const std::string& caption);
65
69 template<class T>
70 void add_option(const std::string& name, const std::shared_ptr<T>& widget)
71 {
72 auto p = std::dynamic_pointer_cast<Widget>(widget);
73 add_option(name, p);
74 }
75
79 void add_option(const std::string& name, const std::shared_ptr<Widget>& widget);
80
84 template<class T>
85 void add_option(const std::shared_ptr<T>& widget)
86 {
87 auto p = std::dynamic_pointer_cast<Widget>(widget);
88 add_option(p);
89 }
90
94 void add_option(const std::shared_ptr<Widget>& widget);
95
100
104 void name_align(const AlignFlags& align)
105 {
106 if (detail::change_if_diff<>(m_name_align, align))
107 parent_layout();
108 }
109
113 void group_align(const AlignFlags& align)
114 {
115 if (detail::change_if_diff<>(m_group_align, align))
116 parent_layout();
117 }
118
119protected:
120
124 EGT_NODISCARD virtual DefaultDim min_option_height() const
125 {
126 return 50;
127 }
128
131
137 std::vector<Widget*> m_options;
138
140 AlignFlags m_name_align{AlignFlag::center_vertical | AlignFlag::left};
141
143 AlignFlags m_group_align{AlignFlag::bottom | AlignFlag::left};
144};
145
146}
147}
148}
149
150#endif
Alignment flags.
Definition widgetflags.h:379
Positions and sizes widgets by Orientation.
Definition sizer.h:49
A Frame is a Widget that has children widgets.
Definition frame.h:45
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Utility class to help with standard Form layout of widgets.
Definition form.h:33
BoxSizer m_vsizer
Internal BoxSizer used for layout.
Definition form.h:130
std::vector< Widget * > m_options
Array of options.
Definition form.h:137
void add_group(const std::string &caption)
Add a group to the Form.
void add_option(const std::string &name, const std::shared_ptr< Widget > &widget)
Add an option to the form with a name.
Form(Serializer::Properties &props, bool is_derived) noexcept
void remove_options()
Remove all options from the Form.
void group_align(const AlignFlags &align)
Set group name text alignment.
Definition form.h:113
Form(Serializer::Properties &props) noexcept
Definition form.h:50
Form(const std::string &title={}) noexcept
Form(Frame &parent, const std::string &title={}) noexcept
void add_option(const std::shared_ptr< T > &widget)
Add an option to the Form without a name.
Definition form.h:85
void add_option(const std::string &name, const std::shared_ptr< T > &widget)
Add an option to the form with a name.
Definition form.h:70
void add_option(const std::shared_ptr< Widget > &widget)
Add an option to the Form without a name.
void name_align(const AlignFlags &align)
Set default option name text alignment.
Definition form.h:104
virtual EGT_NODISCARD DefaultDim min_option_height() const
Minimum option height.
Definition form.h:124
T & align(T &widget, const AlignFlags &a)
Helper to set alignment of a widget.
Definition widgetflags.h:624
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24