HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
indent.hpp
1// Copyright Take Vos 2020, 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9#include <string>
10#include <cstddef>
11
12hi_export_module(hikogui.codec.indent);
13
14hi_export namespace hi { inline namespace v1 {
15
20hi_export class indent {
21public:
22 constexpr ~indent() noexcept = default;
23 constexpr indent() noexcept = default;
24 constexpr indent(indent const& other) noexcept = default;
25 constexpr indent(indent&& other) noexcept = default;
26 constexpr indent& operator=(indent const& other) noexcept = default;
27 constexpr indent& operator=(indent&& other) noexcept = default;
28
35 [[nodiscard]] constexpr indent(int spaces, char space = ' ') noexcept : _space(space), _spaces(spaces), _depth(0) {}
36
39 [[nodiscard]] operator std::string() const noexcept
40 {
41 return std::string(narrow_cast<std::size_t>(_depth) * narrow_cast<std::size_t>(_spaces), _space);
42 }
43
46 constexpr indent &operator+=(int rhs) noexcept
47 {
48 _depth += rhs;
49 return *this;
50 }
51
54 constexpr indent &operator++() noexcept
55 {
56 ++_depth;
57 return *this;
58 }
59
62 [[nodiscard]] constexpr friend indent operator+(indent lhs, int rhs) noexcept
63 {
64 lhs += rhs;
65 return lhs;
66 }
67
68private:
69 char _space = ' ';
70 int _spaces = 4;
71 int _depth = 0;
72};
73
74}} // namespace hi::inline v1
@ other
The gui_event does not have associated data.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Indentation for writing out text files.
Definition indent.hpp:20
constexpr indent & operator+=(int rhs) noexcept
Increase the depth of this indentation.
Definition indent.hpp:46
constexpr friend indent operator+(indent lhs, int rhs) noexcept
Get an indentation at increased depth.
Definition indent.hpp:62
constexpr indent(int spaces, char space=' ') noexcept
Constructor This constructor will start indentation at depth 0.
Definition indent.hpp:35
constexpr indent & operator++() noexcept
Increment the depth of this indentation.
Definition indent.hpp:54