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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef DRC_RE_OVERLAY_FIELD_H
25#define DRC_RE_OVERLAY_FIELD_H
26
27#include <functional>
28#include <wx/string.h>
29
31
32class wxWindow;
33class wxControl;
34class wxStaticBitmap;
35class wxStaticText;
36class UNIT_BINDER;
37
38
47{
48public:
49 using Getter = std::function<double()>;
50 using Setter = std::function<void( double )>;
51
60 DRC_RE_OVERLAY_FIELD( wxWindow* aParent, const wxString& aFieldId, wxControl* aControl,
61 const DRC_RE_FIELD_POSITION& aPosition );
62
64
68 wxControl* GetControl() const { return m_control; }
69
73 const wxString& GetFieldId() const { return m_fieldId; }
74
78 const DRC_RE_FIELD_POSITION& GetPosition() const { return m_position; }
79
88 bool TransferToWindow();
89
97 bool TransferFromWindow();
98
104 void SetGetter( Getter aGetter ) { m_getter = std::move( aGetter ); }
105
111 void SetSetter( Setter aSetter ) { m_setter = std::move( aSetter ); }
112
121 void SetUnitBinder( UNIT_BINDER* aBinder ) { m_unitBinder = aBinder; }
122
127
133 void ShowError( bool aShow );
134
138 bool IsShowingError() const { return m_showingError; }
139
143 wxStaticText* GetLabel() const { return m_label; }
144
148 bool HasLabel() const { return m_label != nullptr; }
149
154 void CreateLabel();
155
156private:
157 void createErrorIcon();
158
159 wxWindow* m_parent;
160 wxString m_fieldId;
161 wxControl* m_control;
163
167
168 wxStaticBitmap* m_errorIcon;
170
171 wxStaticText* m_label;
172};
173
174#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.