KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_overlay_field.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef DRC_RE_OVERLAY_FIELD_H
21#define DRC_RE_OVERLAY_FIELD_H
22
23#include <functional>
24#include <wx/string.h>
25
27
28class wxWindow;
29class wxControl;
30class wxStaticBitmap;
31class wxStaticText;
32class UNIT_BINDER;
33
34
43{
44public:
45 using Getter = std::function<double()>;
46 using Setter = std::function<void( double )>;
47
56 DRC_RE_OVERLAY_FIELD( wxWindow* aParent, const wxString& aFieldId, wxControl* aControl,
57 const DRC_RE_FIELD_POSITION& aPosition );
58
60
64 wxControl* GetControl() const { return m_control; }
65
69 const wxString& GetFieldId() const { return m_fieldId; }
70
74 const DRC_RE_FIELD_POSITION& GetPosition() const { return m_position; }
75
84 bool TransferToWindow();
85
93 bool TransferFromWindow();
94
100 void SetGetter( Getter aGetter ) { m_getter = std::move( aGetter ); }
101
107 void SetSetter( Setter aSetter ) { m_setter = std::move( aSetter ); }
108
117 void SetUnitBinder( UNIT_BINDER* aBinder ) { m_unitBinder = aBinder; }
118
123
129 void ShowError( bool aShow );
130
134 bool IsShowingError() const { return m_showingError; }
135
139 wxStaticText* GetLabel() const { return m_label; }
140
144 bool HasLabel() const { return m_label != nullptr; }
145
150 void CreateLabel();
151
152private:
153 void createErrorIcon();
154
155 wxWindow* m_parent;
156 wxString m_fieldId;
157 wxControl* m_control;
159
163
164 wxStaticBitmap* m_errorIcon;
166
167 wxStaticText* m_label;
168};
169
170#endif // DRC_RE_OVERLAY_FIELD_H
wxStaticText * GetLabel() const
UNIT_BINDER * GetUnitBinder() const
std::function< void(double)> Setter
bool TransferFromWindow()
Transfer data from the control to the model.
const wxString & GetFieldId() const
void CreateLabel()
Create and associate a label with this field.
void SetGetter(Getter aGetter)
Set the getter lambda for reading model data.
const DRC_RE_FIELD_POSITION & GetPosition() const
DRC_RE_OVERLAY_FIELD(wxWindow *aParent, const wxString &aFieldId, wxControl *aControl, const DRC_RE_FIELD_POSITION &aPosition)
Construct an overlay field wrapping an existing control.
std::function< double()> Getter
bool TransferToWindow()
Transfer data from the model to the control.
void SetUnitBinder(UNIT_BINDER *aBinder)
Associate a UNIT_BINDER for unit conversion.
void ShowError(bool aShow)
Show or hide the error indicator icon adjacent to this field.
DRC_RE_FIELD_POSITION m_position
void SetSetter(Setter aSetter)
Set the setter lambda for writing model data.
wxControl * GetControl() const
Specifies the position and size of a field overlaid on a constraint bitmap.