123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- class IUP_GRID_BOX
- -- Creates a void container for composing elements in a regular grid. It is a
- -- box that arranges the elements it contains from top to bottom and from left
- -- to right, but can distribute the elements in lines or in columns.
- --
- -- The child elements are added to the control just like a vbox and hbox,
- -- sequentially. Then they are distributed accordingly the attributes
- -- ORIENTATION and NUMDIV. When ORIENTATION=HORIZONTAL children are distributed
- -- from left to right on the first line until NUMDIV, then on the second line,
- -- and so on. When ORIENTATION=VERTICAL children are distributed from top to
- -- bottom on the first column until NUMDIV, then on the second column, and so
- -- on. The number of lines and the number of columns can be easily obtained
- -- from the combination of these attributes.
- --
- -- Notice that the total number of spaces can be larger than the number of
- -- actual children, the last line or column can be incomplete.
- --
- -- The column sizes will be based only on the width of the children of the
- -- reference line, usually line 0. The line sizes will be based only on the
- -- height of the children of the reference column, usually column 0.
- inherit
- IUP_CONTAINER
- IUP_WIDGET_EXPAND
- IUP_WIDGET_WID
- IUP_WIDGET_SIZE
- IUP_WIDGET_RASTERSIZE
- IUP_WIDGET_USERSIZE
- IUP_WIDGET_FONT
- IUP_WIDGET_CLIENTSIZE
- IUP_WIDGET_CLIENTOFFSET
- IUP_WIDGET_POSITION
- IUP_WIDGET_MAXMIN_SIZE
- IUP_WIDGET_CHILD
- IUP_WIDGET_NAME
- IUP_WIDGET_CUSTOM_ATTRIBUTES
- IUP_WIDGET_NORMALIZE_SIZE
- redefine
- set_normalize_size
- end
- create {ANY}
- grid_box_empty,
- grid_box
-
- feature {ANY}
-
- grid_box_empty
- -- Create an empty grid box.
- local
- p, a_grid_box: POINTER
- do
- a_grid_box := int_grid_box_empty (p)
- set_widget(a_grid_box)
- end
-
- grid_box (col: ARRAY[IUP_WIDGET])
- -- Create a new grid box containing the list of widgets.
- local
- i: INTEGER; arg: ARRAY[POINTER]; s: IUP_WIDGET; a_grid_box: POINTER
- do
- i := col.count
- create arg.make_filled(default_pointer, 1, i + 1)
- i := 0
-
- across
- col as ic
- loop
- i := i + 1
- s := ic.item
- arg.put(s.widget, i)
- end
- a_grid_box := int_grid_box (get_pointer(arg.to_c))
- set_widget(a_grid_box)
- end
- -- Commands to handle attributes.
-
- set_alignment_line (value: STRING)
- -- Vertically aligns the elements within each line. Possible values:
- -- "ATOP", "ACENTER", "ABOTTOM". Default: "ATOP".
- -- (non inheritable)
- require
- valid_lin: is_valid_alignment_lin(value)
- do
- iup_open.set_attribute(Current, "ALIGNMENTLIN", value)
- end
- get_alignment_line: STRING
- -- Return the vertical align of the elements within each line.
- do
- Result := iup_open.get_attribute(Current, "ALIGNMENTLIN")
- end
- set_alignment_for_line (value: STRING; line: INTEGER)
- -- Set the alignment of a single line.
- require
- valid_lin: is_valid_alignment_lin(value)
- line >= 0
- local
- str: STRING
- do
- str := "ALIGNMENTLIN" + line.out
- iup_open.set_attribute(Current, str, value)
- end
- get_alignment_for_line (line: INTEGER): STRING
- -- Return the alignment used at the line.
- require
- line >= 0
- local
- str: STRING
- do
- str := "ALIGNMENTLIN" + line.out
- Result := iup_open.get_attribute(Current, str)
- end
-
- set_alignment_column (value: STRING)
- -- Horizontally aligns the elements within each column. Possible values:
- -- "ALEFT", "ACENTER", "ARIGHT". Default: "ALEFT".
- -- (non inheritable)
- require
- valid_col: is_valid_alignment_col(value)
- do
- iup_open.set_attribute(Current, "ALIGNMENTCOL", value)
- end
- get_alignment_column: STRING
- -- Return the horizontal align of the elements within each line.
- do
- Result := iup_open.get_attribute(Current, "ALIGNMENTCOL")
- end
- set_alignment_for_column (value: STRING; col: INTEGER)
- -- Set the alignment of a single column.
- require
- valid_col: is_valid_alignment_col(value)
- col >= 0
- local
- str: STRING
- do
- str := "ALIGNMENTCOL" + col.out
- iup_open.set_attribute(Current, str, value)
- end
- get_alignment_for_column (col: INTEGER): STRING
- -- Return the alignment used at the column.
- require
- col >= 0
- local
- str: STRING
- do
- str := "ALIGNMENTCOL" + col.out
- Result := iup_open.get_attribute(Current, str)
- end
- set_expand_children (value: STRING)
- -- Forces all children to expand in the given direction and to fully
- -- occupy its space available inside the box. Can be YES (both
- -- directions), HORIZONTAL, VERTICAL or NO. Default: "NO". This has the
- -- same effect as setting EXPAND on each child.
- -- (non inheritable).
- require
- valid_expand_children: is_valid_expand_children(value)
- do
- iup_open.set_attribute(Current, "EXPANDCHILDREN", value)
- end
- get_expand_children: STRING
- -- Return the value of the used expand children.
- do
- Result := iup_open.get_attribute(Current, "EXPANDCHILDREN")
- end
- set_fit_to_children_at_line (line: INTEGER)
- -- (write-only) Set the RASTERSIZE attribute of the reference element in
- -- the given line, so that it will fit the highest element in the line.
- -- Can only be set after the layout of the dialog has been calculated at
- -- least 1 time. If FITMAXWIDTHn or FITMAXHEIGHTn are set for the line
- -- they are used as maximum limit for the size.
- require
- line > 0
- local
- str: STRING
- do
- str := "L" + line.out
- iup_open.set_attribute(Current, "FITTOCHILDREN", str)
- end
- set_fit_to_children_at_column (column: INTEGER)
- -- (write-only) Set the RASTERSIZE attribute of the reference element in
- -- the given column, so that it will fit the largest element in the
- -- column. Can only be set after the layout of the dialog has been
- -- calculated at least 1 time. If FITMAXWIDTHn or FITMAXHEIGHTn are set
- -- for the column they are used as maximum limit for the size.
- require
- column > 0
- local
- str: STRING
- do
- str := "C" + column.out
- iup_open.set_attribute(Current, "FITTOCHILDREN", str)
- end
- set_gaplin (space: INTEGER)
- -- Defines a vertical space in pixels between lines. Default: "0".
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "GAPLIN", space.out)
- end
- get_gaplin: INTEGER
- -- Return the vertical space between lines.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "GAPLIN")
- Result := value.to_integer
- end
- set_cgaplin (space: INTEGER)
- -- Defines a vertical space between lines in the same units of the SIZE
- -- attribute for the height. Default: "0".
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "CGAPLIN", space.out)
- end
- get_cgaplin: INTEGER
- -- Return the value of the attribute cgaplin.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "CGAPLIN")
- Result := value.to_integer
- end
- set_gapcol (space: INTEGER)
- -- Defines an horizontal space in pixels between columns. Default: "0".
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "GAPCOL", space.out)
- end
- get_gapcol: INTEGER
- -- Return the horizontal space between columns.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "GAPCOL")
- Result := value.to_integer
- end
- set_cgapcol (space: INTEGER)
- -- Defines an horizontal space between columns in the same units of the
- -- SIZE attribute for the height. Default: "0".
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "CGAPCOL", space.out)
- end
- get_cgapcol: INTEGER
- -- Return the value of the attribute cgapcol.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "CGAPCOL")
- Result := value.to_integer
- end
- set_ngaplin (space: INTEGER)
- -- Same as *GAPLIN* but non inheritable.
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "NGAPLIN", space.out)
- end
- get_ngaplin: INTEGER
- -- Return the value of *NGAPLIN* attribute.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "NGAPLIN")
- Result := value.to_integer
- end
- set_ncgaplin (space: INTEGER)
- -- Same as *CGAPLIN* but non inheritable.
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "NCGAPLIN", space.out)
- end
- get_ncgaplin: INTEGER
- -- Return the value of *NCGAPLIN* attribute.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "NCGAPLIN")
- Result := value.to_integer
- end
-
- set_ngapcol (space: INTEGER)
- -- Same as *GAPCOL* but non inheritable.
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "NGAPCOL", space.out)
- end
- get_ngapcol: INTEGER
- -- Return the value of *NGAPCOL* attribute.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "NGAPCOL")
- Result := value.to_integer
- end
- set_ncgapcol (space: INTEGER)
- -- Same as *CGAPCOL* but non inheritable.
- require
- space >= 0
- do
- iup_open.set_attribute(Current, "NCGAPCOL", space.out)
- end
- get_ncgapcol: INTEGER
- -- Return the value of *NCGAPCOL* attribute.
- local
- value: STRING
- do
- value := iup_open.get_attribute(Current, "NCGAPCOL")
- Result := value.to_integer
- end
- set_homogeneous_lines (state: BOOLEAN)
- -- (non inheritable): forces all lines to have the same vertical space,
- -- or height. The line height will be based on the highest child of the
- -- reference column (See set_sizecol). Default: "NO". Notice that this
- -- does not changes the children size, only the available space for each
- -- one of them to expand.
- do
- iup_open.set_attribute(Current, "HOMOGENEOUSLIN", boolean_to_yesno(state))
- end
- is_homogeneous_lines: BOOLEAN
- -- Return the state of homogeneouslin.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "HOMOGENEOUSLIN")
- Result := yesno_to_boolean(str)
- end
- set_homogeneous_columns (state: BOOLEAN)
- -- (non inheritable): forces all columns to have the same horizontal
- -- space, or width. The column width will be based on the largest child
- -- of the reference line (See set_sizelin). Default: "NO". Notice that
- -- this does not changes the children size, only the available space for
- -- each one of them to expand.
- do
- iup_open.set_attribute(Current, "HOMOGENEOUSCOL", boolean_to_yesno(state))
- end
- is_homogeneous_columns: BOOLEAN
- -- Return the state of homogeneouscol.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "HOMOGENEOUSCOL")
- Result := yesno_to_boolean(str)
- end
- set_margin (horizontal, vertical: INTEGER)
- -- Defines a margin in pixels. Default: "0x0" (no margin).
- require
- horizontal >= 0
- vertical >= 0
- local
- margin: STRING
- do
- margin := horizontal.out
- margin.append_string("x")
- margin.append_string(vertical.out)
- iup_open.set_attribute(Current, "MARGIN", margin)
- end
- get_margin: TUPLE[INTEGER, INTEGER]
- -- Return the value of the margins.
- local
- margin: STRING
- do
- margin := iup_open.get_attribute(Current, "MARGIN")
- Result := components_of_size(margin)
- end
- set_cmargin (horizontal, vertical: INTEGER)
- -- Defines a margin in the same units of the SIZE attribute.
- -- Default: "0x0" (no margin).
- require
- horizontal >= 0
- vertical >= 0
- local
- margin: STRING
- do
- margin := horizontal.out
- margin.append_string("x")
- margin.append_string(vertical.out)
- iup_open.set_attribute(Current, "CMARGIN", margin)
- end
- get_cmargin: TUPLE[INTEGER, INTEGER]
- -- Return the value of the CMARGIN.
- local
- margin: STRING
- do
- margin := iup_open.get_attribute(Current, "CMARGIN")
- Result := components_of_size(margin)
- end
- set_nmargin (horizontal, vertical: INTEGER)
- -- (non inheritable): Same as MARGIN but are non inheritable.
- require
- horizontal >= 0
- vertical >= 0
- local
- margin: STRING
- do
- margin := horizontal.out
- margin.append_string("x")
- margin.append_string(vertical.out)
- iup_open.set_attribute(Current, "NMARGIN", margin)
- end
- get_nmargin: TUPLE[INTEGER, INTEGER]
- -- Return the value of the nmargin.
- local
- margin: STRING
- do
- margin := iup_open.get_attribute(Current, "NMARGIN")
- Result := components_of_size(margin)
- end
- set_ncmargin (horizontal, vertical: INTEGER)
- -- (non inheritable): Same as CMARGIN but are non inheritable.
- require
- horizontal >= 0
- vertical >= 0
- local
- margin: STRING
- do
- margin := horizontal.out
- margin.append_string("x")
- margin.append_string(vertical.out)
- iup_open.set_attribute(Current, "NCMARGIN", margin)
- end
- get_ncmargin: TUPLE[INTEGER, INTEGER]
- -- Return the value of NCMARGIN.
- local
- margin: STRING
- do
- margin := iup_open.get_attribute(Current, "NCMARGIN")
- Result := components_of_size(margin)
- end
- set_numdiv (num: INTEGER)
- -- Controls the number of divisions along the distribution according to
- -- ORIENTATION. When ORIENTATION=HORIZONTAL, NUMDIV is the number of
- -- columns, when ORIENTATION=VERTICAL, NUMDIV is the number of lines.
- -- When value is 0, its actual value will be calculated to fit the
- -- maximum number of elements in the orientation direction. Default: 0.
- require
- num >= 0
- local
- str: STRING
- do
- if num.is_equal(0) then
- str := "AUTO"
- else
- str := num.out
- end
- iup_open.set_attribute(Current, "NUMDIV", str)
- end
- get_numdiv: INTEGER
- -- Return the number of divisions.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "NUMDIV")
- if str.is_equal("AUTO") then
- Result := 0
- else
- Result := str.to_integer
- end
- end
- get_lines: INTEGER
- -- (read-only): returns the number of lines.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "NUMLIN")
- Result := str.to_integer
- end
- get_columns: INTEGER
- -- (read-only): returns the number of columns.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "NUMCOL")
- Result := str.to_integer
- end
- set_normalize_size (value: STRING)
- -- (non inheritable): normalizes all children natural size to be the
- -- biggest natural size among the reference line and/or the reference
- -- column. All natural width will be set to the biggest width, and all
- -- natural height will be set to the biggest height according to is
- -- value. Can be NO, HORIZONTAL (width only), VERTICAL (height only) or
- -- BOTH. Default: "NO". Same as using IUP_NORMALIZER. Notice that this is
- -- different from the HOMOGENEOUS* attributes in the sense that the
- -- children will have their sizes changed.
- do
- Precursor (value)
- end
- set_horizontal_orientation
- -- (non inheritable): controls the distribution of the children in
- -- columns. This is the default value.
- do
- iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
- end
- set_vertical_orientation
- -- (non inheritable): controls the distribution of the children in
- -- lines.
- do
- iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
- end
- is_horizontal: BOOLEAN
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "ORIENTATION")
- if str.is_equal("HORIZONTAL") then
- Result := True
- else
- Result := False
- end
- end
- is_vertical: BOOLEAN
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "ORIENTATION")
- if str.is_equal("VERTICAL") then
- Result := True
- else
- Result := False
- end
- end
- set_reference_column (col: INTEGER)
- -- (non inheritable): index of the column that will be used as reference
- -- when calculating the height of the lines. Default: 0.
- require
- col >= 0
- do
- iup_open.set_attribute(Current, "SIZECOL", col.out)
- end
- get_reference_column: INTEGER
- -- Return the index of the column used as reference.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "SIZECOL")
- Result := str.to_integer
- end
- set_reference_line (line: INTEGER)
- -- (non inheritable): index of the line that will be used as reference
- -- when calculating the width of the columns. Default: 0.
- require
- line >= 0
- do
- iup_open.set_attribute(Current, "SIZELIN", line.out)
- end
- get_reference_line: INTEGER
- -- Return the index of the line used as reference.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "SIZELIN")
- Result := str.to_integer
- end
- -- Validations
- is_valid_alignment_lin (value: STRING): BOOLEAN
- do
- if value.is_equal("ATOP") or
- value.is_equal("ACENTER") or
- value.is_equal("ABOTTOM") then
- Result := True
- else
- Result := False
- end
- end
- is_valid_alignment_col (value: STRING): BOOLEAN
- do
- if value.is_equal("ALEFT") or
- value.is_equal("ACENTER") or
- value.is_equal("ARIGHT") then
- Result := True
- else
- Result := False
- end
- end
- is_valid_expand_children (value: STRING): BOOLEAN
- do
- if value.is_equal("YES") or
- value.is_equal("HORIZONTAL") or
- value.is_equal("VERTICAL") or
- value.is_equal("NO") then
- Result := True
- else
- Result := False
- end
- end
- feature {NONE}
- -- Internals
-
- int_grid_box_empty (arguments: POINTER): POINTER
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "return IupGridBox ($arguments);"
- end
-
- int_grid_box (arguments: POINTER): POINTER
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "return IupGridBoxv ($arguments);"
- end
-
- end -- class IUP_GRID_BOX
- -- The MIT License (MIT)
- -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
- -- Permission is hereby granted, free of charge, to any person obtaining a copy
- -- of this software and associated documentation files (the "Software"), to deal
- -- in the Software without restriction, including without limitation the rights
- -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- -- copies of the Software, and to permit persons to whom the Software is
- -- furnished to do so, subject to the following conditions:
- --
- -- The above copyright notice and this permission notice shall be included in
- -- all copies or substantial portions of the Software.
- --
- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- -- SOFTWARE.
|