KiCad PCB EDA Suite
Loading...
Searching...
No Matches
margin_offset_binder.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 The 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 MARGIN_OFFSET_BINDER_H
25#define MARGIN_OFFSET_BINDER_H
26
27#include <optional>
28#include <base_units.h>
29#include <units_provider.h>
31#include <wx/event.h>
32
33class EDA_DRAW_FRAME;
34class wxTextEntry;
35class wxStaticText;
36
49class MARGIN_OFFSET_BINDER : public wxEvtHandler
50{
51public:
59 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel );
60
61 MARGIN_OFFSET_BINDER( UNITS_PROVIDER* aUnitsProvider, wxWindow* aEventSource,
62 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel );
63
64 virtual ~MARGIN_OFFSET_BINDER() override;
65
70 void SetOffsetValue( std::optional<int> aValue );
71
76 void SetRatioValue( std::optional<double> aRatio );
77
82 std::optional<int> GetOffsetValue() const;
83
88 std::optional<double> GetRatioValue() const;
89
93 bool IsNull() const;
94
98 void Enable( bool aEnable );
99
103 void Show( bool aShow, bool aResize = false );
104
105protected:
106 void onSetFocus( wxFocusEvent& aEvent );
107 void onKillFocus( wxFocusEvent& aEvent );
108 void onUnitsChanged( wxCommandEvent& aEvent );
109
114 bool parseInput( const wxString& aInput, std::optional<int>& aOffset,
115 std::optional<double>& aRatio ) const;
116
120 wxString formatValue( std::optional<int> aOffset, std::optional<double> aRatio ) const;
121
125 wxString getTextValue() const;
126
130 void setTextValue( const wxString& aValue );
131
132protected:
133 wxStaticText* m_label;
134 wxWindow* m_valueCtrl;
135 wxWindow* m_eventSource;
136 wxStaticText* m_unitLabel;
137
140
142
143 // Cached parsed values (updated on focus loss)
144 mutable std::optional<int> m_cachedOffset;
145 mutable std::optional<double> m_cachedRatio;
146 mutable bool m_needsParsing;
147};
148
149#endif // MARGIN_OFFSET_BINDER_H
The base class for create windows for drawing purpose.
bool IsNull() const
Return true if the control holds no value (ie: empty string).
std::optional< int > GetOffsetValue() const
Get the absolute offset value (in Internal Units).
MARGIN_OFFSET_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel)
std::optional< double > GetRatioValue() const
Get the ratio value as a fraction (e.g., -0.05 for -5%).
const EDA_IU_SCALE * m_iuScale
virtual ~MARGIN_OFFSET_BINDER() override
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void onSetFocus(wxFocusEvent &aEvent)
bool parseInput(const wxString &aInput, std::optional< int > &aOffset, std::optional< double > &aRatio) const
Parse the input string and extract offset and ratio values.
wxStaticText * m_unitLabel
Can be nullptr.
void SetRatioValue(std::optional< double > aRatio)
Set the ratio value as a fraction (e.g., -0.05 for -5%).
std::optional< int > m_cachedOffset
void Show(bool aShow, bool aResize=false)
Show/hide the label, widget and units label.
std::optional< double > m_cachedRatio
wxString getTextValue() const
Get the current text from the control.
void onKillFocus(wxFocusEvent &aEvent)
void setTextValue(const wxString &aValue)
Set the text in the control without triggering events.
wxString formatValue(std::optional< int > aOffset, std::optional< double > aRatio) const
Format the offset and ratio values into a display string.
void onUnitsChanged(wxCommandEvent &aEvent)
void SetOffsetValue(std::optional< int > aValue)
Set the absolute offset value (in Internal Units).
EDA_UNITS
Definition eda_units.h:48