1// Aseprite UI Library
2// Copyright (C) 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#ifndef UI_VIEW_H_INCLUDED
9#define UI_VIEW_H_INCLUDED
10#pragma once
11
12#include "gfx/point.h"
13#include "gfx/size.h"
14#include "ui/scroll_bar.h"
15#include "ui/viewport.h"
16#include "ui/widget.h"
17
18namespace ui {
19 class ScrollRegionEvent;
20
21 class ViewableWidget {
22 public:
23 virtual ~ViewableWidget() { }
24 virtual void onScrollRegion(ScrollRegionEvent& ev) = 0;
25 };
26
27 class View : public Widget
28 , public ScrollableViewDelegate {
29 public:
30 View();
31
32 bool hasScrollBars();
33 ScrollBar* horizontalBar() { return &m_scrollbar_h; }
34 ScrollBar* verticalBar() { return &m_scrollbar_v; }
35
36 void attachToView(Widget* viewableWidget);
37 Widget* attachedWidget();
38
39 void hideScrollBars();
40 void showScrollBars();
41 void makeVisibleAllScrollableArea();
42
43 // Returns the maximum viewable size requested by the attached
44 // widget in the viewport.
45 gfx::Size getScrollableSize() const;
46 void setScrollableSize(const gfx::Size& sz,
47 const bool setScrollPos = true);
48
49 // Returns the visible/available size to see the attached widget.
50 gfx::Size visibleSize() const override;
51 gfx::Point viewScroll() const override;
52 void setViewScroll(const gfx::Point& pt) override;
53
54 void updateView(const bool restoreScrollPos = true);
55
56 Viewport* viewport();
57 gfx::Rect viewportBounds();
58
59 // For viewable widgets
60 static View* getView(const Widget* viewableWidget);
61
62 protected:
63 // Events
64 bool onProcessMessage(Message* msg) override;
65 void onInitTheme(InitThemeEvent& ev) override;
66 void onResize(ResizeEvent& ev) override;
67 void onSizeHint(SizeHintEvent& ev) override;
68
69 virtual void onSetViewScroll(const gfx::Point& pt);
70 virtual void onScrollRegion(ScrollRegionEvent& ev);
71 virtual void onScrollChange();
72
73 private:
74 void updateAttachedWidgetBounds(const gfx::Point& scrollPos);
75 gfx::Point limitScrollPosToViewport(const gfx::Point& pt) const;
76
77 bool m_hasBars;
78 Viewport m_viewport;
79 ScrollBar m_scrollbar_h;
80 ScrollBar m_scrollbar_v;
81 };
82
83} // namespace ui
84
85#endif
86