NAME
UI::Various::Main - general main "Window Manager" class of UI::Various
SYNOPSIS
use UI::Various;
my $main = UI::Various::main();
$main->window(...);
$main->mainloop();
ABSTRACT
This module defines the general main "Window Manager" class of an application using UI::Various. It keeps track of active / inactive windows and / or the active dialogue. In addition it manages global attributes of the current UI, e.g. size of the display.
DESCRIPTION
UI::Various's "Window Manager" is a singleton keeping track of all windows and dialogues of the application. It takes care of setting them up for the currently used UI and removing them when they are no longer needed. In addition it triggers the event loops of the current UI (aka their main loops).
In addition it holds some convenience methods to ease creating windows and some specific dialogues (see METHODS below).
The "Window Manager" holds the following attributes (besides those inherited from UI::Various::widget
):
Attributes
- max_height [ro]
-
maximum height of an application window in (approximately) characters as defined by the underlying UI system and screen / terminal size
- max_width [ro]
-
maximum width of an application window in (approximately) characters as defined by the underlying UI system and screen / terminal size
modified attributes
The following attribute behave slightly different from their general description in widget. First of all (except for initialisation) they always ignore the passed object and use the internal singleton object instead. In addition they are no longer inherited but optional or mandatory, as the main "Window Manager" is the one object defining the defaults for all others that do not set them.
Note that all accessor methods can also be called via the package name itself, e.g. UI::Various::Main::max_width()
. As the "Window Manager" is a singleton, it always accesses the sole existing instance anyway.
METHODS
Besides the accessors (attributes) described above and by UI::Various::widget as well as the methods inherited from UI::Various::widget and UI::Various::container, the following additional methods are provided by the main "Window Manager" class itself:
new - constructor
see UI::Various::core::construct
window - add new window to application
$window = $main->window([$rh_attributes,] @ui_elements);
example:
$main->window(UI::Various::Text->new(text => 'Hello World!'),
UI::Various::Button->new(text => 'Quit',
code => sub{ exit(); }));
parameters:
$rh_attributes optional reference to hash with attributes
@ui_elements array with possible UI elements of a window
description:
Add a new window to the application. An optional attribute HASH is passed on to the created window while optional other UI elements are added in the specified sequence.
returns:
the new window or undef in case of an error
dialog - add new dialogue to application
$dialog = $main->dialog([$rh_attributes,] @ui_elements);
example:
$main->dialog(UI::Various::Text->new(text => 'Hello World!'),
UI::Various::Button->new(text => 'Quit',
code => sub{ exit(); }));
parameters:
$rh_attributes optional reference to hash with attributes
@ui_elements array with possible UI elements of a dialogue
description:
Add a new dialogue to the application. An optional attribute HASH is passed on to the created dialogue while optional other UI elements are added in the specified sequence.
Note that in Curses
the call blocks until the dialogue has finished! (It will therefore return undef
in those cases.) The same goes for PoorTerm
when the mainloop is already running.
returns:
the new dialogue or undef in case of an error (and always in Curses
or PoorTerm
with running mainloop
)
mainloop - main event loop of an application
$main->mainloop();
description:
The main event loop of the application, handling every Window
and Dialog
until none is left or the application exits.
SEE ALSO
LICENSE
Copyright (C) Thomas Dorner.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE file for more details.
AUTHOR
Thomas Dorner <dorner (at) cpan (dot) org>