Simple GUI Library
skin.h
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file skin.h
4 * @date 2021-10-29
5 *
6 * @copyright Copyright (c) 2021
7 */
8
9#pragma once
10
11#include "sml/graphics_wrapper/renderer.h"
12#include "../../paint/insets.h"
13
14namespace Sgl
15{
16 class Control;
17 class Component;
18
19 class Skin
20 {
21 public:
22 virtual ~Skin() = default;
23
24 /**
25 * @brief Should be called by @ref Control when this skin is replaced.
26 *
27 * Must do things like removing its Components from the Control's
28 * children list, detaching its Listeners from the Control's dispatcher.
29 */
30 virtual void dispose() = 0;
31
32 virtual void prerenderControl();
33
34 virtual Component* getHitComponent(int32_t x, int32_t y);
35 virtual const Control* getControl() const = 0;
36 virtual Control* getModifiableControl() = 0;
37
38 virtual int32_t computePrefHeight(int32_t width = -1) const;
39 virtual int32_t computePrefWidth(int32_t height = -1) const;
40
41 virtual int32_t computeMinHeight(int32_t width = -1) const;
42 virtual int32_t computeMinWidth(int32_t height = -1) const;
43
44 virtual int32_t computeMaxHeight(int32_t width = -1) const;
45 virtual int32_t computeMaxWidth(int32_t height = -1) const;
46
47 virtual void layoutChildren();
48 };
49
50 template<typename C>
51 class BaseSkin : public Skin
52 {
53 public:
54 virtual void attach(C* control) = 0;
55 };
56
58 {
59 public:
60 Skin* getSkin();
61 void setSkin(Skin* skin);
62
63 protected:
64 Skin* m_Skin = nullptr;
65 };
66}
Definition: skin.h:20
virtual void dispose()=0
Should be called by Control when this skin is replaced.