DUDS
Distributed Update of Data from Something
MenuView.hpp
Go to the documentation of this file.
1
/*
2
* This file is part of the DUDS project. It is subject to the BSD-style
3
* license terms in the LICENSE file found in the top-level directory of this
4
* distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5
* No part of DUDS, including this file, may be copied, modified, propagated,
6
* or distributed except according to the terms contained in the LICENSE file.
7
*
8
* Copyright (C) 2019 Jeff Jackowski
9
*/
10
#ifndef MENUVIEW_HPP
11
#define MENUVIEW_HPP
12
13
#include <
duds/general/Spinlock.hpp
>
14
#include <
duds/ui/Page.hpp
>
15
#include <boost/any.hpp>
16
#include <list>
17
18
namespace
duds
{
namespace
ui {
namespace
menu {
19
20
class
Menu;
21
class
MenuItem;
22
class
MenuOutput;
23
class
MenuOutputAccess;
24
46
class
MenuView
:
public
Page
{
47
private
:
51
boost::any
ctx
;
55
std::shared_ptr<Menu>
parent
;
60
duds::general::Spinlock
block
;
64
int
currSel
;
68
int
nextSel
;
72
int
outvUsers
;
76
int
nextSelOff
;
80
int
updateIdx
;
84
bool
choseItem
;
89
void
incUser
();
94
void
decUser
();
104
int
adv
(
int
pos);
113
int
retr
(
int
pos);
123
void
insertion
(std::size_t idx);
132
void
removal
(std::size_t idx);
133
friend
Menu
;
134
friend
MenuOutput
;
135
public
:
144
MenuView
();
154
void
attach
(
const
std::shared_ptr<Menu> &
menu
);
160
static
std::shared_ptr<MenuView>
make
(
const
std::shared_ptr<Menu> &
menu
) {
161
std::shared_ptr<MenuView> mv = std::make_shared<MenuView>();
162
mv->attach(menu);
163
return
mv;
164
}
168
const
std::shared_ptr<Menu> &
menu
()
const
{
169
return
parent
;
170
}
180
int
selectedIndex
()
const
{
181
return
currSel
;
182
}
228
void
backward
(
int
dist = 1);
273
void
forward
(
int
dist = 1) {
274
backward
(-dist);
275
}
300
void
jump
(
int
pos);
306
void
jumpToFirst
() {
307
jump
(std::numeric_limits<int>::min());
308
}
314
void
jumpToLast
() {
315
jump
(-1);
316
}
332
void
chose
();
342
bool
queuedInput
();
365
bool
update
();
369
const
boost::any &
context
()
const
{
370
return
ctx
;
371
}
375
boost::any &
context
() {
376
return
ctx
;
377
}
382
std::shared_ptr<MenuView>
shared_from_this
() {
383
return
std::static_pointer_cast<
MenuView
>(Page::shared_from_this());
384
}
385
};
386
390
typedef
std::shared_ptr<MenuView>
MenuViewSptr
;
391
395
typedef
std::weak_ptr<MenuView>
MenuViewWptr
;
396
397
} } }
398
399
#endif // #ifndef MENUVIEW_HPP
duds::ui::menu::MenuViewSptr
std::shared_ptr< MenuView > MenuViewSptr
A shared pointer to a MenuView.
Definition:
MenuView.hpp:390
duds::ui::menu::MenuView::decUser
void decUser()
Decrements the internal count of subviews currently accessing this menu view.
Definition:
MenuView.cpp:286
duds::ui::Page
Represents the notion of a page that may be visited, and helps allow a way to track the path of pages...
Definition:
Page.hpp:24
duds::ui::menu::MenuView::incUser
void incUser()
Increments the internal count of subviews currently accessing this menu view.
Definition:
MenuView.cpp:281
duds::ui::menu::MenuView::MenuOutput
friend MenuOutput
Definition:
MenuView.hpp:134
duds::ui::menu::MenuView::ctx
boost::any ctx
Arbitrary context data that is available to MenuItem::chose().
Definition:
MenuView.hpp:51
duds::ui::menu::MenuView::MenuView
MenuView()
Constructs a new MenuView without attaching it to a Menu.
Definition:
MenuView.cpp:17
duds::ui::menu::MenuView::chose
void chose()
Queues a request to chose what will be the currently selected menu item during input processing when ...
Definition:
MenuView.cpp:310
Page.hpp
duds::ui::menu::MenuView::updateIdx
int updateIdx
The menu's update index value when this subview was last rendered.
Definition:
MenuView.hpp:80
duds::ui::menu::MenuView::selectedIndex
int selectedIndex() const
Returns the index of the currently selected item.
Definition:
MenuView.hpp:180
duds::ui::menu::MenuView::attach
void attach(const std::shared_ptr< Menu > &menu)
Attaches the view to a menu so that the view can operate on the menu's data, and the menu can inform ...
Definition:
MenuView.cpp:21
duds::ui::menu::MenuView::insertion
void insertion(std::size_t idx)
Responds to the menu inserting a menu item to a spot other than the end of the menu.
Definition:
MenuView.cpp:243
duds::ui::menu::MenuView::removal
void removal(std::size_t idx)
Responds to the menu removing a menu item.
Definition:
MenuView.cpp:262
duds::ui::menu::MenuView::currSel
int currSel
The index of the currently selected menu item.
Definition:
MenuView.hpp:64
duds::ui::menu::MenuView::adv
int adv(int pos)
Find the first menu item that is selectable, starting at and including pos, and advancing toward the ...
Definition:
MenuView.cpp:32
duds::ui::menu::MenuView::jumpToFirst
void jumpToFirst()
Jumps to the first option in the menu.
Definition:
MenuView.hpp:306
duds
Definition:
Constants.hpp:15
duds::ui::menu::MenuView::context
const boost::any & context() const
Returns the arbitrary context object for this view.
Definition:
MenuView.hpp:369
duds::ui::menu::MenuView::menu
const std::shared_ptr< Menu > & menu() const
Returns the Menu used by this view.
Definition:
MenuView.hpp:168
duds::ui::menu::MenuView::retr
int retr(int pos)
Find the first menu item that is selectable, starting at and including pos, and advancing toward the ...
Definition:
MenuView.cpp:57
duds::ui::menu::MenuView::parent
std::shared_ptr< Menu > parent
The parent menu that supplies the MenuItems.
Definition:
MenuView.hpp:55
duds::ui::menu::MenuView::jumpToLast
void jumpToLast()
Jumps to the last option in the menu.
Definition:
MenuView.hpp:314
duds::ui::menu::MenuView::update
bool update()
Updates the view's selected and chosen menu item if there are no MenuOutput objects currently renderi...
Definition:
MenuView.cpp:87
duds::ui::menu::MenuView::nextSel
int nextSel
The index of the next menu item to select.
Definition:
MenuView.hpp:68
duds::ui::menu::MenuViewWptr
std::weak_ptr< MenuView > MenuViewWptr
A weak pointer to a MenuView.
Definition:
MenuView.hpp:395
duds::general::Spinlock
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
Definition:
Spinlock.hpp:52
duds::ui::menu::MenuView::nextSelOff
int nextSelOff
Offset from the next selection.
Definition:
MenuView.hpp:76
duds::ui::menu::MenuView
Keeps track of the selected menu item, and updates it based on user input.
Definition:
MenuView.hpp:46
duds::ui::menu::MenuView::Menu
friend Menu
Definition:
MenuView.hpp:133
duds::ui::menu::MenuView::block
duds::general::Spinlock block
Protects this object's data from inappropriate modification when used in a multithreaded manner...
Definition:
MenuView.hpp:60
duds::ui::menu::MenuView::make
static std::shared_ptr< MenuView > make(const std::shared_ptr< Menu > &menu)
Constructs a new MenuView, attaches it to a Menu, and returns the std::shared_ptr that manages the vi...
Definition:
MenuView.hpp:160
duds::ui::menu::MenuView::choseItem
bool choseItem
Flag used to queue an input request to chose the selected item.
Definition:
MenuView.hpp:84
duds::ui::menu::MenuView::outvUsers
int outvUsers
The number of MenuOutput objects currently using this MenuView.
Definition:
MenuView.hpp:72
duds::ui::menu::MenuView::forward
void forward(int dist=1)
Changes the selection toward the front (first item) of the menu.
Definition:
MenuView.hpp:273
duds::ui::menu::MenuView::backward
void backward(int dist=1)
Changes the selection toward the back (last item) of the menu.
Definition:
MenuView.cpp:291
duds::ui::menu::MenuView::context
boost::any & context()
Returns the arbitrary context object for this view.
Definition:
MenuView.hpp:375
duds::ui::menu::MenuView::shared_from_this
std::shared_ptr< MenuView > shared_from_this()
Helper function that returns a shared pointer to this object from the base class Page.
Definition:
MenuView.hpp:382
duds::ui::menu::MenuView::queuedInput
bool queuedInput()
Returns true if any input for the menu view has been queued and is awaiting processing.
Definition:
MenuView.cpp:315
Spinlock.hpp
duds::ui::menu::MenuView::jump
void jump(int pos)
Jump to a particular option by position index.
Definition:
MenuView.cpp:299
duds
ui
menu
MenuView.hpp
Generated on Sat Mar 23 2024 19:12:03 for DUDS by
1.8.13