28#include <wx/bmpbndl.h>
29#include <wx/checkbox.h>
30#include <wx/dcbuffer.h>
31#include <wx/dcclient.h>
32#include <wx/stattext.h>
33#include <wx/textctrl.h>
47 SetBackgroundStyle( wxBG_STYLE_PAINT );
48 Create( aParent, aId );
63 wxAutoBufferedPaintDC
dc(
this );
82 else if( wxWindow* parent = GetParent() )
94 for( wxWindow* window = GetParent(); window; window = window->GetParent() )
96 if( window->UseBgCol() || window->IsTopLevel() )
97 return window->GetBackgroundColour();
100 return GetBackgroundColour();
167 wxControl* ctrl = field->GetControl();
172 int heightLogical = ctrl->GetBestSize().GetHeight();
176 int slotLogical = FromDIP( pos.
xEnd - pos.
xStart );
177 int widthLogical = slotLogical;
179 if( wxTextCtrl*
text =
dynamic_cast<wxTextCtrl*
>( ctrl ) )
184 text->GetTextExtent(
text->GetValue(), &textWidth, &textHeight );
185 widthLogical = std::max( widthLogical, textWidth + FromDIP( 24 ) );
191 widthLogical = std::min( widthLogical, std::max( *roomLogical, slotLogical ) );
193 int xLogical = FromDIP( pos.
xStart );
194 int yLogical = FromDIP( pos.
yCenter ) - heightLogical / 2;
196 ctrl->SetPosition( wxPoint( xLogical, yLogical ) );
197 ctrl->SetSize( wxSize( widthLogical, heightLogical ) );
200 if( field->HasLabel() )
203 if( field->HasPrefixLabel() )
213 if( wxControl* ctrl = field->GetControl() )
214 used = std::max( used, ctrl->GetPosition().x + ctrl->GetSize().x );
216 if( field->HasLabel() )
217 used = std::max( used, field->GetLabel()->GetPosition().x + field->GetLabel()->GetSize().x );
219 if( field->HasPrefixLabel() )
220 used = std::max( used, field->GetPrefixLabel()->GetPosition().x + field->GetPrefixLabel()->GetSize().x );
228 SetMinSize( wxSize( used, height ) );
235 std::optional<int> room;
251 int limit = FromDIP( otherPos.
xStart - pos.
xStart ) - reserved;
253 if( other->HasPrefixLabel() )
254 limit -= other->GetPrefixLabel()->GetBestSize().GetWidth() + FromDIP(
LABEL_GAP );
256 if( !room || limit < *room )
266 wxStaticText* label = aField->
GetLabel();
269 if( !label || !ctrl )
273 wxPoint ctrlPos = ctrl->GetPosition();
274 wxSize ctrlSize = ctrl->GetSize();
275 wxSize labelSize = label->GetBestSize();
283 labelPos.x = ctrlPos.x - labelSize.GetWidth() -
GAP;
284 labelPos.y = ctrlPos.y + ( ctrlSize.GetHeight() - labelSize.GetHeight() ) / 2;
288 labelPos.x = ctrlPos.x + ctrlSize.GetWidth() +
GAP;
289 labelPos.y = ctrlPos.y + ( ctrlSize.GetHeight() - labelSize.GetHeight() ) / 2;
293 labelPos.x = ctrlPos.x + ( ctrlSize.GetWidth() - labelSize.GetWidth() ) / 2;
294 labelPos.y = ctrlPos.y - labelSize.GetHeight() -
GAP;
298 labelPos.x = ctrlPos.x + ( ctrlSize.GetWidth() - labelSize.GetWidth() ) / 2;
299 labelPos.y = ctrlPos.y + ctrlSize.GetHeight() +
GAP;
307 label->SetPosition( labelPos );
308 label->SetSize( labelSize );
317 if( !prefix || !ctrl )
320 wxPoint ctrlPos = ctrl->GetPosition();
321 wxSize ctrlSize = ctrl->GetSize();
322 wxSize prefixSize = prefix->GetBestSize();
327 prefixPos.x = ctrlPos.x - prefixSize.GetWidth() -
GAP;
328 prefixPos.y = ctrlPos.y + ( ctrlSize.GetHeight() - prefixSize.GetHeight() ) / 2;
330 prefix->SetPosition( prefixPos );
331 prefix->SetSize( prefixSize );
361 it->second->ShowError( aMessage );
368 long style = wxALIGN_CENTER_VERTICAL;
371 style |= wxALIGN_RIGHT;
373 style |= wxALIGN_LEFT;
375 wxCheckBox* checkbox =
376 new wxCheckBox(
this, wxID_ANY, aPosition.
labelText, wxDefaultPosition, wxDefaultSize, style );
378 return AddControl( aId, aPosition, checkbox );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
BITMAPS
A list of all bitmap identifiers.
DRC_RE_OVERLAY_FIELD * AddCheckbox(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition)
Create and position a checkbox control on the bitmap overlay.
void LoadBitmap()
Load the appropriate bitmap variant for the current theme and DPI.
void OnThemeChange(wxSysColourChangedEvent &aEvent)
wxBitmap m_bitmap
Current background bitmap.
DRC_RE_OVERLAY_FIELD * AddControl(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, T *aControl)
Position a control on the bitmap overlay.
void OnDPIChanged(wxDPIChangedEvent &aEvent)
void PositionLabel(DRC_RE_OVERLAY_FIELD *aField)
Position a label relative to its field control based on the label position setting.
void OnPaint(wxPaintEvent &aEvent)
std::optional< int > roomBeforeNextField(const DRC_RE_OVERLAY_FIELD *aField) const
wxColour pageBackground() const
void OnFieldBlur(wxFocusEvent &aEvent)
void SetupFieldStyling(wxControl *aControl)
Apply transparent styling to a field control.
virtual ~DRC_RE_BITMAP_OVERLAY_PANEL()
bool TransferDataToWindow() override
std::map< wxString, DRC_RE_OVERLAY_FIELD * > m_fieldIdMap
Field ID to field lookup.
void ShowFieldError(const wxString &aFieldId, const wxString &aMessage)
Show an error indicator on the specified field.
int m_minHeightDIP
Height a subclass asks for, in DIP.
void SetBackgroundBitmap(BITMAPS aBitmap)
Set the background bitmap for this panel.
wxSize m_logicalBitmapSize
Bitmap size in logical pixels.
bool TransferDataFromWindow() override
DRC_RE_BITMAP_OVERLAY_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY)
void ClearFieldErrors()
Clear error indicators from all fields.
BITMAPS m_bitmapId
BITMAPS enum value.
void PositionFields()
Position all fields based on the current scale factor.
void OnFieldFocus(wxFocusEvent &aEvent)
std::vector< std::unique_ptr< DRC_RE_OVERLAY_FIELD > > m_fields
All overlay fields.
void PositionPrefixLabel(DRC_RE_OVERLAY_FIELD *aField)
Position a prefix label to the left of its field control.
Wraps a wxControl positioned over a bitmap overlay panel.
wxStaticText * GetLabel() const
wxStaticText * GetPrefixLabel() const
const DRC_RE_FIELD_POSITION & GetPosition() const
wxControl * GetControl() const
static PANEL_DRC_RULE_EDITOR * FindEditor(wxWindow *aChild)
The rule editor that hosts aChild, or nullptr when it is not inside one.
static constexpr int LABEL_GAP
Space between a field and the label beside it, in DIP.
@ BOTTOM
Label below the field.
@ RIGHT
Label to the right of the field.
@ TOP
Label above the field.
@ LEFT
Label to the left of the field.
Specifies the position and size of a field overlaid on a constraint bitmap.
LABEL_POSITION labelPosition
Position of label relative to field.
int xEnd
Right edge X coordinate where the field ends.
int xStart
Left edge X coordinate where the field starts.
wxString labelText
Optional label text (empty for no label)
int yCenter
Vertical center Y coordinate of the field.
DATABASE_CONNECTION dc(odbcBackend(cs))