2015-09-17 15:19:47 -03:00
|
|
|
// Aseprite UI Library
|
2023-02-02 11:54:13 -03:00
|
|
|
// Copyright (C) 2023 Igara Studio S.A.
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
2015-09-17 15:19:47 -03:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ui/scroll_bar.h"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void setup_scrollbars(const gfx::Size& scrollableSize,
|
|
|
|
gfx::Rect& viewportArea,
|
|
|
|
Widget& parent,
|
|
|
|
ScrollBar& hbar,
|
|
|
|
ScrollBar& vbar)
|
|
|
|
{
|
2023-02-02 11:54:13 -03:00
|
|
|
#define NEED_BAR(w, h) \
|
2015-09-17 15:19:47 -03:00
|
|
|
((scrollableSize.w > viewportArea.w) && \
|
|
|
|
(vbar.getBarWidth() < fullViewportArea.w) && \
|
|
|
|
(hbar.getBarWidth() < fullViewportArea.h))
|
|
|
|
|
|
|
|
const gfx::Rect fullViewportArea = viewportArea;
|
|
|
|
|
|
|
|
hbar.setSize(scrollableSize.w);
|
|
|
|
vbar.setSize(scrollableSize.h);
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-04 14:39:04 -03:00
|
|
|
if (hbar.parent()) parent.removeChild(&hbar);
|
|
|
|
if (vbar.parent()) parent.removeChild(&vbar);
|
2015-09-17 15:19:47 -03:00
|
|
|
|
2023-02-02 11:54:13 -03:00
|
|
|
if (NEED_BAR(w, h)) {
|
2015-09-17 15:19:47 -03:00
|
|
|
viewportArea.h -= hbar.getBarWidth();
|
|
|
|
parent.addChild(&hbar);
|
|
|
|
|
2023-02-02 11:54:13 -03:00
|
|
|
if (NEED_BAR(h, w)) {
|
2015-09-17 15:19:47 -03:00
|
|
|
viewportArea.w -= vbar.getBarWidth();
|
2023-02-02 11:54:13 -03:00
|
|
|
if (NEED_BAR(w, h))
|
2015-09-17 15:19:47 -03:00
|
|
|
parent.addChild(&vbar);
|
|
|
|
else {
|
|
|
|
viewportArea.w += vbar.getBarWidth();
|
|
|
|
viewportArea.h += hbar.getBarWidth();
|
|
|
|
parent.removeChild(&hbar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-02 11:54:13 -03:00
|
|
|
else if (NEED_BAR(h, w)) {
|
2015-09-17 15:19:47 -03:00
|
|
|
viewportArea.w -= vbar.getBarWidth();
|
|
|
|
parent.addChild(&vbar);
|
|
|
|
|
2023-02-02 11:54:13 -03:00
|
|
|
if (NEED_BAR(w, h)) {
|
2015-09-17 15:19:47 -03:00
|
|
|
viewportArea.h -= hbar.getBarWidth();
|
2023-02-02 11:54:13 -03:00
|
|
|
if (NEED_BAR(h, w))
|
2015-09-17 15:19:47 -03:00
|
|
|
parent.addChild(&hbar);
|
|
|
|
else {
|
|
|
|
viewportArea.w += vbar.getBarWidth();
|
|
|
|
viewportArea.h += hbar.getBarWidth();
|
|
|
|
parent.removeChild(&vbar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent.hasChild(&hbar)) {
|
|
|
|
hbar.setBounds(gfx::Rect(viewportArea.x, viewportArea.y2(),
|
|
|
|
viewportArea.w, hbar.getBarWidth()));
|
|
|
|
hbar.setVisible(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hbar.setVisible(false);
|
|
|
|
|
|
|
|
if (parent.hasChild(&vbar)) {
|
|
|
|
vbar.setBounds(gfx::Rect(viewportArea.x2(), viewportArea.y,
|
|
|
|
vbar.getBarWidth(), viewportArea.h));
|
|
|
|
vbar.setVisible(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vbar.setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ui
|