1 | // Aseprite |
2 | // Copyright (C) 2020-2022 Igara Studio S.A. |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifndef APP_UI_USER_DATA_VIEW_H_INCLUDED |
8 | #define APP_UI_USER_DATA_VIEW_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "app/pref/preferences.h" |
12 | #include "app/ui/color_button.h" |
13 | #include "doc/user_data.h" |
14 | #include "obs/signal.h" |
15 | #include "ui/base.h" |
16 | #include "ui/entry.h" |
17 | #include "ui/grid.h" |
18 | #include "ui/label.h" |
19 | |
20 | #include "user_data.xml.h" |
21 | |
22 | namespace app { |
23 | |
24 | class UserDataView { |
25 | public: |
26 | UserDataView(Option<bool>& visibility); |
27 | |
28 | void configureAndSet(const doc::UserData& userData, ui::Grid* parent); |
29 | void toggleVisibility(); |
30 | void setVisible(bool state, bool saveAsDefault = true); |
31 | |
32 | const doc::UserData& userData() const { return m_userData; } |
33 | ColorButton* color() { return m_container.color(); } |
34 | ui::Entry* entry() { return m_container.entry(); } |
35 | ui::Label* colorLabel() { return m_container.colorLabel(); } |
36 | ui::Label* entryLabel() { return m_container.entryLabel(); } |
37 | |
38 | // Called when the user data text or color are changed by the user |
39 | // (not from the code/self-update). |
40 | obs::signal<void()> UserDataChange; |
41 | |
42 | private: |
43 | bool isVisible() const { return m_visibility(); } |
44 | void onEntryChange(); |
45 | void onColorChange(); |
46 | |
47 | gen::UserData m_container; |
48 | doc::UserData m_userData; |
49 | Option<bool>& m_visibility; |
50 | bool m_isConfigured = false; |
51 | // True if the change of the user data is from the same object |
52 | // (not from the user), i.e. from configureAndSet() |
53 | bool m_selfUpdate = false; |
54 | }; |
55 | |
56 | } // namespace app |
57 | |
58 | #endif |
59 | |