Files
tdesktop/Telegram/lib_ui/ui/widgets/side_bar_button.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
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

139 lines
3.4 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 "ui/widgets/buttons.h"
#include "ui/text/text.h"
namespace style {
struct SideBarButton;
} // namespace style
namespace Ui {
class RippleAnimation;
[[nodiscard]] QImage SideBarLockIcon(const style::color &fg);
class SideBarButton final : public Ui::RippleButton {
public:
SideBarButton(
not_null<QWidget*> parent,
const TextWithEntities &title,
const style::SideBarButton &st,
Text::MarkedContext context = {},
Fn<bool()> paused = nullptr);
void setActive(bool active);
void setBadge(const QString &badge, bool muted);
void setIconOverride(
const style::icon *iconOverride,
const style::icon *iconOverrideActive = nullptr);
void setLocked(bool locked);
int resizeGetHeight(int newWidth) override;
[[nodiscard]] bool locked() const;
QString accessibilityName() override {
return !_badge.isEmpty()
? u"%1 (%2)"_q.arg(_text.toString(), _badge.toString())
: _text.toString();
}
private:
void paintEvent(QPaintEvent *e) override;
[[nodiscard]] const style::icon &computeIcon() const;
void validateIconCache();
void validateLockIconCache();
const style::SideBarButton &_st;
const style::icon *_iconOverride = nullptr;
const style::icon *_iconOverrideActive = nullptr;
Ui::Text::String _text;
Ui::Text::String _badge;
QImage _iconCache;
QImage _iconCacheActive;
int _iconCacheBadgeWidth = 0;
bool _active = false;
bool _badgeMuted = false;
Fn<bool()> _paused;
Text::MarkedContext _context;
struct {
bool locked = false;
QImage iconCache;
QImage iconCacheActive;
} _lock;
};
//
//class SideBarMenu final {
//public:
// struct Item {
// QString id;
// QString title;
// QString badge;
// not_null<const style::icon*> icon;
// not_null<const style::icon*> iconActive;
// int iconTop = 0;
// };
//
// SideBarMenu(not_null<QWidget*> parent, const style::SideBarMenu &st);
// ~SideBarMenu();
//
// [[nodiscard]] not_null<const Ui::RpWidget*> widget() const;
//
// void setGeometry(QRect geometry);
// void setItems(std::vector<Item> items);
// void setActive(
// const QString &id,
// anim::type animated = anim::type::normal);
// [[nodiscard]] rpl::producer<QString> activateRequests() const;
//
// [[nodiscard]] rpl::lifetime &lifetime();
//
//private:
// struct MenuItem {
// Item data;
// Ui::Text::String text;
// mutable std::unique_ptr<Ui::RippleAnimation> ripple;
// int top = 0;
// int height = 0;
// };
// void setup();
// void paint(Painter &p, QRect clip) const;
// [[nodiscard]] int countContentHeight(int width, int outerHeight);
//
// void mouseMove(QPoint position);
// void mousePress(Qt::MouseButton button);
// void mouseRelease(Qt::MouseButton button);
//
// void setSelected(int selected);
// void setPressed(int pressed);
// void addRipple(MenuItem &item, QPoint position);
// void repaint(const QString &id);
// [[nodiscard]] MenuItem *itemById(const QString &id);
//
// const style::SideBarMenu &_st;
//
// Ui::RpWidget _outer;
// const not_null<Ui::ScrollArea*> _scroll;
// const not_null<Ui::RpWidget*> _inner;
// std::vector<MenuItem> _items;
// int _selected = -1;
// int _pressed = -1;
//
// QString _activeId;
// rpl::event_stream<QString> _activateRequests;
//
//};
} // namespace Ui