Remove MIN/MAX/MID macros from ui library

This commit is contained in:
David Capello 2019-12-20 15:08:34 -03:00
parent 87c754a11c
commit 34ec123ecc
23 changed files with 157 additions and 134 deletions

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -35,6 +36,7 @@
#include "ui/alert.h"
#include "base/bind.h"
#include "base/clamp.h"
#include "base/string.h"
#include "ui/box.h"
#include "ui/button.h"
@ -142,7 +144,7 @@ CheckBox* Alert::addCheckBox(const std::string& text)
void Alert::setProgress(double progress)
{
ASSERT(m_progress);
m_progress->setValue(int(MID(0.0, progress * 100.0, 100.0)));
m_progress->setValue(int(base::clamp(progress * 100.0, 0.0, 100.0)));
}
// static

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -12,25 +12,6 @@
// Get the system's definition of NULL
#include <stddef.h>
#ifndef TRUE
#define TRUE (-1)
#define FALSE (0)
#endif
#undef MIN
#undef MAX
#undef MID
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#define MID(x,y,z) MAX((x), MIN((y), (z)))
#undef ABS
#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
#undef SGN
#define SGN(x) (((x) >= 0) ? 1 : -1)
namespace ui {
// Widget flags

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -9,13 +9,16 @@
#include "config.h"
#endif
#include "base/clamp.h"
#include "gfx/size.h"
#include "ui/box.h"
#include "ui/message.h"
#include "ui/size_hint_event.h"
#include "ui/resize_event.h"
#include "ui/size_hint_event.h"
#include "ui/theme.h"
#include <algorithm>
namespace ui {
using namespace gfx;
@ -30,12 +33,12 @@ Box::Box(int align)
void Box::onSizeHint(SizeHintEvent& ev)
{
#define ADD_CHILD_SIZE(w, h) { \
if (align() & HOMOGENEOUS) \
prefSize.w = MAX(prefSize.w, childSize.w); \
else \
prefSize.w += childSize.w; \
prefSize.h = MAX(prefSize.h, childSize.h); \
#define ADD_CHILD_SIZE(w, h) { \
if (align() & HOMOGENEOUS) \
prefSize.w = std::max(prefSize.w, childSize.w); \
else \
prefSize.w += childSize.w; \
prefSize.h = std::max(prefSize.h, childSize.h); \
}
#define FINAL_ADJUSTMENT(w) { \
@ -114,8 +117,8 @@ void Box::onResize(ResizeEvent& ev)
} \
\
Rect childPos = defChildPos; \
childPos.w = size = MID(child->minSize().w, size, child->maxSize().w); \
childPos.h = MID(child->minSize().h, childPos.h, child->maxSize().h); \
childPos.w = size = base::clamp(size, child->minSize().w, child->maxSize().w); \
childPos.h = base::clamp(childPos.h, child->minSize().h, child->maxSize().h); \
child->setBounds(childPos); \
\
defChildPos.x += size + childSpacing(); \

View File

@ -11,6 +11,7 @@
#include "ui/combobox.h"
#include "base/clamp.h"
#include "gfx/size.h"
#include "os/font.h"
#include "ui/button.h"
@ -27,6 +28,8 @@
#include "ui/view.h"
#include "ui/window.h"
#include <algorithm>
namespace ui {
using namespace gfx;
@ -432,7 +435,7 @@ void ComboBox::onSizeHint(SizeHintEvent& ev)
Size buttonSize = m_button->sizeHint();
reqSize.w += buttonSize.w;
reqSize.h = MAX(reqSize.h, buttonSize.h);
reqSize.h = std::max(reqSize.h, buttonSize.h);
ev.setSizeHint(reqSize);
}
@ -623,8 +626,8 @@ void ComboBox::openListBox()
if (!item->hasFlags(HIDDEN))
size.h += item->sizeHint().h;
int max = MAX(entryBounds.y, ui::display_h() - entryBounds.y2()) - 8*guiscale();
size.h = MID(textHeight(), size.h, max);
int max = std::max(entryBounds.y, ui::display_h() - entryBounds.y2()) - 8*guiscale();
size.h = base::clamp(size.h, textHeight(), max);
viewport->setMinSize(size);
}

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -12,6 +12,7 @@
#include "ui/entry.h"
#include "base/bind.h"
#include "base/clamp.h"
#include "base/string.h"
#include "os/draw_text.h"
#include "os/font.h"
@ -112,8 +113,8 @@ void Entry::setCaretPos(int pos)
{
gfx::Size caretSize = theme()->getEntryCaretSize(this);
int textlen = lastCaretPos();
m_caret = MID(0, pos, textlen);
m_scroll = MID(0, m_scroll, textlen);
m_caret = base::clamp(pos, 0, textlen);
m_scroll = base::clamp(m_scroll, 0, textlen);
// Backward scroll
if (m_caret < m_scroll)
@ -206,8 +207,8 @@ void Entry::getEntryThemeInfo(int* scroll, int* caret, int* state,
if ((m_select >= 0) &&
(m_caret != m_select)) {
*selbeg = MIN(m_caret, m_select);
*selend = MAX(m_caret, m_select)-1;
*selbeg = std::min(m_caret, m_select);
*selend = std::max(m_caret, m_select)-1;
}
else {
*selbeg = -1;
@ -462,7 +463,7 @@ gfx::Size Entry::sizeHintWithText(Entry* entry,
void Entry::onSizeHint(SizeHintEvent& ev)
{
int trailing = font()->textLength(getSuffix());
trailing = MAX(trailing, 2*theme()->getEntryCaretSize(this).w);
trailing = std::max(trailing, 2*theme()->getEntryCaretSize(this).w);
int w =
font()->textLength("w") * std::min(m_maxsize, 6) +
@ -513,11 +514,11 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg)
int mouseX = mousemsg->position().x;
if (mouseX < bounds().x+border().left()) {
// Scroll to the left
return MAX(0, m_scroll-1);
return std::max(0, m_scroll-1);
}
int lastPos = lastCaretPos();
int i = MIN(m_scroll, lastPos);
int i = std::min(m_scroll, lastPos);
for (; i<lastPos; ++i) {
int segmentWidth = 0;
int indexBox = 0;
@ -538,7 +539,7 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg)
break;
}
return MID(0, i, lastPos);
return base::clamp(i, 0, lastPos);
}
void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed)
@ -810,8 +811,8 @@ void Entry::backwardWord()
bool Entry::isPosInSelection(int pos)
{
return (pos >= MIN(m_caret, m_select) &&
pos <= MAX(m_caret, m_select));
return (pos >= std::min(m_caret, m_select) &&
pos <= std::max(m_caret, m_select));
}
void Entry::showEditPopupMenu(const gfx::Point& pt)

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -8,6 +9,7 @@
#include "config.h"
#endif
#include "base/clamp.h"
#include "gfx/rect.h"
#include "ui/base.h"
#include "ui/system.h"
@ -56,8 +58,8 @@ int fit_bounds(int arrowAlign, const gfx::Rect& target, gfx::Rect& bounds)
break;
}
bounds.x = MID(0, bounds.x, ui::display_w()-bounds.w);
bounds.y = MID(0, bounds.y, ui::display_h()-bounds.h);
bounds.x = base::clamp(bounds.x, 0, ui::display_w()-bounds.w);
bounds.y = base::clamp(bounds.y, 0, ui::display_h()-bounds.h);
if (target.intersects(bounds)) {
switch (trycount) {

View File

@ -26,6 +26,7 @@
#include "ui/scale.h"
#include "ui/theme.h"
#include <algorithm>
#include <cctype>
namespace ui {
@ -493,7 +494,7 @@ gfx::Size Graphics::doUIStringAlgorithm(const std::string& str, gfx::Color fg, g
gfx::Size lineSize(
m_font->textLength(line.c_str()),
m_font->height()+lineSeparation);
calculatedSize.w = MAX(calculatedSize.w, lineSize.w);
calculatedSize.w = std::max(calculatedSize.w, lineSize.w);
// Render the text
if (draw) {

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -18,6 +18,7 @@
#include "ui/theme.h"
#include "ui/widget.h"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@ -252,7 +253,7 @@ void Grid::calculateSize()
if (m_same_width_columns) {
int max_w = 0;
for (int col=0; col<(int)m_colstrip.size(); ++col)
max_w = MAX(max_w, m_colstrip[col].size);
max_w = std::max(max_w, m_colstrip[col].size);
for (int col=0; col<(int)m_colstrip.size(); ++col)
m_colstrip[col].size = max_w;
@ -346,8 +347,8 @@ void Grid::expandStrip(std::vector<Strip>& colstrip,
// Calculate the maximum (expand_count) in cell's columns.
int max_expand_count = 0;
for (i=col; i<col+cell_span; ++i)
max_expand_count = MAX(max_expand_count,
colstrip[i].expand_count);
max_expand_count = std::max(max_expand_count,
colstrip[i].expand_count);
int expand = 0; // How many columns have the maximum value of "expand_count"
int last_expand = 0; // This variable is used to add the remainder space to the last column
@ -399,8 +400,8 @@ void Grid::distributeStripSize(std::vector<Strip>& colstrip,
int max_expand_count = 0;
for (i=0; i<(int)colstrip.size(); ++i)
max_expand_count = MAX(max_expand_count,
colstrip[i].expand_count);
max_expand_count = std::max(max_expand_count,
colstrip[i].expand_count);
int total_req = 0;
int wantmore_count = 0;
@ -471,7 +472,7 @@ bool Grid::putWidgetInCell(Widget* child, int hspan, int vspan, int align)
parentcell = cell;
colbeg = col;
colend = MIN(col+hspan, (int)m_colstrip.size());
colend = std::min(col+hspan, (int)m_colstrip.size());
rowend = row+vspan;
expandRows(row+vspan);

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -10,6 +11,7 @@
#include "ui/int_entry.h"
#include "base/clamp.h"
#include "base/scoped_value.h"
#include "gfx/rect.h"
#include "gfx/region.h"
@ -23,6 +25,7 @@
#include "ui/system.h"
#include "ui/theme.h"
#include <algorithm>
#include <cmath>
namespace ui {
@ -51,12 +54,12 @@ IntEntry::~IntEntry()
int IntEntry::getValue() const
{
int value = m_slider.convertTextToValue(text());
return MID(m_min, value, m_max);
return base::clamp(value, m_min, m_max);
}
void IntEntry::setValue(int value)
{
value = MID(m_min, value, m_max);
value = base::clamp(value, m_min, m_max);
setText(m_slider.convertValueToText(value));
@ -72,7 +75,7 @@ bool IntEntry::onProcessMessage(Message* msg)
// Reset value if it's out of bounds when focus is lost
case kFocusLeaveMessage:
setValue(MID(m_min, getValue(), m_max));
setValue(base::clamp(getValue(), m_min, m_max));
deselectText();
break;
@ -107,7 +110,7 @@ bool IntEntry::onProcessMessage(Message* msg)
int newValue = oldValue
+ static_cast<MouseMessage*>(msg)->wheelDelta().x
- static_cast<MouseMessage*>(msg)->wheelDelta().y;
newValue = MID(m_min, newValue, m_max);
newValue = base::clamp(newValue, m_min, m_max);
if (newValue != oldValue) {
setValue(newValue);
selectAllText();
@ -144,12 +147,12 @@ void IntEntry::onInitTheme(InitThemeEvent& ev)
void IntEntry::onSizeHint(SizeHintEvent& ev)
{
int trailing = font()->textLength(getSuffix());
trailing = MAX(trailing, 2*theme()->getEntryCaretSize(this).w);
trailing = std::max(trailing, 2*theme()->getEntryCaretSize(this).w);
int min_w = font()->textLength(m_slider.convertValueToText(m_min));
int max_w = font()->textLength(m_slider.convertValueToText(m_max)) + trailing;
int w = MAX(min_w, max_w);
int w = std::max(min_w, max_w);
int h = textHeight();
w += border().width();

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -16,6 +17,8 @@
#include "ui/theme.h"
#include "ui/view.h"
#include <algorithm>
namespace ui {
using namespace gfx;
@ -65,8 +68,8 @@ void ListItem::onSizeHint(SizeHintEvent& ev)
for (auto child : children()) {
Size reqSize = child->sizeHint();
maxSize.w = MAX(maxSize.w, reqSize.w);
maxSize.h = MAX(maxSize.h, reqSize.h);
maxSize.w = std::max(maxSize.w, reqSize.w);
maxSize.h = std::max(maxSize.h, reqSize.h);
}
w = maxSize.w + border().width();

View File

@ -18,6 +18,7 @@
#include "ui/manager.h"
#include "base/clamp.h"
#include "base/concurrent_queue.h"
#include "base/scoped_value.h"
#include "base/time.h"
@ -1302,8 +1303,8 @@ void Manager::onInitTheme(InitThemeEvent& ev)
gfx::Rect bounds = window->bounds();
bounds *= newUIScale;
bounds /= oldUIScale;
bounds.x = MID(0, bounds.x, m_display->width() - bounds.w);
bounds.y = MID(0, bounds.y, m_display->height() - bounds.h);
bounds.x = base::clamp(bounds.x, 0, m_display->width() - bounds.w);
bounds.y = base::clamp(bounds.y, 0, m_display->height() - bounds.h);
window->setBounds(bounds);
}
}
@ -1390,7 +1391,7 @@ int Manager::pumpQueue()
// Send this message to filters
{
Filters& msg_filter = msg_filters[MIN(msg->type(), kFirstRegisteredMessage)];
Filters& msg_filter = msg_filters[std::min(msg->type(), kFirstRegisteredMessage)];
if (!msg_filter.empty()) {
LockFilters lock;
for (Filter* filter : msg_filter) {

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -11,11 +11,13 @@
#include "ui/menu.h"
#include "base/clamp.h"
#include "gfx/size.h"
#include "os/font.h"
#include "ui/intern.h"
#include "ui/ui.h"
#include <algorithm>
#include <cctype>
#include <memory>
@ -269,8 +271,8 @@ void Menu::showPopup(const gfx::Point& pos)
// Menubox position
window->positionWindow(
MID(0, pos.x, ui::display_w() - window->bounds().w),
MID(0, pos.y, ui::display_h() - window->bounds().h));
base::clamp(pos.x, 0, ui::display_w() - window->bounds().w),
base::clamp(pos.y, 0, ui::display_h() - window->bounds().h));
// Set the focus to the new menubox
Manager* manager = Manager::getDefault();
@ -349,10 +351,10 @@ void Menu::onSizeHint(SizeHintEvent& ev)
if (parent() &&
parent()->type() == kMenuBarWidget) {
size.w += reqSize.w + ((it+1 != end) ? childSpacing(): 0);
size.h = MAX(size.h, reqSize.h);
size.h = std::max(size.h, reqSize.h);
}
else {
size.w = MAX(size.w, reqSize.w);
size.w = std::max(size.w, reqSize.w);
size.h += reqSize.h + ((it+1 != end) ? childSpacing(): 0);
}
}
@ -746,8 +748,8 @@ bool MenuItem::onProcessMessage(Message* msg)
Rect pos = window->bounds();
if (inBar()) {
pos.x = MID(0, bounds().x, ui::display_w()-pos.w);
pos.y = MAX(0, bounds().y2());
pos.x = base::clamp(bounds().x, 0, ui::display_w()-pos.w);
pos.y = std::max(0, bounds().y2());
}
else {
int x_left = old_pos.x - pos.w;
@ -755,9 +757,9 @@ bool MenuItem::onProcessMessage(Message* msg)
int x, y = bounds().y-3*guiscale();
Rect r1(0, 0, pos.w, pos.h), r2(0, 0, pos.w, pos.h);
r1.x = x_left = MID(0, x_left, ui::display_w()-pos.w);
r2.x = x_right = MID(0, x_right, ui::display_w()-pos.w);
r1.y = r2.y = y = MID(0, y, ui::display_h()-pos.h);
r1.x = x_left = base::clamp(x_left, 0, ui::display_w()-pos.w);
r2.x = x_right = base::clamp(x_right, 0, ui::display_w()-pos.w);
r1.y = r2.y = y = base::clamp(y, 0, ui::display_h()-pos.h);
// Calculate both intersections
gfx::Rect s1 = r1.createIntersection(old_pos);

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -8,6 +9,7 @@
#include "config.h"
#endif
#include "base/clamp.h"
#include "gfx/size.h"
#include "ui/message.h"
#include "ui/paint_event.h"
@ -146,13 +148,13 @@ bool ScrollBar::onProcessMessage(Message* msg)
if (align() & HORIZONTAL) {
pos = (m_wherepos + mousePos.x - m_whereclick);
pos = MID(0, pos, bar_size - len);
pos = base::clamp(pos, 0, bar_size - len);
scroll.x = (m_size - viewport_size) * pos / (bar_size - len);
}
else {
pos = (m_wherepos + mousePos.y - m_whereclick);
pos = MID(0, pos, bar_size - len);
pos = base::clamp(pos, 0, bar_size - len);
scroll.y = (m_size - viewport_size) * pos / (bar_size - len);
}
@ -220,9 +222,9 @@ void ScrollBar::getScrollBarInfo(int *_pos, int *_len, int *_bar_size, int *_vie
}
else if (m_size > 0) {
len = bar_size * viewport_size / m_size;
len = MID(theme()->getScrollbarSize()*2-border_width, len, bar_size);
len = base::clamp(len, theme()->getScrollbarSize()*2-border_width, bar_size);
pos = (bar_size-len) * m_pos / (m_size-viewport_size);
pos = MID(0, pos, bar_size-len);
pos = base::clamp(pos, 0, bar_size-len);
}
else {
len = pos = 0;

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -16,6 +16,8 @@
#include "ui/size_hint_event.h"
#include "ui/theme.h"
#include <algorithm>
namespace ui {
using namespace gfx;
@ -37,13 +39,13 @@ void Separator::onSizeHint(SizeHintEvent& ev)
for (auto child : children()) {
Size reqSize = child->sizeHint();
maxSize.w = MAX(maxSize.w, reqSize.w);
maxSize.h = MAX(maxSize.h, reqSize.h);
maxSize.w = std::max(maxSize.w, reqSize.w);
maxSize.h = std::max(maxSize.h, reqSize.h);
}
if (hasText()) {
maxSize.w = MAX(maxSize.w, textWidth());
maxSize.h = MAX(maxSize.h, textHeight());
maxSize.w = std::max(maxSize.w, textWidth());
maxSize.h = std::max(maxSize.h, textHeight());
}
int w = maxSize.w + border().width();

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -10,6 +11,7 @@
#include "ui/slider.h"
#include "base/clamp.h"
#include "os/font.h"
#include "ui/manager.h"
#include "ui/message.h"
@ -18,6 +20,7 @@
#include "ui/theme.h"
#include "ui/widget.h"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
@ -31,7 +34,7 @@ Slider::Slider(int min, int max, int value, SliderDelegate* delegate)
: Widget(kSliderWidget)
, m_min(min)
, m_max(max)
, m_value(MID(min, value, max))
, m_value(base::clamp(value, min, max))
, m_readOnly(false)
, m_delegate(delegate)
{
@ -43,7 +46,7 @@ void Slider::setRange(int min, int max)
{
m_min = min;
m_max = max;
m_value = MID(min, m_value, max);
m_value = base::clamp(m_value, min, max);
invalidate();
}
@ -52,7 +55,7 @@ void Slider::setValue(int value)
{
int old_value = m_value;
m_value = MID(m_min, value, m_max);
m_value = base::clamp(value, m_min, m_max);
if (m_value != old_value)
invalidate();
@ -129,13 +132,13 @@ bool Slider::onProcessMessage(Message* msg)
}
// With right click
else {
accuracy = MID(1, rc.w / range, rc.w);
accuracy = base::clamp(rc.w / range, 1, rc.w);
value = slider_press_value +
(mousePos.x - slider_press_x) / accuracy;
}
value = MID(m_min, value, m_max);
value = base::clamp(value, m_min, m_max);
if (m_value != value) {
setValue(value);
onChange();
@ -177,7 +180,7 @@ bool Slider::onProcessMessage(Message* msg)
goto not_used;
}
value = MID(m_min, value, m_max);
value = base::clamp(value, m_min, m_max);
if (m_value != value) {
setValue(value);
onChange();
@ -193,7 +196,7 @@ bool Slider::onProcessMessage(Message* msg)
+ static_cast<MouseMessage*>(msg)->wheelDelta().x
- static_cast<MouseMessage*>(msg)->wheelDelta().y;
value = MID(m_min, value, m_max);
value = base::clamp(value, m_min, m_max);
if (m_value != value) {
this->setValue(value);
@ -217,7 +220,7 @@ void Slider::onSizeHint(SizeHintEvent& ev)
int min_w = font()->textLength(convertValueToText(m_min));
int max_w = font()->textLength(convertValueToText(m_max));
int w = MAX(min_w, max_w);
int w = std::max(min_w, max_w);
int h = textHeight();
w += border().width();

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -10,6 +11,7 @@
#include "ui/splitter.h"
#include "base/clamp.h"
#include "ui/load_layout_event.h"
#include "ui/manager.h"
#include "ui/message.h"
@ -20,6 +22,7 @@
#include "ui/system.h"
#include "ui/theme.h"
#include <algorithm>
#include <sstream>
namespace ui {
@ -207,7 +210,7 @@ void Splitter::onResize(ResizeEvent& ev)
} \
\
/* TODO uncomment this to make a restricted splitter */ \
/* pos.w = MID(reqSize1.w, pos.w, avail-reqSize2.w); */ \
/* pos.w = base::clamp(pos.w, reqSize1.w, avail-reqSize2.w); */ \
pos.h = rc.h; \
\
child1->setBounds(pos); \
@ -247,10 +250,10 @@ void Splitter::onResize(ResizeEvent& ev)
void Splitter::onSizeHint(SizeHintEvent& ev)
{
#define GET_CHILD_SIZE(w, h) \
do { \
w = MAX(w, reqSize.w); \
h = MAX(h, reqSize.h); \
#define GET_CHILD_SIZE(w, h) \
do { \
w = std::max(w, reqSize.w); \
h = std::max(h, reqSize.h); \
} while(0)
#define FINAL_SIZE(w) \
@ -338,22 +341,22 @@ void Splitter::limitPos()
if (align() & HORIZONTAL) {
switch (m_type) {
case ByPercentage:
m_pos = MID(0, m_pos, 100);
m_pos = base::clamp<double>(m_pos, 0, 100);
break;
case ByPixel:
if (isVisible())
m_pos = MID(0, m_pos, bounds().w);
m_pos = base::clamp<double>(m_pos, 0, bounds().w);
break;
}
}
else {
switch (m_type) {
case ByPercentage:
m_pos = MID(0, m_pos, 100);
m_pos = base::clamp<double>(m_pos, 0, 100);
break;
case ByPixel:
if (isVisible())
m_pos = MID(0, m_pos, bounds().h);
m_pos = base::clamp<double>(m_pos, 0, bounds().h);
break;
}
}

View File

@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -18,6 +19,8 @@
#include "ui/theme.h"
#include "ui/view.h"
#include <algorithm>
namespace ui {
TextBox::TextBox(const std::string& text, int align)
@ -169,7 +172,7 @@ void TextBox::onSizeHint(SizeHintEvent& ev)
width = bounds().w;
}
w = MAX(min, width);
w = std::max(min, width);
Theme::drawTextBox(nullptr, this, &w, &h, gfx::ColorNone, gfx::ColorNone);
w = min;

View File

@ -577,12 +577,12 @@ void Theme::calcSlices(const Widget* widget,
!layer.slicesBounds().isEmpty()) {
gfx::Rect sprite = layer.spriteBounds();
gfx::Rect slices = layer.slicesBounds();
topLeft.w = MAX(topLeft.w, slices.x);
topLeft.h = MAX(topLeft.h, slices.y);
center.w = MAX(center.w, slices.w);
center.h = MAX(center.h, slices.h);
bottomRight.w = MAX(bottomRight.w, sprite.w - slices.x2());
bottomRight.h = MAX(bottomRight.h, sprite.h - slices.y2());
topLeft.w = std::max(topLeft.w, slices.x);
topLeft.h = std::max(topLeft.h, slices.y);
center.w = std::max(center.w, slices.w);
center.h = std::max(center.h, slices.h);
bottomRight.w = std::max(bottomRight.w, sprite.w - slices.x2());
bottomRight.h = std::max(bottomRight.h, sprite.h - slices.y2());
}
});
}
@ -769,7 +769,7 @@ void Theme::drawTextBox(Graphics* g, Widget* widget,
// Make good use of the complete text-box
if (view) {
gfx::Size maxSize = view->getScrollableSize();
width = MAX(vp.w, maxSize.w);
width = std::max(vp.w, maxSize.w);
}
else {
width = vp.w;
@ -846,7 +846,7 @@ void Theme::drawTextBox(Graphics* g, Widget* widget,
}
if (w)
*w = MAX(*w, len);
*w = std::max(*w, len);
y += textheight;

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -11,6 +11,7 @@
#include "ui/tooltips.h"
#include "base/clamp.h"
#include "gfx/size.h"
#include "ui/graphics.h"
#include "ui/intern.h"
@ -211,8 +212,8 @@ bool TipWindow::pointAt(int arrowAlign, const gfx::Rect& target)
break;
}
x = MID(0, x, ui::display_w()-w);
y = MID(0, y, ui::display_h()-h);
x = base::clamp(x, 0, ui::display_w()-w);
y = base::clamp(y, 0, ui::display_h()-h);
if (m_target.intersects(gfx::Rect(x, y, w, h))) {
switch (trycount) {

View File

@ -376,8 +376,8 @@ void View::updateAttachedWidgetBounds(const gfx::Point& scrollPos)
cpos.offset(-scrollPos);
for (auto child : m_viewport.children()) {
Size reqSize = child->sizeHint();
cpos.w = MAX(reqSize.w, cpos.w);
cpos.h = MAX(reqSize.h, cpos.h);
cpos.w = std::max(reqSize.w, cpos.w);
cpos.h = std::max(reqSize.h, cpos.h);
if (cpos.w != child->bounds().w ||
cpos.h != child->bounds().h)
child->setBounds(cpos);

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
@ -18,6 +18,8 @@
#include "ui/view.h"
#include "ui/viewport.h"
#include <algorithm>
namespace ui {
using namespace gfx;
@ -43,8 +45,8 @@ void Viewport::onResize(ResizeEvent& ev)
for (auto child : children()) {
Size reqSize = child->sizeHint();
cpos.w = MAX(reqSize.w, rect.w - border().width());
cpos.h = MAX(reqSize.h, rect.h - border().height());
cpos.w = std::max(reqSize.w, rect.w - border().width());
cpos.h = std::max(reqSize.h, rect.h - border().height());
child->setBounds(cpos);
}
@ -68,8 +70,8 @@ Size Viewport::calculateNeededSize()
for (auto child : children()) {
reqSize = child->sizeHint();
maxSize.w = MAX(maxSize.w, reqSize.w);
maxSize.h = MAX(maxSize.h, reqSize.h);
maxSize.w = std::max(maxSize.w, reqSize.w);
maxSize.h = std::max(maxSize.h, reqSize.h);
}
return maxSize;

View File

@ -13,6 +13,7 @@
#include "ui/widget.h"
#include "base/clamp.h"
#include "base/memory.h"
#include "base/string.h"
#include "os/display.h"
@ -35,6 +36,7 @@
#include "ui/view.h"
#include "ui/window.h"
#include <algorithm>
#include <cctype>
#include <cstdarg>
#include <cstdio>
@ -863,19 +865,19 @@ void Widget::getTextIconInfo(
// Box size
if (icon_align & CENTER) { // With the icon in the center
if (icon_align & MIDDLE) { // With the icon inside the text
box_w = MAX(icon_w, text_w);
box_h = MAX(icon_h, text_h);
box_w = std::max(icon_w, text_w);
box_h = std::max(icon_h, text_h);
}
// With the icon in the top or bottom
else {
box_w = MAX(icon_w, text_w);
box_w = std::max(icon_w, text_w);
box_h = icon_h + (hasText() ? childSpacing(): 0) + text_h;
}
}
// With the icon in left or right that doesn't care by now
else {
box_w = icon_w + (hasText() ? childSpacing(): 0) + text_w;
box_h = MAX(icon_h, text_h);
box_h = std::max(icon_h, text_h);
}
// Box position
@ -1217,8 +1219,8 @@ Size Widget::sizeHint()
onSizeHint(ev);
Size sz(ev.sizeHint());
sz.w = MID(m_minSize.w, sz.w, m_maxSize.w);
sz.h = MID(m_minSize.h, sz.h, m_maxSize.h);
sz.w = base::clamp(sz.w, m_minSize.w, m_maxSize.w);
sz.h = base::clamp(sz.h, m_minSize.h, m_maxSize.h);
return sz;
}
}
@ -1246,8 +1248,8 @@ Size Widget::sizeHint(const Size& fitIn)
onSizeHint(ev);
Size sz(ev.sizeHint());
sz.w = MID(m_minSize.w, sz.w, m_maxSize.w);
sz.h = MID(m_minSize.h, sz.h, m_maxSize.h);
sz.w = base::clamp(sz.w, m_minSize.w, m_maxSize.w);
sz.h = base::clamp(sz.h, m_minSize.h, m_maxSize.h);
return sz;
}
}

View File

@ -25,6 +25,8 @@
#include "ui/system.h"
#include "ui/theme.h"
#include <algorithm>
namespace ui {
using namespace gfx;
@ -508,13 +510,13 @@ void Window::onSizeHint(SizeHintEvent& ev)
if (!child->isDecorative()) {
reqSize = child->sizeHint();
maxSize.w = MAX(maxSize.w, reqSize.w);
maxSize.h = MAX(maxSize.h, reqSize.h);
maxSize.w = std::max(maxSize.w, reqSize.w);
maxSize.h = std::max(maxSize.h, reqSize.h);
}
}
if (m_titleLabel)
maxSize.w = MAX(maxSize.w, m_titleLabel->sizeHint().w);
maxSize.w = std::max(maxSize.w, m_titleLabel->sizeHint().w);
ev.setSizeHint(maxSize.w + border().width(),
maxSize.h + border().height());
@ -584,8 +586,8 @@ void Window::windowSetPosition(const gfx::Rect& rect)
void Window::limitSize(int* w, int* h)
{
*w = MAX(*w, border().width());
*h = MAX(*h, border().height());
*w = std::max(*w, border().width());
*h = std::max(*h, border().height());
}
void Window::moveWindow(const gfx::Rect& rect, bool use_blit)