2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-10-27 07:23:53 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-11-03 05:49:05 -03:00
|
|
|
#include <AK/String.h>
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
class TextPosition {
|
2019-10-27 07:23:53 -03:00
|
|
|
public:
|
2021-09-16 03:57:01 -03:00
|
|
|
TextPosition() = default;
|
2020-02-02 11:07:41 -03:00
|
|
|
TextPosition(size_t line, size_t column)
|
2019-10-27 07:23:53 -03:00
|
|
|
: m_line(line)
|
|
|
|
|
, m_column(column)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-09 13:45:40 -03:00
|
|
|
bool is_valid() const { return m_line != 0xffffffffu && m_column != 0xffffffffu; }
|
2019-10-27 07:23:53 -03:00
|
|
|
|
2019-12-09 13:45:40 -03:00
|
|
|
size_t line() const { return m_line; }
|
|
|
|
|
size_t column() const { return m_column; }
|
2019-10-27 07:23:53 -03:00
|
|
|
|
2019-12-09 13:45:40 -03:00
|
|
|
void set_line(size_t line) { m_line = line; }
|
|
|
|
|
void set_column(size_t column) { m_column = column; }
|
2019-10-27 07:23:53 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
bool operator==(const TextPosition& other) const { return m_line == other.m_line && m_column == other.m_column; }
|
|
|
|
|
bool operator!=(const TextPosition& other) const { return m_line != other.m_line || m_column != other.m_column; }
|
|
|
|
|
bool operator<(const TextPosition& other) const { return m_line < other.m_line || (m_line == other.m_line && m_column < other.m_column); }
|
2019-10-27 07:23:53 -03:00
|
|
|
|
|
|
|
|
private:
|
2019-12-09 13:45:40 -03:00
|
|
|
size_t m_line { 0xffffffff };
|
|
|
|
|
size_t m_column { 0xffffffff };
|
2019-10-27 07:23:53 -03:00
|
|
|
};
|
2019-11-03 05:49:05 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
}
|
2020-10-06 14:25:25 -03:00
|
|
|
|
|
|
|
|
template<>
|
2021-01-08 21:00:22 -03:00
|
|
|
struct AK::Formatter<GUI::TextPosition> : AK::Formatter<FormatString> {
|
2020-12-30 08:14:15 -03:00
|
|
|
void format(FormatBuilder& builder, const GUI::TextPosition& value)
|
2020-10-06 14:25:25 -03:00
|
|
|
{
|
|
|
|
|
if (value.is_valid())
|
2021-01-08 21:00:22 -03:00
|
|
|
Formatter<FormatString>::format(builder, "({},{})", value.line(), value.column());
|
2020-10-06 14:25:25 -03:00
|
|
|
else
|
2021-01-08 21:00:22 -03:00
|
|
|
Formatter<FormatString>::format(builder, "GUI::TextPosition(Invalid)");
|
2020-10-06 14:25:25 -03:00
|
|
|
}
|
|
|
|
|
};
|