TermOx
include
termox
widget
widgets
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
21
Read_file_widgets
();
22
};
23
24
}
// namespace ox::detail
25
26
namespace
ox {
27
29
template
<
typename
Char_t =
char
>
30
class
Read_file
:
public
detail::Read_file_widgets
{
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
ox::Button
Button widget that emits Signal on a left mouse button press.
Definition:
button.hpp:18
ox::Line_edit
Definition:
line_edit.hpp:16
ox::Read_file
Provides a filename Line_edit and button to emit a std::ifstream.
Definition:
read_file.hpp:30
ox::Tile
A unit width/height Widget that can display a single Glyph.
Definition:
tile.hpp:12
ox::Tuple
Heterogeneous collection of Widgets within a Layout_t.
Definition:
tuple.hpp:17
ox::detail::Textline_base::text
auto text() const noexcept -> ox::Glyph_string const &
Return the full text contents.
Definition:
textline_base.cpp:35
ox::detail::Read_file_widgets
Definition:
read_file.hpp:16
Generated by
1.9.1