Files
tdesktop/Telegram/lib_ui/ui/wrap/table_layout.h
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
init
2026-02-16 15:50:16 +03:00

102 lines
2.3 KiB
C++

// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
#include "base/object_ptr.h"
#include "ui/rp_widget.h"
namespace style {
struct Table;
} // namespace style
namespace st {
extern const style::Table &defaultTable;
} // namespace st
namespace Ui {
class TableLayout : public RpWidget {
public:
TableLayout(QWidget *parent, const style::Table &st = st::defaultTable);
~TableLayout();
[[nodiscard]] const style::Table &st() const {
return _st;
}
[[nodiscard]] int rowsCount() const {
return _rows.size();
}
[[nodiscard]] not_null<RpWidget*> labelAt(int index) const {
Expects(index >= 0 && index < rowsCount());
return _rows[index].label.data();
}
[[nodiscard]] not_null<RpWidget*> valueAt(int index) const {
Expects(index >= 0 && index < rowsCount());
return _rows[index].value.data();
}
void insertRow(
int atPosition,
object_ptr<RpWidget> &&label,
object_ptr<RpWidget> &&value,
const style::margins &labelMargin = style::margins(),
const style::margins &valueMargin = style::margins());
void addRow(
object_ptr<RpWidget> &&label,
object_ptr<RpWidget> &&value,
const style::margins &labelMargin = style::margins(),
const style::margins &valueMargin = style::margins()) {
insertRow(
rowsCount(),
std::move(label),
std::move(value),
labelMargin,
valueMargin);
}
void clear();
protected:
void paintEvent(QPaintEvent *e) override;
int resizeGetHeight(int newWidth) override;
void visibleTopBottomUpdated(
int visibleTop,
int visibleBottom) override;
private:
struct Row {
object_ptr<RpWidget> label;
object_ptr<RpWidget> value;
style::margins labelMargin;
style::margins valueMargin;
mutable int top = 0;
};
[[nodiscard]] int rowVerticalSkip(const Row &row) const;
void childHeightUpdated(RpWidget *child);
void removeChild(RpWidget *child);
void updateRowGeometry(const Row &row, int width, int top) const;
void updateRowPosition(const Row &row, int width, int top) const;
const style::Table &_st;
std::vector<Row> _rows;
int _valueLeft = 0;
bool _inResize = false;
rpl::lifetime _rowsLifetime;
};
} // namespace Ui