1.10
scrollwheel.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_SCROLLWHEEL_H
7#define EGT_SCROLLWHEEL_H
8
15#include <egt/button.h>
16#include <egt/detail/meta.h>
17#include <egt/grid.h>
18#include <egt/label.h>
19#include <egt/signal.h>
20#include <string>
21#include <vector>
22
23namespace egt
24{
25inline namespace v1
26{
35class EGT_API Scrollwheel : public Widget
36{
37public:
38
48 using ItemArray = std::vector<std::string>;
49
53 explicit Scrollwheel(const ItemArray& items = {}) noexcept;
54
59 explicit Scrollwheel(const Rect& rect,
60 ItemArray items = {}) noexcept;
61
66 explicit Scrollwheel(Frame& parent,
67 const ItemArray& items = {}) noexcept;
68
74 explicit Scrollwheel(Frame& parent,
75 const Rect& rect,
76 const ItemArray& items = {}) noexcept;
77
81 explicit Scrollwheel(Serializer::Properties& props) noexcept
82 : Scrollwheel(props, false)
83 {
84 }
85
86protected:
87
88 explicit Scrollwheel(Serializer::Properties& props, bool is_derived) noexcept;
89
90public:
91
98 explicit Scrollwheel(const Rect& rect, int min, int max, int step) noexcept;
99
103 void image_down(const Image& image);
104
108 void image_up(const Image& image);
109
113 EGT_NODISCARD Orientation orient() const { return m_orient; }
114
118 void orient(Orientation orient);
119
123 EGT_NODISCARD std::string value() const;
124
128 void add_item(const std::string& item);
129
133 bool remove_item(const std::string& item);
134
139
143 EGT_NODISCARD size_t selected() const;
144
148 void selected(size_t index);
149
153 EGT_NODISCARD size_t item_count() const { return m_items.size(); }
154
159 void reversed(bool enabled);
160
164 EGT_NODISCARD bool reversed() const { return m_reversed; }
165
166 void serialize(Serializer& serializer) const override;
167
168protected:
170 void init(bool in_deserialize = false);
172 void update_orientation();
176 size_t m_selected{0};
186 bool m_reversed{false};
188 Orientation m_orient{Orientation::vertical};
189
190private:
191
192 void deserialize(Serializer::Properties& props);
193};
194
195}
196}
197
198#endif
A Frame is a Widget that has children widgets.
Definition frame.h:45
Raster image resource used for drawing or displaying.
Definition image.h:39
A Label that displays text.
Definition label.h:41
Scrollwheel widget.
Definition scrollwheel.h:36
EGT_NODISCARD std::string value() const
Returns a string of the item selected.
Scrollwheel(Frame &parent, const Rect &rect, const ItemArray &items={}) noexcept
void orient(Orientation orient)
Set the Orientation.
Scrollwheel(Frame &parent, const ItemArray &items={}) noexcept
ImageButton m_button_down
Down button.
Definition scrollwheel.h:182
std::vector< std::string > ItemArray
Item array type.
Definition scrollwheel.h:48
EGT_NODISCARD size_t item_count() const
Return the number of items.
Definition scrollwheel.h:153
StaticGrid m_grid
Layout grid.
Definition scrollwheel.h:178
ItemArray m_items
Array of items.
Definition scrollwheel.h:174
Label m_label
Label for the value.
Definition scrollwheel.h:184
bool remove_item(const std::string &item)
Remove an item from the array.
EGT_NODISCARD bool reversed() const
Get the boolean reversed state of the scrollwheel.
Definition scrollwheel.h:164
void clear_items()
Remove all the items.
void reversed(bool enabled)
Enable or disable the reversed mode.
EGT_NODISCARD Orientation orient() const
Get the Orientation.
Definition scrollwheel.h:113
void selected(size_t index)
Set the index to select a specific item.
Scrollwheel(const ItemArray &items={}) noexcept
void add_item(const std::string &item)
Add an item at the end of the array.
Scrollwheel(Serializer::Properties &props, bool is_derived) noexcept
void serialize(Serializer &serializer) const override
Serialize the widget to the specified serializer.
void image_up(const Image &image)
Change the up button image.
Signal on_value_changed
Event signal.
Definition scrollwheel.h:44
Scrollwheel(Serializer::Properties &props) noexcept
Definition scrollwheel.h:81
void image_down(const Image &image)
Change the down button image.
Scrollwheel(const Rect &rect, ItemArray items={}) noexcept
ImageButton m_button_up
Up button.
Definition scrollwheel.h:180
Scrollwheel(const Rect &rect, int min, int max, int step) noexcept
EGT_NODISCARD size_t selected() const
Get the index of the item selected.
Abstract base serializer class.
Definition serialize.h:34
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Signal class used for defining a signal and dispatching events.
Definition signal.h:30
Static grid organization for widgets.
Definition grid.h:43
Base Widget class.
Definition widget.h:53
Orientation
Generic orientation flags.
Definition widgetflags.h:652
EGT framework namespace.
Definition animation.h:24