Support emoji in Ui::SettingsButton.
This commit is contained in:
parent
1ba9270234
commit
8415f7058c
3 changed files with 17 additions and 33 deletions
|
|
@ -703,6 +703,7 @@ SettingsButton::~SettingsButton() = default;
|
||||||
|
|
||||||
SettingsButton *SettingsButton::toggleOn(rpl::producer<bool> &&toggled) {
|
SettingsButton *SettingsButton::toggleOn(rpl::producer<bool> &&toggled) {
|
||||||
Expects(_toggle == nullptr);
|
Expects(_toggle == nullptr);
|
||||||
|
|
||||||
_toggle = std::make_unique<Ui::ToggleView>(
|
_toggle = std::make_unique<Ui::ToggleView>(
|
||||||
isOver() ? _st.toggleOver : _st.toggle,
|
isOver() ? _st.toggleOver : _st.toggle,
|
||||||
false,
|
false,
|
||||||
|
|
@ -773,18 +774,24 @@ void SettingsButton::paintBg(Painter &p, const QRect &rect, bool over) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsButton::paintText(Painter &p, bool over, int outerw) const {
|
void SettingsButton::paintText(Painter &p, bool over, int outerw) const {
|
||||||
p.setFont(_st.font);
|
auto available = outerw - _padding.left() - _padding.right();
|
||||||
|
if (_toggle) {
|
||||||
|
available -= (width() - toggleRect().x());
|
||||||
|
}
|
||||||
|
if (available <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
p.setPen(_textColorOverride
|
p.setPen(_textColorOverride
|
||||||
? QPen(*_textColorOverride)
|
? QPen(*_textColorOverride)
|
||||||
: over
|
: over
|
||||||
? _st.textFgOver
|
? _st.textFgOver
|
||||||
: _st.textFg);
|
: _st.textFg);
|
||||||
p.drawTextLeft(
|
_text.drawLeftElided(
|
||||||
|
p,
|
||||||
_padding.left(),
|
_padding.left(),
|
||||||
_padding.top(),
|
_padding.top(),
|
||||||
outerw,
|
available,
|
||||||
_text,
|
outerw);
|
||||||
_textWidth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsButton::paintToggle(Painter &p, int outerw) const {
|
void SettingsButton::paintToggle(Painter &p, int outerw) const {
|
||||||
|
|
@ -804,7 +811,6 @@ QRect SettingsButton::toggleRect() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int SettingsButton::resizeGetHeight(int newWidth) {
|
int SettingsButton::resizeGetHeight(int newWidth) {
|
||||||
updateVisibleText(newWidth);
|
|
||||||
return _padding.top() + _st.height + _padding.bottom();
|
return _padding.top() + _st.height + _padding.bottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -821,26 +827,7 @@ void SettingsButton::onStateChanged(
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsButton::setText(QString &&text) {
|
void SettingsButton::setText(QString &&text) {
|
||||||
_original = std::move(text);
|
_text.setText(_st.style, text);
|
||||||
_originalWidth = _st.font->width(_original);
|
|
||||||
updateVisibleText(width());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsButton::updateVisibleText(int newWidth) {
|
|
||||||
auto availableWidth = newWidth
|
|
||||||
- _padding.left()
|
|
||||||
- _padding.right();
|
|
||||||
if (_toggle) {
|
|
||||||
availableWidth -= (width() - toggleRect().x());
|
|
||||||
}
|
|
||||||
accumulate_max(availableWidth, 0);
|
|
||||||
if (availableWidth < _originalWidth) {
|
|
||||||
_text = _st.font->elided(_original, availableWidth);
|
|
||||||
_textWidth = _st.font->width(_text);
|
|
||||||
} else {
|
|
||||||
_text = _original;
|
|
||||||
_textWidth = _originalWidth;
|
|
||||||
}
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "ui/abstract_button.h"
|
#include "ui/abstract_button.h"
|
||||||
#include "ui/round_rect.h"
|
#include "ui/round_rect.h"
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
|
#include "ui/text/text.h"
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -285,14 +286,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
void setText(QString &&text);
|
void setText(QString &&text);
|
||||||
QRect toggleRect() const;
|
QRect toggleRect() const;
|
||||||
void updateVisibleText(int newWidth);
|
|
||||||
|
|
||||||
const style::SettingsButton &_st;
|
const style::SettingsButton &_st;
|
||||||
style::margins _padding;
|
style::margins _padding;
|
||||||
QString _original;
|
Ui::Text::String _text;
|
||||||
QString _text;
|
|
||||||
int _originalWidth = 0;
|
|
||||||
int _textWidth = 0;
|
|
||||||
std::unique_ptr<Ui::ToggleView> _toggle;
|
std::unique_ptr<Ui::ToggleView> _toggle;
|
||||||
std::optional<QColor> _textColorOverride;
|
std::optional<QColor> _textColorOverride;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -520,7 +520,7 @@ SettingsButton {
|
||||||
textBg: color;
|
textBg: color;
|
||||||
textBgOver: color;
|
textBgOver: color;
|
||||||
|
|
||||||
font: font;
|
style: TextStyle;
|
||||||
rightLabel: FlatLabel;
|
rightLabel: FlatLabel;
|
||||||
|
|
||||||
height: pixels;
|
height: pixels;
|
||||||
|
|
@ -1393,7 +1393,7 @@ defaultSettingsButton: SettingsButton {
|
||||||
textBg: windowBg;
|
textBg: windowBg;
|
||||||
textBgOver: windowBgOver;
|
textBgOver: windowBgOver;
|
||||||
|
|
||||||
font: boxTextFont;
|
style: boxTextStyle;
|
||||||
rightLabel: defaultSettingsRightLabel;
|
rightLabel: defaultSettingsRightLabel;
|
||||||
|
|
||||||
height: 20px;
|
height: 20px;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue