DUDS
Distributed Update of Data from Something
MenuOutput.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 MENUOUTPUT_HPP
11 #define MENUOUTPUT_HPP
12 
13 #include <duds/ui/menu/Menu.hpp>
15 
16 namespace duds { namespace ui { namespace menu {
17 
19 
24 typedef std::list<MenuItem*> MenuVisibleList;
25 
45 class MenuOutput {
46 private:
50  std::shared_ptr<MenuView> mview;
58  MenuVisibleList items;
65  MenuVisibleList::const_iterator seliter;
73  std::size_t selectedVis;
77  std::size_t firstIdx;
81  std::size_t lastIdx;
85  std::size_t range = 1;
91  std::size_t selected = 0;
95  int updateIdx = -1;
100  bool vchg;
104  bool showFirst;
108  bool showLast;
123  void lock(std::size_t newRange);
128  void unlock();
137  void maxVisible(std::size_t newRange);
145  bool fore(Menu::ItemVec::const_iterator &iter);
153  bool revr(Menu::ItemVec::const_iterator &iter);
163  void updateVisible();
170  bool changed() const {
171  return vchg;
172  }
174 public:
179  MenuOutput() = default;
188  MenuOutput(const std::shared_ptr<MenuView> &view, int vis);
196  static std::shared_ptr<MenuOutput> make(
197  const std::shared_ptr<MenuView> &view,
198  int vis
199  ) {
200  return std::make_shared<MenuOutput>(view, vis);
201  }
211  void attach(const std::shared_ptr<MenuView> &view, int vis = 0);
215  const std::shared_ptr<MenuView> &view() const {
216  return mview;
217  }
225  const std::shared_ptr<Menu> &menu() const;
226 };
227 
231 typedef std::shared_ptr<MenuOutput> MenuOutputSptr;
232 
236 typedef std::weak_ptr<MenuOutput> MenuOutputWptr;
237 
238 } } }
239 
240 #endif // #ifndef MENUOUTPUT_HPP
bool showFirst
True if the visible list includes the first visible item on the menu.
Definition: MenuOutput.hpp:104
const std::shared_ptr< MenuView > & view() const
Returns the MenuView used by this output view.
Definition: MenuOutput.hpp:215
MenuOutput()=default
Constructs a menu output without a view.
int updateIdx
The menu&#39;s update index value when this subview was last rendered.
Definition: MenuOutput.hpp:95
bool revr(Menu::ItemVec::const_iterator &iter)
A helper function for update() that moves iter towards the back of the menu until it finds a visible ...
Definition: MenuOutput.cpp:85
std::size_t selected
Index of the selected item from the container of all menu items.
Definition: MenuOutput.hpp:91
void updateVisible()
Updates which items should be visible.
Definition: MenuOutput.cpp:98
bool changed() const
True if the view has changed.
Definition: MenuOutput.hpp:170
bool vchg
True when the view has changed since the last access, and false otherwise.
Definition: MenuOutput.hpp:100
std::shared_ptr< MenuView > mview
The menu view handling the selected menu item.
Definition: MenuOutput.hpp:50
std::list< MenuItem * > MenuVisibleList
Type used by MenuOutput and MenuOutputAccess for the list of visible menu items.
Definition: MenuOutput.hpp:18
MenuVisibleList::const_iterator seliter
Iterator to the currently selected item.
Definition: MenuOutput.hpp:65
std::size_t lastIdx
Index of the last menu item that is visible.
Definition: MenuOutput.hpp:81
MenuVisibleList items
The currently visible menu items.
Definition: MenuOutput.hpp:58
void unlock()
Informs the MenuView that it has one fewer MenuOutput objects acting upon it, and releases the shared...
Definition: MenuOutput.cpp:56
std::size_t firstIdx
Index of the first menu item that is visible.
Definition: MenuOutput.hpp:77
void maxVisible(std::size_t newRange)
Changes the maximum number of visible menu items and causes the visible list to be regenerated...
Definition: MenuOutput.cpp:61
void lock(std::size_t newRange)
Handles several tasks to lock and prepare menu data.
Definition: MenuOutput.cpp:39
bool fore(Menu::ItemVec::const_iterator &iter)
A helper function for update() that moves iter towards the front of the menu until it finds a visible...
Definition: MenuOutput.cpp:72
std::size_t selectedVis
Index of the selected item within the list of currently visible menu items.
Definition: MenuOutput.hpp:73
std::weak_ptr< MenuOutput > MenuOutputWptr
A weak pointer to a MenuOutput.
Definition: MenuOutput.hpp:236
Compiles a list of visible menu items based on the selected item of a MenuView.
Definition: MenuOutput.hpp:45
void attach(const std::shared_ptr< MenuView > &view, int vis=0)
Attaches this object to the given MenuView.
Definition: MenuOutput.cpp:20
bool showLast
True if the visible list includes the last visible item on the menu.
Definition: MenuOutput.hpp:108
static std::shared_ptr< MenuOutput > make(const std::shared_ptr< MenuView > &view, int vis)
Makes a new output view for a given menu that will start with a specified maximum number of visible i...
Definition: MenuOutput.hpp:196
std::size_t range
The maximum number of visible items.
Definition: MenuOutput.hpp:85
const std::shared_ptr< Menu > & menu() const
Returns the Menu used by this output view.
Definition: MenuOutput.cpp:32
Provides access to a MenuOutput for rendering.
std::shared_ptr< MenuOutput > MenuOutputSptr
A shared pointer to a MenuOutput.
Definition: MenuOutput.hpp:231