1// Aseprite UI Library
2// Copyright (C) 2018-2019 Igara Studio S.A.
3// Copyright (C) 2001-2017 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "ui/separator.h"
13
14#include "gfx/size.h"
15#include "ui/message.h"
16#include "ui/size_hint_event.h"
17#include "ui/theme.h"
18
19#include <algorithm>
20
21namespace ui {
22
23using namespace gfx;
24
25Separator::Separator(const std::string& text, int align)
26 : Widget(kSeparatorWidget)
27{
28 enableFlags(IGNORE_MOUSE);
29 setAlign(align);
30 if (!text.empty())
31 setText(text);
32
33 initTheme();
34}
35
36void Separator::onSizeHint(SizeHintEvent& ev)
37{
38 Size maxSize(0, 0);
39
40 for (auto child : children()) {
41 Size reqSize = child->sizeHint();
42 maxSize.w = std::max(maxSize.w, reqSize.w);
43 maxSize.h = std::max(maxSize.h, reqSize.h);
44 }
45
46 if (hasText()) {
47 maxSize.w = std::max(maxSize.w, textWidth());
48 maxSize.h = std::max(maxSize.h, textHeight());
49 }
50
51 int w = maxSize.w + border().width();
52 int h = maxSize.h + border().height();
53
54 ev.setSizeHint(Size(w, h));
55}
56
57} // namespace ui
58