1 /**
2  * @file
3  * @brief Formatted scroller
4 **/
5 
6 #pragma once
7 
8 #include "menu.h"
9 #include "ui.h"
10 
11 enum FSFlag {
12     FS_START_AT_END = 0x01,
13     FS_PREWRAPPED_TEXT = 0x02,
14     FS_EASY_EXIT = 0x04,
15 };
16 
17 class formatted_scroller
18 {
19 public:
20     formatted_scroller(int flags, const string& text = "")
21         : m_lastch(0), m_flags(0x0), m_scroll(0)
22     {
23         m_flags = flags;
24         add_text(text);
25     };
26     formatted_scroller(const string& text = "") : formatted_scroller(0, text) {};
27 
28     virtual void add_formatted_string(const formatted_string& s, bool new_line = false);
29     virtual void add_text(const string& s, bool new_line = false);
30     virtual void add_raw_text(const string& s, bool new_line = false);
31 
32     virtual int show();
get_lastch()33     int get_lastch() { return m_lastch; }
34 
set_tag(const string & tag)35     void set_tag(const string& tag) { m_tag = tag; }
36 
set_more()37     void set_more() { m_more.clear(); }
set_more(formatted_string more)38     void set_more(formatted_string more) { m_more = move(more); }
39 
set_title()40     void set_title() { m_title.clear(); };
set_title(formatted_string title)41     void set_title(formatted_string title) { m_title = move(title); };
42 
43     void scroll_to_end();
44     void set_scroll(int y);
45 
get_contents()46     const formatted_string& get_contents() { return contents; };
47 
48     string highlight;
49 
50 protected:
51 
52     formatted_string contents;
53     string m_tag;
54     formatted_string m_title;
55     formatted_string m_more;
56     int m_lastch;
57     int m_flags;
58     int m_scroll;
59 
60     bool m_contents_dirty, m_scroll_dirty;
61 
62     virtual bool process_key(int keyin);
63     shared_ptr<ui::Scroller> m_scroller;
64 };
65 
66 void recv_formatted_scroller_scroll(int line);
67