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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef MARGIN_OFFSET_BINDER_H
21#define MARGIN_OFFSET_BINDER_H
22
23#include <optional>
24#include <base_units.h>
25#include <units_provider.h>
27#include <wx/event.h>
28
29class EDA_DRAW_FRAME;
30class wxTextEntry;
31class wxStaticText;
32
45class MARGIN_OFFSET_BINDER : public wxEvtHandler
46{
47public:
55 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel );
56
57 MARGIN_OFFSET_BINDER( UNITS_PROVIDER* aUnitsProvider, wxWindow* aEventSource,
58 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel );
59
60 virtual ~MARGIN_OFFSET_BINDER() override;
61
66 void SetOffsetValue( std::optional<int> aValue );
67
72 void SetRatioValue( std::optional<double> aRatio );
73
78 std::optional<int> GetOffsetValue() const;
79
84 std::optional<double> GetRatioValue() const;
85
89 bool IsNull() const;
90
94 void Enable( bool aEnable );
95
99 void Show( bool aShow, bool aResize = false );
100
101protected:
102 void onSetFocus( wxFocusEvent& aEvent );
103 void onKillFocus( wxFocusEvent& aEvent );
104 void onTextChanged( wxCommandEvent& aEvent );
105 void onUnitsChanged( wxCommandEvent& aEvent );
106
111 bool parseInput( const wxString& aInput, std::optional<int>& aOffset,
112 std::optional<double>& aRatio ) const;
113
117 wxString formatValue( std::optional<int> aOffset, std::optional<double> aRatio ) const;
118
122 wxString getTextValue() const;
123
127 void setTextValue( const wxString& aValue );
128
129protected:
130 wxStaticText* m_label;
131 wxWindow* m_valueCtrl;
132 wxWindow* m_eventSource;
133 wxStaticText* m_unitLabel;
134
137
139
140 // Cached parsed values (updated on focus loss)
141 mutable std::optional<int> m_cachedOffset;
142 mutable std::optional<double> m_cachedRatio;
143 mutable bool m_needsParsing;
144};
145
146#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).
void onTextChanged(wxCommandEvent &aEvent)
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:44