TermOx
include
termox
widget
widgets
write_file.hpp
1
#ifndef TERMOX_WIDGET_WIDGETS_WRITE_FILE_HPP
2
#define TERMOX_WIDGET_WIDGETS_WRITE_FILE_HPP
3
#include <fstream>
4
5
#include <signals_light/signal.hpp>
6
7
#include <termox/widget/pipe.hpp>
8
#include <termox/widget/tuple.hpp>
9
#include <termox/widget/widgets/button.hpp>
10
#include <termox/widget/widgets/line_edit.hpp>
11
#include <termox/widget/widgets/tile.hpp>
12
13
namespace
ox::detail {
14
15
struct
Write_file_widgets
:
HTuple
<Button, Tile, Line_edit> {
16
Button
& save_btn = this->get<0>();
17
Tile
& buffer = this->get<1>();
18
Line_edit
& filename_edit = this->get<2>();
19
20
Write_file_widgets
();
21
};
22
23
}
// namespace ox::detail
24
25
namespace
ox {
26
27
template
<
typename
Char_t =
char
>
28
class
Write_file
:
public
detail::Write_file_widgets
{
29
public
:
30
using
Stream_t = std::basic_ofstream<Char_t>;
31
32
public
:
33
sl::Signal<void(Stream_t&)> request;
34
35
public
:
36
Write_file
()
37
{
38
save_btn | pipe::on_press([
this
] { this->notify(); });
39
}
40
41
private
:
42
void
notify()
43
{
44
auto
ofs = Stream_t{filename_edit.
text
().str()};
45
request.emit(ofs);
46
}
47
};
48
50
template
<
typename
Char_t =
char
>
51
[[nodiscard]]
auto
write_file() -> std::unique_ptr<Write_file<Char_t>>
52
{
53
return
std::make_unique<Write_file<Char_t>>();
54
}
55
56
}
// namespace ox
57
#endif
// TERMOX_WIDGET_WIDGETS_WRITE_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::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::Write_file
Definition:
write_file.hpp:28
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::Write_file_widgets
Definition:
write_file.hpp:15
Generated by
1.9.1