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 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( const wxString& aMessage );
130
134 void ClearError();
135
139 bool IsShowingError() const;
140
144 wxStaticText* GetLabel() const { return m_label; }
145
149 bool HasLabel() const { return m_label != nullptr; }
150
154 wxStaticText* GetPrefixLabel() const { return m_prefixLabel; }
155
159 bool HasPrefixLabel() const { return m_prefixLabel != nullptr; }
160
166 void CreateLabels();
167
168private:
169 wxWindow* m_parent;
170 wxString m_fieldId;
171 wxControl* m_control;
173
177
179
180 wxStaticText* m_label;
181 wxStaticText* m_prefixLabel;
182};
183
184#endif // DRC_RE_OVERLAY_FIELD_H
void ShowError(const wxString &aMessage)
Show the error icon inside the right end of this field, with a tooltip listing the error.
wxStaticText * GetLabel() const
UNIT_BINDER * GetUnitBinder() const
wxStaticText * GetPrefixLabel() const
void CreateLabels()
Create and associate labels with this field.
std::function< void(double)> Setter
bool TransferFromWindow()
Transfer data from the control to the model.
const wxString & GetFieldId() const
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.
DRC_RE_FIELD_POSITION m_position
void ClearError()
Hide the error icon.
void SetSetter(Setter aSetter)
Set the setter lambda for writing model data.
FIELD_WARNING_ICON * m_errorIcon
Owned by the control's parent window, created on first error.
wxControl * GetControl() const
A warning icon drawn inside the right edge of a field, left of its dropdown button when it has one,...
Specifies the position and size of a field overlaid on a constraint bitmap.