TermOx
read_file.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_READ_FILE_HPP
2 #define TERMOX_WIDGET_WIDGETS_READ_FILE_HPP
3 #include <fstream>
4 #include <memory>
5 
6 #include <signals_light/signal.hpp>
7 
8 #include <termox/widget/pipe.hpp>
9 #include <termox/widget/tuple.hpp>
10 #include <termox/widget/widgets/button.hpp>
11 #include <termox/widget/widgets/line_edit.hpp>
12 #include <termox/widget/widgets/tile.hpp>
13 
14 namespace ox::detail {
15 
16 struct Read_file_widgets : HTuple<Button, Tile, Line_edit> {
17  Button& open_btn = this->get<0>();
18  Tile& buffer = this->get<1>();
19  Line_edit& filename_edit = this->get<2>();
20 
22 };
23 
24 } // namespace ox::detail
25 
26 namespace ox {
27 
29 template <typename Char_t = char>
31  public:
32  using Stream_t = std::basic_ifstream<Char_t>;
33 
34  public:
35  sl::Signal<void(Stream_t&)> request;
36 
37  public:
38  Read_file()
39  {
40  open_btn | pipe::on_press([this] { this->notify(); });
41  }
42 
43  private:
44  void notify()
45  {
46  auto ifs = Stream_t{filename_edit.text().str()};
47  request.emit(ifs);
48  }
49 };
50 
52 template <typename Char_t = char>
53 [[nodiscard]] auto read_file() -> std::unique_ptr<Read_file<Char_t>>
54 {
55  return std::make_unique<Read_file<Char_t>>();
56 }
57 
58 } // namespace ox
59 #endif // TERMOX_WIDGET_WIDGETS_READ_FILE_HPP
Button widget that emits Signal on a left mouse button press.
Definition: button.hpp:18
Definition: line_edit.hpp:16
Provides a filename Line_edit and button to emit a std::ifstream.
Definition: read_file.hpp:30
A unit width/height Widget that can display a single Glyph.
Definition: tile.hpp:12
Heterogeneous collection of Widgets within a Layout_t.
Definition: tuple.hpp:17
auto text() const noexcept -> ox::Glyph_string const &
Return the full text contents.
Definition: textline_base.cpp:35
Definition: read_file.hpp:16