mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 13:21:34 +00:00
Fix UI vs Screen Scaling bugs w/window buttons and button sets/grids (fix #5043)
Includes: * New ui::Style::rawMargin/Border/Padding() to detect what values are undefined, and ui::Style::margin/border/padding() to return normalized values (replacing kUndefinedSide with 0 when a value is not defined in the whole hierarchy of styles). With this change we avoid using a margin/border/padding value of -1 by mistake. * New guiscaled_div() to calculate an integer division taking care the guiscale() for a scaled value. * CALC_FOR_CENTER() renamed to guiscaled_center() and moved to ui/scale.h There are still a lot of work to be done to fully fix these UI issues between Screen Scaling=200%/UI Scaling=100% vs Screen Scaling=100%/UI Scaling=200%
This commit is contained in:
parent
c949f4a5a6
commit
d3265a1711
@ -485,25 +485,25 @@
|
||||
<icon part="window_close_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_close_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_center_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_center_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_center_icon" color="button_normal_text" />
|
||||
<icon part="window_center_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_center_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_play_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_play_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_play_icon" color="button_normal_text" />
|
||||
<icon part="window_play_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_play_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_stop_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_stop_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_stop_icon" color="button_normal_text" />
|
||||
<icon part="window_stop_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_stop_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_help_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_help_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_help_icon" color="button_normal_text" />
|
||||
<icon part="window_help_icon" color="button_hot_text" state="mouse" />
|
||||
|
@ -481,25 +481,25 @@
|
||||
<icon part="window_close_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_close_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_center_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_center_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_center_icon" color="button_normal_text" />
|
||||
<icon part="window_center_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_center_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_play_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_play_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_play_icon" color="button_normal_text" />
|
||||
<icon part="window_play_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_play_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_stop_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_stop_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_stop_icon" color="button_normal_text" />
|
||||
<icon part="window_stop_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_stop_icon" color="button_selected_text" state="selected" />
|
||||
</style>
|
||||
<style id="window_help_button" extends="window_button" margin-top="3" margin-right="2">
|
||||
<style id="window_help_button" extends="window_button" margin-top="3" margin-right="1">
|
||||
<newlayer />
|
||||
<icon part="window_help_icon" color="button_normal_text" />
|
||||
<icon part="window_help_icon" color="button_hot_text" state="mouse" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2024 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -22,6 +22,7 @@
|
||||
#include "ui/accelerator.h"
|
||||
#include "ui/menu.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
@ -134,9 +135,9 @@ void AppMenuItem::onSizeHint(SizeHintEvent& ev)
|
||||
gfx::Size size(0, 0);
|
||||
|
||||
if (hasText()) {
|
||||
size.w = +textWidth() + (inBar() ? childSpacing() / 4 : childSpacing()) + border().width();
|
||||
|
||||
size.h = +textHeight() + border().height();
|
||||
size.w = textWidth() + (inBar() ? guiscaled_div(childSpacing(), 4) : childSpacing()) +
|
||||
border().width();
|
||||
size.h = textHeight() + border().height();
|
||||
|
||||
if (m_key && !m_key->accels().empty()) {
|
||||
size.w += font()->textLength(m_key->accels().front().toString());
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||
// Copyright (C) 2020-2025 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -131,11 +131,12 @@ private:
|
||||
theme->parts.miniSliderFull().get());
|
||||
}
|
||||
|
||||
const int sensorH = guiscaled_div(rc.h, 4);
|
||||
g->fillRect(theme->colors.sliderEmptyText(),
|
||||
gfx::Rect(rc.x, rc.y + rc.h / 2 - rc.h / 8, sensorW, rc.h / 4));
|
||||
gfx::Rect(rc.x, guiscaled_center(rc.y, rc.h, sensorH), sensorW, sensorH));
|
||||
|
||||
g->drawRgbaSurface(thumb, minX - thumb->width() / 2, thumb_y);
|
||||
g->drawRgbaSurface(thumb, maxX - thumb->width() / 2, thumb_y);
|
||||
g->drawRgbaSurface(thumb, minX - guiscaled_div(thumb->width(), 2), thumb_y);
|
||||
g->drawRgbaSurface(thumb, maxX - guiscaled_div(thumb->width(), 2), thumb_y);
|
||||
}
|
||||
|
||||
bool onProcessMessage(Message* msg) override
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2024 Igara Studio S.A.
|
||||
// Copyright (C) 2024-2025 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -59,13 +59,13 @@ void MiniHelpButton::onSetDecorativeWidgetBounds()
|
||||
gfx::Rect rect(0, 0, 0, 0);
|
||||
const gfx::Size thisSize = this->sizeHint();
|
||||
const gfx::Size closeSize = theme->calcSizeHint(this, theme->styles.windowCloseButton());
|
||||
const gfx::Border margin(0, 0, 0, 0);
|
||||
const gfx::Border margin = style()->margin();
|
||||
|
||||
rect.w = thisSize.w;
|
||||
rect.h = thisSize.h;
|
||||
rect.offset(window->bounds().x2() - theme->styles.windowCloseButton()->margin().width() -
|
||||
closeSize.w - style()->margin().right() - thisSize.w,
|
||||
window->bounds().y + style()->margin().top());
|
||||
closeSize.w - margin.right() - thisSize.w,
|
||||
window->bounds().y + margin.top());
|
||||
|
||||
setBounds(rect);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2023 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -65,17 +65,16 @@ protected:
|
||||
{
|
||||
auto theme = SkinTheme::get(this);
|
||||
Widget* window = parent();
|
||||
gfx::Rect rect(0, 0, 0, 0);
|
||||
gfx::Size centerSize = this->sizeHint();
|
||||
gfx::Size playSize = theme->calcSizeHint(this, theme->styles.windowPlayButton());
|
||||
gfx::Size closeSize = theme->calcSizeHint(this, theme->styles.windowCloseButton());
|
||||
const gfx::Size centerSize = this->sizeHint();
|
||||
const gfx::Size playSize = theme->calcSizeHint(this, theme->styles.windowPlayButton());
|
||||
const gfx::Size closeSize = theme->calcSizeHint(this, theme->styles.windowCloseButton());
|
||||
const gfx::Border margin = style()->margin();
|
||||
|
||||
rect.w = centerSize.w;
|
||||
rect.h = centerSize.h;
|
||||
gfx::Rect rect(centerSize);
|
||||
rect.offset(window->bounds().x2() - theme->styles.windowCloseButton()->margin().width() -
|
||||
closeSize.w - theme->styles.windowPlayButton()->margin().width() - playSize.w -
|
||||
style()->margin().right() - centerSize.w,
|
||||
window->bounds().y + style()->margin().top());
|
||||
margin.right() - centerSize.w,
|
||||
window->bounds().y + margin.top());
|
||||
|
||||
setBounds(rect);
|
||||
}
|
||||
@ -129,16 +128,14 @@ private:
|
||||
{
|
||||
auto theme = SkinTheme::get(this);
|
||||
Widget* window = parent();
|
||||
gfx::Rect rect(0, 0, 0, 0);
|
||||
gfx::Size playSize = this->sizeHint();
|
||||
gfx::Size closeSize = theme->calcSizeHint(this, theme->styles.windowCloseButton());
|
||||
gfx::Border margin(0, 0, 0, 0);
|
||||
const gfx::Size playSize = this->sizeHint();
|
||||
const gfx::Size closeSize = theme->calcSizeHint(this, theme->styles.windowCloseButton());
|
||||
const gfx::Border margin = style()->margin();
|
||||
|
||||
rect.w = playSize.w;
|
||||
rect.h = playSize.h;
|
||||
gfx::Rect rect(playSize);
|
||||
rect.offset(window->bounds().x2() - theme->styles.windowCloseButton()->margin().width() -
|
||||
closeSize.w - style()->margin().right() - playSize.w,
|
||||
window->bounds().y + style()->margin().top());
|
||||
closeSize.w - margin.right() - playSize.w,
|
||||
window->bounds().y + margin.top());
|
||||
|
||||
setBounds(rect);
|
||||
}
|
||||
|
@ -684,7 +684,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
|
||||
const char* t = xmlStyle->Attribute("margin-top");
|
||||
const char* r = xmlStyle->Attribute("margin-right");
|
||||
const char* b = xmlStyle->Attribute("margin-bottom");
|
||||
gfx::Border margin = style->margin();
|
||||
gfx::Border margin = style->rawMargin();
|
||||
if (m || l)
|
||||
margin.left(scale * std::strtol(l ? l : m, nullptr, 10));
|
||||
if (m || t)
|
||||
@ -703,7 +703,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
|
||||
const char* t = xmlStyle->Attribute("border-top");
|
||||
const char* r = xmlStyle->Attribute("border-right");
|
||||
const char* b = xmlStyle->Attribute("border-bottom");
|
||||
gfx::Border border = style->border();
|
||||
gfx::Border border = style->rawBorder();
|
||||
if (m || l)
|
||||
border.left(scale * std::strtol(l ? l : m, nullptr, 10));
|
||||
if (m || t)
|
||||
@ -722,7 +722,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
|
||||
const char* t = xmlStyle->Attribute("padding-top");
|
||||
const char* r = xmlStyle->Attribute("padding-right");
|
||||
const char* b = xmlStyle->Attribute("padding-bottom");
|
||||
gfx::Border padding = style->padding();
|
||||
gfx::Border padding = style->rawPadding();
|
||||
if (m || l)
|
||||
padding.left(scale * std::strtol(l ? l : m, nullptr, 10));
|
||||
if (m || t)
|
||||
@ -1335,7 +1335,7 @@ void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget)
|
||||
if (!widget->getSuffix().empty()) {
|
||||
Rect sufBounds(bounds.x,
|
||||
bounds.y,
|
||||
bounds.x2() - widget->childSpacing() * guiscale() - bounds.x,
|
||||
bounds.x2() - widget->childSpacing() - bounds.x,
|
||||
widget->textHeight());
|
||||
IntersectClip clip(g, sufBounds & widget->clientChildrenBounds());
|
||||
if (clip) {
|
||||
|
@ -666,8 +666,8 @@ void ToolBar::drawToolIcon(Graphics* g, int group_index, SkinPartPtr skin, os::S
|
||||
|
||||
if (icon) {
|
||||
g->drawRgbaSurface(icon,
|
||||
CALC_FOR_CENTER(toolrc.x, toolrc.w, icon->width()),
|
||||
CALC_FOR_CENTER(toolrc.y, toolrc.h, icon->height()));
|
||||
guiscaled_center(toolrc.x, toolrc.w, icon->width()),
|
||||
guiscaled_center(toolrc.y, toolrc.h, icon->height()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -799,8 +799,8 @@ void ToolBar::ToolStrip::onPaint(PaintEvent& ev)
|
||||
os::Surface* icon = theme->getToolIcon(tool->getId().c_str());
|
||||
if (icon) {
|
||||
g->drawRgbaSurface(icon,
|
||||
CALC_FOR_CENTER(toolrc.x, toolrc.w, icon->width()),
|
||||
CALC_FOR_CENTER(toolrc.y, toolrc.h, icon->height()));
|
||||
guiscaled_center(toolrc.x, toolrc.w, icon->width()),
|
||||
guiscaled_center(toolrc.y, toolrc.h, icon->height()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -13,6 +13,7 @@
|
||||
#include "ui/box.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
@ -109,7 +110,7 @@ void Box::onResize(ResizeEvent& ev)
|
||||
size = child->sizeHint().w; \
|
||||
\
|
||||
if (child->isExpansive()) { \
|
||||
int extraSize = (availExtraSize / (expansiveChildren - j)); \
|
||||
const int extraSize = guiscaled_div(availExtraSize, (expansiveChildren - j)); \
|
||||
size += extraSize; \
|
||||
availExtraSize -= extraSize; \
|
||||
if (++j == expansiveChildren) \
|
||||
|
@ -558,7 +558,7 @@ gfx::Rect Entry::onGetEntryTextBounds() const
|
||||
{
|
||||
gfx::Rect bounds = clientBounds();
|
||||
bounds.x += border().left();
|
||||
bounds.y += CALC_FOR_CENTER(0, bounds.h, textHeight());
|
||||
bounds.y += guiscaled_center(0, bounds.h, textHeight());
|
||||
bounds.w -= border().width();
|
||||
bounds.h = textHeight();
|
||||
return bounds;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -14,6 +14,7 @@
|
||||
#include "ui/grid.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/widget.h"
|
||||
@ -186,7 +187,7 @@ void Grid::onResize(ResizeEvent& ev)
|
||||
w = reqSize.w;
|
||||
}
|
||||
else if (cell->align & CENTER) {
|
||||
x += w / 2 - reqSize.w / 2;
|
||||
x = guiscaled_center(x, w, reqSize.w);
|
||||
w = reqSize.w;
|
||||
}
|
||||
else if (cell->align & RIGHT) {
|
||||
@ -198,7 +199,7 @@ void Grid::onResize(ResizeEvent& ev)
|
||||
h = reqSize.h;
|
||||
}
|
||||
else if (cell->align & MIDDLE) {
|
||||
y += h / 2 - reqSize.h / 2;
|
||||
y = guiscaled_center(y, h, reqSize.h);
|
||||
h = reqSize.h;
|
||||
}
|
||||
else if (cell->align & BOTTOM) {
|
||||
@ -394,7 +395,7 @@ void Grid::expandStrip(std::vector<Strip>& colstrip,
|
||||
}
|
||||
|
||||
// Divide the available size of the cell in the number of columns which are expandible
|
||||
int size = cell_size / expand;
|
||||
int size = guiscaled_div(cell_size, expand);
|
||||
for (i = col; i < col + cell_span; ++i) {
|
||||
if (colstrip[i].expand_count == max_expand_count) {
|
||||
// For the last column, use all the available space in the column
|
||||
@ -468,7 +469,7 @@ void Grid::distributeStripSize(std::vector<Strip>& colstrip,
|
||||
}
|
||||
}
|
||||
|
||||
int extra_foreach = extra_total / wantmore_count;
|
||||
int extra_foreach = guiscaled_div(extra_total, wantmore_count);
|
||||
|
||||
for (i = 0; i < (int)colstrip.size(); ++i) {
|
||||
if (colstrip[i].expand_count == max_expand_count || same_width) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2025 Igara Studio S.A.
|
||||
// Copyright (C) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -14,6 +15,17 @@ namespace ui {
|
||||
// Every icon/graphics/font should be scaled to this factor.
|
||||
int guiscale();
|
||||
|
||||
// num: is a numerator with the guiscale() already applied.
|
||||
inline int guiscaled_div(const int uiscaled_num, const int dem)
|
||||
{
|
||||
return ((uiscaled_num / guiscale()) / dem) * guiscale();
|
||||
}
|
||||
|
||||
inline int guiscaled_center(const int p, const int s1, const int s2)
|
||||
{
|
||||
return (p / guiscale() + (s1 / guiscale()) / 2 - (s2 / guiscale()) / 2) * guiscale();
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||
// Copyright (C) 2020-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -16,7 +16,7 @@ namespace ui {
|
||||
// static
|
||||
gfx::Border Style::UndefinedBorder()
|
||||
{
|
||||
return gfx::Border(-1, -1, -1, -1);
|
||||
return gfx::Border(kUndefinedSide, kUndefinedSide, kUndefinedSide, kUndefinedSide);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -33,9 +33,9 @@ gfx::Size Style::MaxSize()
|
||||
|
||||
Style::Style(const Style* base)
|
||||
: m_insertionPoint(0)
|
||||
, m_margin(base ? base->margin() : Style::UndefinedBorder())
|
||||
, m_border(base ? base->border() : Style::UndefinedBorder())
|
||||
, m_padding(base ? base->padding() : Style::UndefinedBorder())
|
||||
, m_margin(base ? base->rawMargin() : Style::UndefinedBorder())
|
||||
, m_border(base ? base->rawBorder() : Style::UndefinedBorder())
|
||||
, m_padding(base ? base->rawPadding() : Style::UndefinedBorder())
|
||||
, m_minSize(base ? base->minSize() : Style::MinSize())
|
||||
, m_maxSize(base ? base->maxSize() : Style::MaxSize())
|
||||
, m_gap(base ? base->gap() : gfx::Size(0, 0))
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||
// Copyright (C) 2020-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -96,6 +96,7 @@ public:
|
||||
|
||||
typedef std::vector<Layer> Layers;
|
||||
|
||||
static constexpr const int kUndefinedSide = -1;
|
||||
static gfx::Border UndefinedBorder();
|
||||
|
||||
static gfx::Size MinSize();
|
||||
@ -104,9 +105,17 @@ public:
|
||||
Style(const Style* base);
|
||||
|
||||
const std::string& id() const { return m_id; }
|
||||
const gfx::Border& margin() const { return m_margin; }
|
||||
const gfx::Border& border() const { return m_border; }
|
||||
const gfx::Border& padding() const { return m_padding; }
|
||||
|
||||
// Raw margin/border/padding values which might contain
|
||||
// kUndefinedSide values.
|
||||
const gfx::Border& rawMargin() const { return m_margin; }
|
||||
const gfx::Border& rawBorder() const { return m_border; }
|
||||
const gfx::Border& rawPadding() const { return m_padding; }
|
||||
|
||||
gfx::Border margin() const { return normalizeBorder(m_margin); }
|
||||
gfx::Border border() const { return normalizeBorder(m_border); }
|
||||
gfx::Border padding() const { return normalizeBorder(m_padding); }
|
||||
|
||||
const gfx::Size& minSize() const { return m_minSize; }
|
||||
const gfx::Size& maxSize() const { return m_maxSize; }
|
||||
const gfx::Size& gap() const { return m_gap; }
|
||||
@ -126,7 +135,27 @@ public:
|
||||
void setMnemonics(const bool enabled) { m_mnemonics = enabled; }
|
||||
void addLayer(const Layer& layer);
|
||||
|
||||
static inline void applyOnlyDefinedBorders(gfx::Border& border, const gfx::Border& defBorder)
|
||||
{
|
||||
if (defBorder.left() != kUndefinedSide)
|
||||
border.left(defBorder.left());
|
||||
if (defBorder.top() != kUndefinedSide)
|
||||
border.top(defBorder.top());
|
||||
if (defBorder.right() != kUndefinedSide)
|
||||
border.right(defBorder.right());
|
||||
if (defBorder.bottom() != kUndefinedSide)
|
||||
border.bottom(defBorder.bottom());
|
||||
}
|
||||
|
||||
private:
|
||||
static inline gfx::Border normalizeBorder(const gfx::Border& b)
|
||||
{
|
||||
return gfx::Border(b.left() == kUndefinedSide ? 0 : b.left(),
|
||||
b.top() == kUndefinedSide ? 0 : b.top(),
|
||||
b.right() == kUndefinedSide ? 0 : b.right(),
|
||||
b.bottom() == kUndefinedSide ? 0 : b.bottom());
|
||||
}
|
||||
|
||||
std::string m_id; // Just for debugging purposes
|
||||
Layers m_layers;
|
||||
int m_insertionPoint;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2019-2023 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -15,6 +15,7 @@
|
||||
#include "ui/display.h"
|
||||
#include "ui/intern.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2019-2024 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -214,7 +214,7 @@ void Theme::setDecorativeWidgetBounds(Widget* widget)
|
||||
Window* window = widget->window();
|
||||
gfx::Rect buttonBounds(widget->sizeHint());
|
||||
gfx::Rect windowBounds(window->bounds());
|
||||
gfx::Border margin(0, 0, 0, 0);
|
||||
gfx::Border margin;
|
||||
if (widget->style())
|
||||
margin = widget->style()->margin();
|
||||
|
||||
@ -506,25 +506,16 @@ void Theme::paintLayer(Graphics* g,
|
||||
g->drawAlignedUIText(text, layer.color(), bgColor, textBounds, layer.align());
|
||||
}
|
||||
else {
|
||||
gfx::Size textSize = g->measureText(text);
|
||||
const gfx::Size textSize = g->measureText(text);
|
||||
const gfx::Border padding = style->padding();
|
||||
gfx::Point pt;
|
||||
gfx::Border undef = Style::UndefinedBorder();
|
||||
gfx::Border padding = style->padding();
|
||||
if (padding.left() == undef.left())
|
||||
padding.left(0);
|
||||
if (padding.right() == undef.right())
|
||||
padding.right(0);
|
||||
if (padding.top() == undef.top())
|
||||
padding.top(0);
|
||||
if (padding.bottom() == undef.bottom())
|
||||
padding.bottom(0);
|
||||
|
||||
if (layer.align() & LEFT)
|
||||
pt.x = rc.x + padding.left();
|
||||
else if (layer.align() & RIGHT)
|
||||
pt.x = rc.x + rc.w - textSize.w - padding.right();
|
||||
else {
|
||||
pt.x = CALC_FOR_CENTER(rc.x + padding.left(), rc.w - padding.width(), textSize.w);
|
||||
pt.x = guiscaled_center(rc.x + padding.left(), rc.w - padding.width(), textSize.w);
|
||||
}
|
||||
|
||||
if (layer.align() & TOP)
|
||||
@ -532,7 +523,7 @@ void Theme::paintLayer(Graphics* g,
|
||||
else if (layer.align() & BOTTOM)
|
||||
pt.y = rc.y + rc.h - textSize.h - padding.bottom();
|
||||
else {
|
||||
pt.y = CALC_FOR_CENTER(rc.y + padding.top(), rc.h - padding.height(), textSize.h);
|
||||
pt.y = guiscaled_center(rc.y + padding.top(), rc.h - padding.height(), textSize.h);
|
||||
}
|
||||
|
||||
pt += layer.offset();
|
||||
@ -561,25 +552,16 @@ void Theme::paintLayer(Graphics* g,
|
||||
case Style::Layer::Type::kIcon: {
|
||||
os::Surface* icon = providedIcon ? providedIcon : layer.icon();
|
||||
if (icon) {
|
||||
gfx::Size iconSize(icon->width(), icon->height());
|
||||
const gfx::Size iconSize(icon->width(), icon->height());
|
||||
const gfx::Border padding = style->padding();
|
||||
gfx::Point pt;
|
||||
gfx::Border undef = Style::UndefinedBorder();
|
||||
gfx::Border padding = style->padding();
|
||||
if (padding.left() == undef.left())
|
||||
padding.left(0);
|
||||
if (padding.right() == undef.right())
|
||||
padding.right(0);
|
||||
if (padding.top() == undef.top())
|
||||
padding.top(0);
|
||||
if (padding.bottom() == undef.bottom())
|
||||
padding.bottom(0);
|
||||
|
||||
if (layer.align() & LEFT)
|
||||
pt.x = rc.x + padding.left();
|
||||
else if (layer.align() & RIGHT)
|
||||
pt.x = rc.x + rc.w - iconSize.w - padding.right();
|
||||
else {
|
||||
pt.x = CALC_FOR_CENTER(rc.x + padding.left(), rc.w - padding.width(), iconSize.w);
|
||||
pt.x = guiscaled_center(rc.x + padding.left(), rc.w - padding.width(), iconSize.w);
|
||||
}
|
||||
|
||||
if (layer.align() & TOP)
|
||||
@ -587,7 +569,7 @@ void Theme::paintLayer(Graphics* g,
|
||||
else if (layer.align() & BOTTOM)
|
||||
pt.y = rc.y + rc.h - iconSize.h - padding.bottom();
|
||||
else {
|
||||
pt.y = CALC_FOR_CENTER(rc.y + padding.top(), rc.h - padding.height(), iconSize.h);
|
||||
pt.y = guiscaled_center(rc.y + padding.top(), rc.h - padding.height(), iconSize.h);
|
||||
}
|
||||
|
||||
pt += layer.offset();
|
||||
@ -807,25 +789,8 @@ void Theme::calcWidgetMetrics(const Widget* widget,
|
||||
measureLayer(widget, style, layer, borderHint, textHint, textAlign, iconHint, iconAlign);
|
||||
});
|
||||
|
||||
gfx::Border undef = Style::UndefinedBorder();
|
||||
|
||||
if (style->border().left() != undef.left())
|
||||
borderHint.left(style->border().left());
|
||||
if (style->border().top() != undef.top())
|
||||
borderHint.top(style->border().top());
|
||||
if (style->border().right() != undef.right())
|
||||
borderHint.right(style->border().right());
|
||||
if (style->border().bottom() != undef.bottom())
|
||||
borderHint.bottom(style->border().bottom());
|
||||
|
||||
if (style->padding().left() != undef.left())
|
||||
paddingHint.left(style->padding().left());
|
||||
if (style->padding().top() != undef.top())
|
||||
paddingHint.top(style->padding().top());
|
||||
if (style->padding().right() != undef.right())
|
||||
paddingHint.right(style->padding().right());
|
||||
if (style->padding().bottom() != undef.bottom())
|
||||
paddingHint.bottom(style->padding().bottom());
|
||||
Style::applyOnlyDefinedBorders(borderHint, style->rawBorder());
|
||||
Style::applyOnlyDefinedBorders(paddingHint, style->rawPadding());
|
||||
|
||||
sizeHint = gfx::Size(borderHint.width() + paddingHint.width(),
|
||||
borderHint.height() + paddingHint.height());
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "text/fwd.h"
|
||||
#include "ui/base.h"
|
||||
#include "ui/cursor_type.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/style.h"
|
||||
|
||||
namespace gfx {
|
||||
@ -41,11 +40,6 @@ class Theme;
|
||||
void set_theme(Theme* theme, const int uiscale);
|
||||
Theme* get_theme();
|
||||
|
||||
inline int CALC_FOR_CENTER(int p, int s1, int s2)
|
||||
{
|
||||
return (p / guiscale() + (s1 / guiscale()) / 2 - (s2 / guiscale()) / 2) * guiscale();
|
||||
}
|
||||
|
||||
struct PaintWidgetPartInfo {
|
||||
gfx::Color bgColor;
|
||||
int styleFlags; // ui::Style::Layer flags
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "ui/paint_event.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/save_layout_event.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
@ -1013,7 +1014,7 @@ void Widget::getTextIconInfo(gfx::Rect* box,
|
||||
if (align() & RIGHT)
|
||||
box_x = bounds.x2() - box_w - border().right();
|
||||
else if (align() & CENTER) {
|
||||
box_x = CALC_FOR_CENTER(bounds.x + border().top(), bounds.w - border().width(), box_w);
|
||||
box_x = guiscaled_center(bounds.x + border().top(), bounds.w - border().width(), box_w);
|
||||
}
|
||||
else
|
||||
box_x = bounds.x + border().left();
|
||||
@ -1021,7 +1022,7 @@ void Widget::getTextIconInfo(gfx::Rect* box,
|
||||
if (align() & BOTTOM)
|
||||
box_y = bounds.y2() - box_h - border().bottom();
|
||||
else if (align() & MIDDLE) {
|
||||
box_y = CALC_FOR_CENTER(bounds.y + border().left(), bounds.h - border().height(), box_h);
|
||||
box_y = guiscaled_center(bounds.y + border().left(), bounds.h - border().height(), box_h);
|
||||
}
|
||||
else
|
||||
box_y = bounds.y + border().top();
|
||||
@ -1034,8 +1035,8 @@ void Widget::getTextIconInfo(gfx::Rect* box,
|
||||
icon_x = box_x + box_w - icon_w;
|
||||
}
|
||||
else if (icon_align & CENTER) {
|
||||
text_x = CALC_FOR_CENTER(box_x, box_w, text_w);
|
||||
icon_x = CALC_FOR_CENTER(box_x, box_w, icon_w);
|
||||
text_x = guiscaled_center(box_x, box_w, text_w);
|
||||
icon_x = guiscaled_center(box_x, box_w, icon_w);
|
||||
}
|
||||
else {
|
||||
text_x = box_x + box_w - text_w;
|
||||
@ -1048,8 +1049,8 @@ void Widget::getTextIconInfo(gfx::Rect* box,
|
||||
icon_y = box_y + box_h - icon_h;
|
||||
}
|
||||
else if (icon_align & MIDDLE) {
|
||||
text_y = CALC_FOR_CENTER(box_y, box_h, text_h);
|
||||
icon_y = CALC_FOR_CENTER(box_y, box_h, icon_h);
|
||||
text_y = guiscaled_center(box_y, box_h, text_h);
|
||||
icon_y = guiscaled_center(box_y, box_h, icon_h);
|
||||
}
|
||||
else {
|
||||
text_y = box_y + box_h - text_h;
|
||||
|
Loading…
x
Reference in New Issue
Block a user