FINAL CUT
flistbox.h
1 /***********************************************************************
2 * flistbox.h - Widget FListBox and FListBoxItem *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2014-2026 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTerm ▏ ▕ FObject ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲ ▲
30  * │ │
31  * └─────┬─────┘
32  * │
33  * ▕▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏
36  * ▲
37  * │
38  * ▕▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▏
39  * ▕ FListBox ▏- - - -▕ FListBoxItem ▏- - - -▕ FData ▏
40  * ▕▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏
41  *
42  */
43 
44 #ifndef FLISTBOX_H
45 #define FLISTBOX_H
46 
47 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
48  #error "Only <final/final.h> can be included directly."
49 #endif
50 
51 #include <memory>
52 #include <unordered_map>
53 #include <utility>
54 #include <vector>
55 
56 #include "final/fwidget.h"
57 #include "final/util/fdata.h"
58 #include "final/widget/fscrollbar.h"
59 
60 namespace finalcut
61 {
62 
63 // class forward declaration
64 class FScrollBar;
65 class FString;
66 
67 //----------------------------------------------------------------------
68 // class FListBoxItem
69 //----------------------------------------------------------------------
70 
72 {
73  public:
74  // Constructors
75  template <typename DT = std::nullptr_t>
76  explicit FListBoxItem (const FString& = FString{}, DT&& = DT() );
77 
78  // Accessors
79  auto getClassName() const -> FString;
80  auto getText() const -> FString;
81  template <typename DT>
82  auto getData() const -> clean_fdata_t<DT>&;
83 
84  // Mutators
85  void setText (const FString&);
86  template <typename DT>
87  void setData (DT&&);
88 
89  // Predicate
90  auto isSelected() const -> bool;
91 
92  // Methods
93  void clear();
94 
95  private:
96  // Using-declaration
97  using FDataAccessPtr = std::shared_ptr<FDataAccess>;
98 
99  // Methods
100  static auto stringFilter (const FString&) -> FString;
101 
102  // Data members
103  FString text{};
104  FDataAccessPtr data_pointer{};
105  BracketType brackets{BracketType::None};
106  bool selected{false};
107 
108  // Friend classes
109  friend class FListBox;
110 };
111 
112 
113 // FListBoxItem inline functions
114 //----------------------------------------------------------------------
115 template <typename DT>
116 inline FListBoxItem::FListBoxItem (const FString& txt, DT&& data)
117  : text{stringFilter(txt)}
118  , data_pointer{makeFData(std::forward<DT>(data))}
119 { }
120 
121 //----------------------------------------------------------------------
122 inline auto FListBoxItem::getClassName() const -> FString
123 { return "FListBoxItem"; }
124 
125 //----------------------------------------------------------------------
126 inline auto FListBoxItem::getText() const -> FString
127 { return text; }
128 
129 //----------------------------------------------------------------------
130 template <typename DT>
131 inline auto FListBoxItem::getData() const -> clean_fdata_t<DT>&
132 {
133  return static_cast<FData<clean_fdata_t<DT>>&>(*data_pointer).get();
134 }
135 
136 //----------------------------------------------------------------------
137 inline void FListBoxItem::setText (const FString& txt)
138 {
139  text.setString(stringFilter(txt));
140 }
141 
142 //----------------------------------------------------------------------
143 template <typename DT>
144 inline void FListBoxItem::setData (DT&& data)
145 {
146  auto data_obj = makeFData(std::forward<DT>(data));
147  data_pointer = std::move(data_obj);
148 }
149 
150 //----------------------------------------------------------------------
151 inline auto FListBoxItem::isSelected() const -> bool
152 { return selected; }
153 
154 //----------------------------------------------------------------------
155 inline void FListBoxItem::clear()
156 { text.clear(); }
157 
158 //----------------------------------------------------------------------
159 inline auto FListBoxItem::stringFilter (const FString& txt) -> FString
160 {
161  return txt.rtrim()
162  .expandTabs(FVTerm::getFOutput()->getTabstop())
163  .removeBackspaces()
164  .removeDel()
165  .replaceControlCodes();
166 }
167 
168 
169 //----------------------------------------------------------------------
170 // class FListBox
171 //----------------------------------------------------------------------
172 
173 class FListBox : public FWidget
174 {
175  public:
176  // Using-declaration
177  using FWidget::setGeometry;
178  using FListBoxItems = std::vector<FListBoxItem>;
179 
180  // Constructor
181  explicit FListBox (FWidget* = nullptr);
182  template <typename Iterator
183  , typename InsertConverter>
184  FListBox (Iterator, Iterator, InsertConverter, FWidget* = nullptr);
185  template <typename Container
186  , typename LazyConverter>
187  FListBox (Container, LazyConverter&&, FWidget* = nullptr);
188 
189  // Disable copy constructor
190  FListBox (const FListBox&) = delete;
191 
192  // Disable move constructor
193  FListBox (FListBox&&) noexcept = delete;
194 
195  // Destructor
196  ~FListBox() override;
197 
198  // Disable copy assignment operator (=)
199  auto operator = (const FListBox&) -> FListBox& = delete;
200 
201  // Disable move assignment operator (=)
202  auto operator = (FListBox&&) noexcept -> FListBox& = delete;
203 
204  // Accessors
205  auto getClassName() const -> FString override;
206  auto getCount() const -> std::size_t;
207  auto getItem (std::size_t) & -> FListBoxItem&;
208  auto getItem (std::size_t) const & -> const FListBoxItem&;
209  auto getItem (FListBoxItems::iterator) & -> FListBoxItem&;
210  auto getItem (FListBoxItems::const_iterator) const & -> const FListBoxItem&;
211  auto currentItem() const noexcept -> std::size_t;
212  auto getData() & -> FListBoxItems&;
213  auto getData() const & -> const FListBoxItems&;
214  auto getText() & -> FString&;
215 
216  // Mutators
217  void setCurrentItem (std::size_t);
218  void setCurrentItem (FListBoxItems::iterator);
219  void selectItem (std::size_t);
220  void selectItem (FListBoxItems::iterator) const;
221  void unselectItem (std::size_t);
222  void unselectItem (FListBoxItems::iterator) const;
223  void showInsideBrackets (const std::size_t, BracketType);
224  void showNoBrackets (std::size_t);
225  void showNoBrackets (FListBoxItems::iterator) const;
226  void setSize (const FSize&, bool = true) override;
227  void setGeometry (const FPoint&, const FSize&, bool = true) override;
228  void setMultiSelection (bool = true);
229  void unsetMultiSelection ();
230  void setDisable() override;
231  void setText (const FString&);
232 
233  // Predicates
234  auto isSelected (std::size_t) const -> bool;
235  auto isSelected (FListBoxItems::iterator) const -> bool;
236  auto isMultiSelection() const -> bool;
237  auto hasBrackets (std::size_t) const -> bool;
238  auto hasBrackets (FListBoxItems::iterator) const -> bool;
239 
240  // Methods
241  void hide() override;
242  template <typename Iterator
243  , typename InsertConverter>
244  void insert (Iterator, Iterator, const InsertConverter&);
245  template <typename Container
246  , typename LazyConverter>
247  void insert (const Container&, LazyConverter&&);
248  template <typename Container
249  , typename LazyConverter>
250  void insert (Container*, LazyConverter&&);
251  void insert (const FListBoxItem&);
252  template <typename T
253  , typename DT = std::nullptr_t>
254  void insert ( const std::initializer_list<T>& list
255  , BracketType = BracketType::None
256  , bool = false
257  , DT&& = DT() );
258  template <typename ItemT
259  , typename DT = std::nullptr_t>
260  void insert ( const ItemT&
261  , BracketType = BracketType::None
262  , bool = false
263  , DT&& = DT() );
264  void remove (std::size_t);
265  auto findItem (const FString&) -> FListBoxItems::iterator;
266  void reserve (std::size_t);
267  void clear();
268 
269  // Event handlers
270  void onKeyPress (FKeyEvent*) override;
271  void onMouseDown (FMouseEvent*) override;
272  void onMouseUp (FMouseEvent*) override;
273  void onMouseMove (FMouseEvent*) override;
274  void onMouseDoubleClick (FMouseEvent*) override;
275  void onWheel (FWheelEvent*) override;
276  void onTimer (FTimerEvent*) override;
277  void onFocusIn (FFocusEvent*) override;
278  void onFocusOut (FFocusEvent*) override;
279 
280  protected:
281  // Methods
282  void initLayout() override;
283  void adjustYOffset (std::size_t);
284  void adjustSize() override;
285 
286  private:
287  // Using-declaration
288  using KeyMap = std::unordered_map<FKey, std::function<void()>, EnumHash<FKey>>;
289  using KeyMapResult = std::unordered_map<FKey, std::function<bool()>, EnumHash<FKey>>;
290  using LazyInsert = std::function<void(FListBoxItem&, FDataAccess*, std::size_t)>;
291  using FWidgetColorsptr = std::shared_ptr<FWidgetColors>;
292 
293  struct ListBoxData
294  {
295  FListBoxItems itemlist{};
296  FDataAccess* source_container{nullptr};
297  FString text{};
298  FString inc_search{};
299  KeyMap key_map{};
300  KeyMapResult key_map_result{};
301  };
302 
303  struct SelectionState
304  {
305  std::size_t current{0};
306  int last_current{-1};
307  int select_from_item{-1};
308  bool multi_select{false};
309  bool mouse_select{false};
310  bool click_on_list{false};
311  };
312 
313  struct ScrollingState
314  {
315  FScrollBarPtr vbar{nullptr};
316  FScrollBarPtr hbar{nullptr};
317  int xoffset{0};
318  int yoffset{0};
319  int last_yoffset{-1};
320  int repeat{100};
321  int distance{1};
322  bool timer{false};
323  };
324 
325  struct ElementData
326  {
327  bool& search_mark;
328  std::size_t bracket_space{0};
329  std::size_t inc_len{0};
330  FString text{};
331  std::size_t text_width{0};
332  std::size_t column_width{0};
333  };
334 
335  // Enumeration
336  enum class ConvertType : uInt8
337  {
338  None = 0,
339  Direct = 1,
340  Lazy = 2
341  };
342 
343  // Accessors
344  static auto getString (FListBoxItems::iterator) -> FString;
345 
346  // Predicates
347  auto isHorizontallyScrollable() const -> bool;
348  auto isVerticallyScrollable() const -> bool;
349  auto isCurrentLine (int) const -> bool;
350  auto isDragSelect() const -> bool;
351  auto canSkipDragScrolling() -> bool;
352 
353  // Methods
354  void init();
355  void mapKeyFunctions();
356  void processKeyAction (FKeyEvent*);
357  void draw() override;
358  void drawBorder() override;
359  void drawScrollBars() const;
360  void drawHeadline();
361  auto canSkipDrawing() const -> bool;
362  auto calculateNumberItemsToDraw() const -> std::size_t;
363  auto canRedrawPartialList() const -> bool;
364  void updateRedrawParameters (std::size_t&, std::size_t&) const;
365  void finalizeDrawing();
366  void drawList();
367  void drawListLine (int, FListBoxItems::iterator, bool);
368  void printLeftBracket (BracketType);
369  template<class UnaryPred>
370  void printLeftBracket_if (BracketType, UnaryPred);
371  void printRightBracket (BracketType);
372  template<class UnaryPred>
373  void printRightBracket_if (BracketType, ElementData&, UnaryPred);
374  void setCurrentFocusedElementColor() const;
375  void drawListBracketsLine (int, FListBoxItems::iterator, bool);
376  void printElement (const ElementData&);
377  auto shouldPrintRightBracket (const ElementData&, std::size_t) const -> bool;
378  void printLeftCurrentLineArrow (int);
379  void printRightCurrentLineArrow (int);
380  void printRemainingSpacesFromPos (std::size_t);
381  void setInitialLineAttributes (bool) const;
382  void setCurrentLineAttributes (int, bool, bool, bool&);
383  void setSelectedCurrentLineAttributes (int);
384  void setUnselectedCurrentLineAttributes (int, bool, bool&);
385  void setLineAttributes (int, bool, bool, bool&);
386  auto getMaxWidth() const -> std::size_t;
387  void unsetAttributes() const;
388  void updateDrawing (bool, bool);
389  void recalculateHorizontalBar (std::size_t, bool);
390  void recalculateVerticalBar (std::size_t) const;
391  void multiSelection (std::size_t);
392  void multiSelectionUpTo (std::size_t);
393  void wheelUp (int);
394  void wheelDown (int);
395  void wheelLeft (int);
396  void wheelRight (int);
397  auto dragScrollUp() -> bool;
398  auto dragScrollDown() -> bool;
399  void dragUp (MouseButton);
400  void dragDown (MouseButton);
401  void stopDragScroll();
402  void prevListItem (int);
403  void nextListItem (int);
404  void scrollToX (int);
405  void scrollToY (int);
406  void scrollLeft (int);
407  void scrollRight (int);
408  void scrollLeft();
409  void scrollRight();
410  void onePosUp();
411  void onePosDown();
412  void onePageUp();
413  void onePageDown();
414  void firstPos();
415  void lastPos();
416  auto isWithinListBounds (const FPoint&) const -> bool;
417  auto skipIncrementalSearch() -> bool;
418  auto isNonSelectMouseButtonPressed (const FMouseEvent*) const -> bool;
419  template <typename MultiSelectionFunction>
420  void handleMouseWithinListBounds (const FMouseEvent*, const MultiSelectionFunction&);
421  void handleMouseDragging (const FMouseEvent*);
422  void acceptSelection();
423  auto spacebarProcessing() -> bool;
424  auto changeSelectionAndPosition() -> bool;
425  auto deletePreviousCharacter() -> bool;
426  auto keyIncSearchInput (FKey) -> bool;
427  void processClick() const;
428  void processSelect() const;
429  void processRowChanged() const;
430  void processChanged() const;
431  void changeOnResize() const;
432  void updateScrollBarAfterRemoval (std::size_t);
433  auto getScrollBarMaxHorizontal() const noexcept -> int;
434  auto getScrollBarMaxVertical() const noexcept -> int;
435  void recalculateMaximumLineWidth();
436  void lazyConvert (FListBoxItems::iterator, std::size_t);
437  auto index2iterator (std::size_t) -> FListBoxItems::iterator;
438  auto index2iterator (std::size_t index) const -> FListBoxItems::const_iterator;
439  void handleSelectionChange (const std::size_t);
440  void handleXOffsetChange (const int);
441  void handleVerticalScrollBarUpdate (const FScrollBar::ScrollType, const int) const;
442  void handleHorizontalScrollBarUpdate (const FScrollBar::ScrollType, const int) const;
443  auto getVerticalScrollDistance (const FScrollBar::ScrollType) const -> int;
444  auto getHorizontalScrollDistance (const FScrollBar::ScrollType) const -> int;
445 
446  // Callback methods
447  void cb_vbarChange (const FWidget*);
448  void cb_hbarChange (const FWidget*);
449 
450  // Function Pointer
451  LazyInsert lazy_inserter{};
452 
453  // Data members
454  std::size_t nf_offset{0};
455  std::size_t max_line_width{0};
456  ListBoxData data{};
457  ScrollingState scroll{};
458  SelectionState selection{};
459  ConvertType conv_type{ConvertType::None};
460  DragScrollMode drag_scroll{DragScrollMode::None};
461 };
462 
463 // non-member function
464 //----------------------------------------------------------------------
465 namespace flistboxhelper
466 {
467 
468 template <typename Container>
469 constexpr auto getContainer(FDataAccess* container) -> clean_fdata_t<Container>&
470 {
471  return static_cast<FData<clean_fdata_t<Container>>&>(*container).get();
472 }
473 
474 } // namespace flistboxhelper
475 
476 // FListBox inline functions
477 //----------------------------------------------------------------------
478 template <typename Iterator
479  , typename InsertConverter>
480 inline FListBox::FListBox ( Iterator first
481  , Iterator last
482  , InsertConverter convert
483  , FWidget* parent )
484  : FWidget{parent}
485 {
486  init();
487 
488  while ( first != last )
489  {
490  insert(convert(first), BracketType::None, false, &(*first));
491  ++first;
492  }
493 }
494 
495 //----------------------------------------------------------------------
496 template <typename Container
497  , typename LazyConverter>
498 inline FListBox::FListBox ( Container container
499  , LazyConverter&& convert
500  , FWidget* parent )
501  : FWidget{parent}
502 {
503  init();
504  insert (container, std::forward<LazyConverter>(convert));
505 }
506 
507 //----------------------------------------------------------------------
508 inline auto FListBox::getClassName() const -> FString
509 { return "FListBox"; }
510 
511 //----------------------------------------------------------------------
512 inline auto FListBox::getCount() const -> std::size_t
513 { return data.itemlist.size(); }
514 
515 //----------------------------------------------------------------------
516 inline auto FListBox::getItem (std::size_t index) & -> FListBoxItem&
517 {
518  auto iter = index2iterator(index - 1);
519  return *iter;
520 }
521 
522 //----------------------------------------------------------------------
523 inline auto FListBox::getItem (std::size_t index) const & -> const FListBoxItem&
524 {
525  auto iter = index2iterator(index - 1);
526  return *iter;
527 }
528 
529 //----------------------------------------------------------------------
530 inline auto FListBox::getItem (FListBoxItems::iterator iter) & -> FListBoxItem&
531 { return *iter; }
532 
533 //----------------------------------------------------------------------
534 inline auto FListBox::getItem (FListBoxItems::const_iterator iter) const & -> const FListBoxItem&
535 { return *iter; }
536 
537 //----------------------------------------------------------------------
538 inline auto FListBox::currentItem() const noexcept -> std::size_t
539 { return selection.current; }
540 
541 //----------------------------------------------------------------------
542 inline auto FListBox::getData() & -> FListBoxItems&
543 { return data.itemlist; }
544 
545 //----------------------------------------------------------------------
546 inline auto FListBox::getData() const & -> const FListBoxItems&
547 { return data.itemlist; }
548 
549 //----------------------------------------------------------------------
550 inline auto FListBox::getText() & -> FString&
551 { return data.text; }
552 
553 //----------------------------------------------------------------------
554 inline void FListBox::selectItem (std::size_t index)
555 { index2iterator(index - 1)->selected = true; }
556 
557 //----------------------------------------------------------------------
558 inline void FListBox::selectItem (FListBoxItems::iterator iter) const
559 { iter->selected = true; }
560 
561 //----------------------------------------------------------------------
562 inline void FListBox::unselectItem (std::size_t index)
563 { index2iterator(index - 1)->selected = false; }
564 
565 //----------------------------------------------------------------------
566 inline void FListBox::unselectItem (FListBoxItems::iterator iter) const
567 { iter->selected = false; }
568 
569 //----------------------------------------------------------------------
570 inline void FListBox::showNoBrackets (std::size_t index)
571 { index2iterator(index - 1)->brackets = BracketType::None; }
572 
573 //----------------------------------------------------------------------
574 inline void FListBox::showNoBrackets (FListBoxItems::iterator iter) const
575 { iter->brackets = BracketType::None; }
576 
577 //----------------------------------------------------------------------
578 inline void FListBox::setMultiSelection (bool enable)
579 { selection.multi_select = enable; }
580 
581 //----------------------------------------------------------------------
582 inline void FListBox::unsetMultiSelection()
583 { setMultiSelection(false); }
584 
585 //----------------------------------------------------------------------
586 inline void FListBox::setDisable()
587 { setEnable(false); }
588 
589 //----------------------------------------------------------------------
590 inline auto FListBox::isSelected (std::size_t index) const -> bool
591 { return index2iterator(index - 1)->selected; }
592 
593 //----------------------------------------------------------------------
594 inline auto FListBox::isSelected (FListBoxItems::iterator iter) const -> bool
595 { return iter->selected; }
596 
597 //----------------------------------------------------------------------
598 inline auto FListBox::isMultiSelection() const -> bool
599 { return selection.multi_select; }
600 
601 //----------------------------------------------------------------------
602 inline auto FListBox::hasBrackets(std::size_t index) const -> bool
603 { return index2iterator(index - 1)->brackets != BracketType::None; }
604 
605 //----------------------------------------------------------------------
606 inline auto FListBox::hasBrackets(FListBoxItems::iterator iter) const -> bool
607 { return iter->brackets != BracketType::None; }
608 
609 //----------------------------------------------------------------------
610 inline void FListBox::reserve (std::size_t new_cap)
611 { data.itemlist.reserve(new_cap); }
612 
613 //----------------------------------------------------------------------
614 template <typename Iterator
615  , typename InsertConverter>
616 inline void FListBox::insert ( Iterator first
617  , Iterator last
618  , const InsertConverter& convert )
619 {
620  conv_type = ConvertType::Direct;
621 
622  while ( first != last )
623  {
624  insert (convert(first), BracketType::None, false, &(*first));
625  ++first;
626  }
627 }
628 
629 //----------------------------------------------------------------------
630 template <typename Container
631  , typename LazyConverter>
632 void FListBox::insert (const Container& container, LazyConverter&& converter)
633 {
634  conv_type = ConvertType::Lazy;
635  data.source_container = makeFData(container).release();
636  lazy_inserter = std::forward<LazyConverter>(converter);
637  const std::size_t size = container.size();
638 
639  if ( size > 0 )
640  data.itemlist.resize(size);
641 
642  recalculateVerticalBar(size);
643 }
644 
645 //----------------------------------------------------------------------
646 template <typename Container
647  , typename LazyConverter>
648 void FListBox::insert (Container* container, LazyConverter&& converter)
649 {
650  insert (*container, std::forward<LazyConverter>(converter));
651 }
652 
653 //----------------------------------------------------------------------
654 template <typename T
655  , typename DT>
656 void FListBox::insert ( const std::initializer_list<T>& list
657  , BracketType b
658  , bool s
659  , DT&& d )
660 {
661  for (const auto& item : list)
662  {
663  FListBoxItem listItem (FString() << item, std::forward<DT>(d));
664  listItem.brackets = b;
665  listItem.selected = s;
666  insert (listItem);
667  }
668 }
669 
670 //----------------------------------------------------------------------
671 template <typename ItemT
672  , typename DT>
673 void FListBox::insert ( const ItemT& item
674  , BracketType b
675  , bool s
676  , DT&& d )
677 {
678  FListBoxItem listItem (FString() << item, std::forward<DT>(d));
679  listItem.brackets = b;
680  listItem.selected = s;
681  insert (listItem);
682 }
683 
684 //----------------------------------------------------------------------
685 inline auto FListBox::isHorizontallyScrollable() const -> bool
686 { return max_line_width + 1 >= getClientWidth(); }
687 
688 //----------------------------------------------------------------------
689 inline auto FListBox::isVerticallyScrollable() const -> bool
690 { return getCount() > getClientHeight(); }
691 
692 //----------------------------------------------------------------------
693 inline auto FListBox::isCurrentLine (int y) const -> bool
694 { return y + scroll.yoffset + 1 == int(selection.current); }
695 
696 //----------------------------------------------------------------------
697 template<class UnaryPred>
698 inline void FListBox::printLeftBracket_if ( BracketType bracket_type
699  , UnaryPred p )
700 {
701  if ( p )
702  printLeftBracket(bracket_type);
703 }
704 
705 //----------------------------------------------------------------------
706 template<class UnaryPred>
707 inline void FListBox::printRightBracket_if ( BracketType bracket_type
708  , ElementData& elem
709  , UnaryPred p )
710 {
711  if ( ! p )
712  return;
713 
714  if ( elem.search_mark && elem.text.getLength() == elem.inc_len )
715  setCurrentFocusedElementColor();
716 
717  printRightBracket (bracket_type);
718  elem.column_width++;
719 }
720 
721 //----------------------------------------------------------------------
722 inline auto FListBox::getMaxWidth() const -> std::size_t
723 { return getWidth() - nf_offset - 4; }
724 
725 //----------------------------------------------------------------------
726 inline auto \
727  FListBox::index2iterator (std::size_t index) -> FListBoxItems::iterator
728 {
729  auto iter = data.itemlist.begin();
730  using distance_type = FListBoxItems::difference_type;
731  std::advance (iter, distance_type(index));
732  return iter;
733 }
734 
735 //----------------------------------------------------------------------
736 inline auto \
737  FListBox::index2iterator (std::size_t index) const -> FListBoxItems::const_iterator
738 {
739  auto iter = data.itemlist.begin();
740  using distance_type = FListBoxItems::difference_type;
741  std::advance (iter, distance_type(index));
742  return iter;
743 }
744 
745 } // namespace finalcut
746 
747 #endif // FLISTBOX_H
Definition: fdata.h:128
Definition: fevent.h:207
Definition: fevent.h:144
Definition: flistbox.h:173
Definition: fevent.h:311
Definition: fevent.h:182
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fsize.h:55
Definition: flistbox.h:71
Definition: fstring.h:82
Definition: fdata.h:55
Definition: fwidget.h:129
Definition: fevent.h:124
Definition: ftypes.h:161