Button class
#include <Jazz2/UI/Windows/Widgets.h>
Button with a text, an icon or both.
Base classes
- class Element
- Element of the interface.
Constructors, destructors, conversion operators
- Button(StringView text, IconId icon = StockIcon::None, Function<void()>&& onClick = {})
- Creates a new instance.
Public functions
- auto Measure(const Context& context, Vector2f available) -> Vector2f override
- Returns the size the element wants, in pixels.
- auto MeasureDependsOnAvailable() const -> bool override
- Returns
falseif what Measure() returns doesn't depend on the available size, it's measured once a frame then. - void Draw(Painter& painter) override
- Shows only the icon of a button with both that is narrower than them, centered, the text is its tooltip then.
- auto AcceptsPointer() const -> bool override
- Returns
trueif the element takes the pointer itself. - auto OnPointerDown(const PointerEvent& event) -> bool override
- Called when the pointer is pressed over the element, returns
trueto keep getting it until released. - void OnPointerUp(const PointerEvent& event, bool inside) override
- Called when the pointer is released,
insidetells whether it's still over the element. - auto YieldsToScroll() const -> bool override
- Returns
trueif a press on the element may become scrolling of the list it's in. - auto IsTabStop() const -> bool override
- Reached by
Tab,EnterorSpaceclicks it then. - auto OnKeyPressed(const KeyboardEvent& event) -> bool override
- Called when a key is pressed while the element has the focus, returns
trueif it was used. - auto GetTooltip(Vector2f pos) const -> StringView override
- Returns the tooltip at a position.
- auto IsChecked() -> bool
- Returns
trueif the button is shown checked. - auto IsTextCut() const -> bool
- Returns
trueif the icon and the text didn't fit into the button when it was drawn last.
Public variables
- String Text
- Text.
- IconId Icon
- Icon.
- ButtonStyle Style
- How the button is drawn.
- Function<void()> OnClick
- Called when the button is clicked.
- Function<bool()> IsCheckedFunc
- Returns whether the button is shown checked.
- Colorf IconColor
- Color of the icon.
- float MinWidth
- Smallest width in units.
- float IconGap
- Room added between the icon and the text, in units.
- Alignment TextAlign
- Where the text and the icon are in a button wider than them, centered, at the left or at the right.
- Colorf TextColor
- Color of the text instead of the usual one, a text color (see Theme::Text), unused if its alpha is 0.
- Function<bool()> IconOnlyFunc
- Returns whether only the icon is shown, instead of when the text doesn't fit (see IsTextCut()).
Function documentation
bool Jazz2:: UI:: Windows:: Button:: YieldsToScroll() const override
Returns true if a press on the element may become scrolling of the list it's in.
A finger dragged over a button scrolls the list then, the button isn't clicked. Elements that are dragged themselves keep the press.
Variable documentation
Function<bool()> Jazz2:: UI:: Windows:: Button:: IconOnlyFunc
Returns whether only the icon is shown, instead of when the text doesn't fit (see IsTextCut()).
So buttons next to each other show their texts or only their icons all alike.