Jazz2::UI::Windows::Dialog class

Window shown over the interface with a title, content and buttons.

The window is moved by dragging its title, the cross next to the title cancels it as Escape does. A window that is Resizable is resized by its edges and the corner with the dots.

Base classes

class Panel
A stack with a background.

Derived classes

class FileDialog
Picks a file to open or to save to.

Constructors, destructors, conversion operators

Dialog(StringView title, bool scrollContent = false) explicit
Creates a new instance.

Public functions

auto GetContent() const -> Stack*
Returns the area for the content.
auto AddButton(StringView text, Function<void()>&& onClick, bool accent = false) -> Button*
Adds a button.
void Close()
Closes the dialog.
void Cancel()
Cancels the dialog as Escape does, by OnCancel, by the last button, or closes it if it has none.
auto GetTitle() const -> StringView override
Returns the title of the element as a window, the system shows it on the taskbar while it's in a window of its own.
auto Measure(const Context& context, Vector2f available) -> Vector2f override
Returns the size the element wants, in pixels.
void Arrange(const Context& context, const Rectf& bounds) override
Places the element and its children.
void Draw(Painter& painter) override
Draws the element and its children.
void Update(float timeMult) override
Advances animations of the element and its children.
auto HitTest(Vector2f pos) -> Element* override
Returns the element under a position that takes the pointer, or nullptr.
auto GetHitBounds() const -> Rectf override
With the edges a window that is Resizable is grabbed by, which reach a little outside of it.
auto OnPointerDown(const PointerEvent& event) -> bool override
Called when the pointer is pressed over the element, returns true to keep getting it until released.
void OnPointerMove(const PointerEvent& event) override
Called when the pointer moves while pressed over the element.
void OnPointerUp(const PointerEvent& event, bool inside) override
Called when the pointer is released, inside tells whether it's still over the element.
auto OnKeyPressed(const KeyboardEvent& event) -> bool override
Called when a key is pressed while the element has the focus, returns true if it was used.

Public variables

Function<void()> OnCancel
Called instead of the last button when the dialog is cancelled by Escape or the cross.
float MaxScreenHeightFraction
Part of the height of the screen the dialog takes at most, 1 for all of it.
float MinScreenWidthFraction
Part of the width of the screen the dialog takes if its content is narrower, 0 for as wide as its content.
float MaxStretchedWidth
Width in units MinScreenWidthFraction makes the dialog at most, 0 for no limit, its content can still make it wider.
bool Resizable
Whether the window can be resized by its edges.
Vector2f MinResizeSize
Smallest size in units the window can be resized to.

Protected variables

DragBar* _titleBar
String _title
Button* _closeButton
Stack* _content
Stack* _buttons
SmallVector<Button*, 4> _buttonList
ScrollView* _contentScroll

Function documentation

Jazz2::UI::Windows::Dialog::Dialog(StringView title, bool scrollContent = false) explicit

Creates a new instance.

With scrollContent, a dialog taller than the screen is made as tall as the screen and its content scrolls, the title and the buttons stay. It's left to the dialog, as a list in the content that has no height of its own would be as tall as all of its rows then, and the whole content would scroll instead of the list.

Button* Jazz2::UI::Windows::Dialog::AddButton(StringView text, Function<void()>&& onClick, bool accent = false)

Adds a button.

Enter chooses the first accented button, or the first one if none is accented and OnCancel isn't set. Escape and the cross choose the last one, it should be the one that closes the dialog, unless OnCancel is set. A window closed only by its cross has no button that closes it — with no buttons at all, Escape and the cross close it, and the row of buttons isn't shown.

Vector2f Jazz2::UI::Windows::Dialog::Measure(const Context& context, Vector2f available) override

Returns the size the element wants, in pixels.

The available size is what the parent can give, a size without limit is a very large number.

Variable documentation

Function<void()> Jazz2::UI::Windows::Dialog::OnCancel

Called instead of the last button when the dialog is cancelled by Escape or the cross.

A window whose buttons do other things than closing it sets it, Enter then runs only an accented button.

float Jazz2::UI::Windows::Dialog::MaxScreenHeightFraction

Part of the height of the screen the dialog takes at most, 1 for all of it.

A list in the content that should use the room is given Element::Flex and no height of its own, it gets what's left then, and scrolls if it's longer.

float Jazz2::UI::Windows::Dialog::MinScreenWidthFraction

Part of the width of the screen the dialog takes if its content is narrower, 0 for as wide as its content.

A dialog is never narrower than its content, unless the screen is.

bool Jazz2::UI::Windows::Dialog::Resizable

Whether the window can be resized by its edges.

Its size is then its Width and Height, set by the resizing, the size it starts with if they're set before, and the content should fill it by Element::Flex.