PCL
Sizer.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/Sizer.h - Released 2024-01-13T15:47:58Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Sizer_h
53 #define __PCL_Sizer_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/UIObject.h>
62 
63 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
84 namespace Align
85 {
86  enum value_type
87  {
88  Expand,
89  Left,
90  Top = Left,
91  Right,
92  Bottom = Right,
93  Center,
94  Default = Expand
95  };
96 }
97 
98 // ----------------------------------------------------------------------------
99 
100 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
101 
102 class PCL_CLASS Control;
103 
104 // ----------------------------------------------------------------------------
105 
146 class PCL_CLASS Sizer : public UIObject
147 {
148 public:
149 
153  using item_alignment = Align::value_type;
154 
161  Sizer( bool vertical );
162 
166  ~Sizer() override
167  {
168  }
169 
177  void EnsureUnique() override
178  {
179  // Sizers are unique objects by definition
180  }
181 
186  static Sizer& Null();
187 
192  Control& ParentControl() const;
193 
197  bool IsVertical() const;
198 
202  bool IsHorizontal() const
203  {
204  return !IsVertical();
205  }
206 
210  int NumberOfItems() const;
211 
216  int IndexOf( const Sizer& s ) const;
217 
222  int IndexOf( const Control& c ) const;
223 
227  bool Contains( const Sizer& s ) const
228  {
229  return IndexOf( s ) >= 0;
230  }
231 
235  bool Contains( const Control& c ) const
236  {
237  return IndexOf( c ) >= 0;
238  }
239 
255  void Add( Sizer& s, int stretchFactor = 0 );
256 
292  void Add( Control& c, int stretchFactor = 0, item_alignment align = Align::Default );
293 
305  void AddSpacing( int size, bool autoScaling = true );
306 
313  void AddScaledSpacing( int size )
314  {
315  AddSpacing( size, true );
316  }
317 
324  void AddUnscaledSpacing( int size )
325  {
326  AddSpacing( size, false );
327  }
328 
337  void AddStretch( int stretchFactor = 100 );
338 
356  void Insert( int index, Sizer& s, int stretchFactor = 0 );
357 
376  void Insert( int index, Control& c, int stretchFactor = 0, item_alignment align = Align::Default );
377 
389  void InsertSpacing( int index, int size, bool autoScaling = true );
390 
397  void InsertScaledSpacing( int index, int size )
398  {
399  InsertSpacing( index, size, true );
400  }
401 
408  void InsertUnscaledSpacing( int index, int size )
409  {
410  InsertSpacing( index, size, false );
411  }
412 
421  void InsertStretch( int index, int stretchFactor = 100 );
422 
427  void Remove( Sizer& s );
428 
433  void Remove( Control& c );
434 
442  void SetStretchFactor( Sizer& s, int stretch );
443 
451  void SetStretchFactor( Control& c, int stretch );
452 
457  void SetAlignment( Sizer& s, item_alignment align );
458 
463  void SetAlignment( Control& c, item_alignment align );
464 
481  int Margin( bool autoScaling = true ) const;
482 
494  void SetMargin( int margin, bool autoScaling = true );
495 
507  int Spacing( bool autoScaling = true ) const;
508 
520  void SetSpacing( int spacing, bool autoScaling = true );
521 
536  double DisplayPixelRatio() const;
537 
544  int LogicalPixelsToPhysical( int size ) const
545  {
546  return RoundInt( DisplayPixelRatio()*size );
547  }
548 
555  int PhysicalPixelsToLogical( int size ) const
556  {
557  return RoundInt( size/DisplayPixelRatio() );
558  }
559 
560 private:
561 
562  Sizer( void* h ) : UIObject( h )
563  {
564  }
565 
566  void* CloneHandle() const override;
567 
568  friend class Control;
569 };
570 
571 // ----------------------------------------------------------------------------
572 
579 class PCL_CLASS HorizontalSizer : public Sizer
580 {
581 public:
582 
585  using item_alignment = Sizer::item_alignment;
586 
591  : Sizer( false/*vertical*/ )
592  {
593  }
594 
598  ~HorizontalSizer() override
599  {
600  }
601 };
602 
603 // ----------------------------------------------------------------------------
604 
611 class PCL_CLASS VerticalSizer : public Sizer
612 {
613 public:
614 
617  using item_alignment = Sizer::item_alignment;
618 
623  : Sizer( true/*vertical*/ )
624  {
625  }
626 
630  ~VerticalSizer() override
631  {
632  }
633 };
634 
635 // ----------------------------------------------------------------------------
636 
637 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
638 
639 } // pcl
640 
641 #endif // __PCL_Sizer_h
642 
643 // ----------------------------------------------------------------------------
644 // EOF pcl/Sizer.h - Released 2024-01-13T15:47:58Z
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::Sizer::AddUnscaledSpacing
void AddUnscaledSpacing(int size)
Definition: Sizer.h:324
pcl::HorizontalSizer::HorizontalSizer
HorizontalSizer()
Definition: Sizer.h:590
pcl::Sizer::~Sizer
~Sizer() override
Definition: Sizer.h:166
pcl::RoundInt
int RoundInt(T x) noexcept
Definition: Math.h:1503
pcl::VerticalSizer
Client-side interface to a PixInsight vertical sizer.
Definition: Sizer.h:611
pcl::UIObject
Root base class for all user interface objects.
Definition: UIObject.h:94
pcl::Sizer::LogicalPixelsToPhysical
int LogicalPixelsToPhysical(int size) const
Definition: Sizer.h:544
pcl::Sizer
Base class for PixInsight sizer objects.
Definition: Sizer.h:146
pcl::Sizer::item_alignment
Align::value_type item_alignment
Definition: Sizer.h:153
pcl::Sizer::InsertScaledSpacing
void InsertScaledSpacing(int index, int size)
Definition: Sizer.h:397
pcl::Sizer::InsertUnscaledSpacing
void InsertUnscaledSpacing(int index, int size)
Definition: Sizer.h:408
pcl::Sizer::PhysicalPixelsToLogical
int PhysicalPixelsToLogical(int size) const
Definition: Sizer.h:555
pcl::HorizontalSizer
Client-side interface to a PixInsight horizontal sizer.
Definition: Sizer.h:579
UIObject.h
pcl::Sizer::IsHorizontal
bool IsHorizontal() const
Definition: Sizer.h:202
pcl::VerticalSizer::~VerticalSizer
~VerticalSizer() override
Definition: Sizer.h:630
pcl::Sizer::Contains
bool Contains(const Control &c) const
Definition: Sizer.h:235
pcl::Control
Client-side interface to a PixInsight Control object.
Definition: Control.h:125
pcl::Sizer::EnsureUnique
void EnsureUnique() override
Definition: Sizer.h:177
pcl::Sizer::Contains
bool Contains(const Sizer &s) const
Definition: Sizer.h:227
pcl::HorizontalSizer::~HorizontalSizer
~HorizontalSizer() override
Definition: Sizer.h:598
Defs.h
pcl::VerticalSizer::VerticalSizer
VerticalSizer()
Definition: Sizer.h:622
pcl::Sizer::AddScaledSpacing
void AddScaledSpacing(int size)
Definition: Sizer.h:313