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