Manažer rozložení komponent Fox::FXMatrix
, jak již název napovídá rozmístňuje komponenty do pravidelné mřížky a umožňuje nám vytvořit formulář kde komponenty „zařezávají“ jak vodorovně tak svisle.
#!/usr/bin/env ruby # $Id: matrix1.rb,v 1.2 2003/11/04 10:00:18 radek Exp $ # $Source: /home/radek/cvs/ruby-book/example/gui/fxruby/matrix1.rb,v $ require "fox" include Fox class MyApp < FXApp end class MyWin < FXMainWindow def initialize(app) super(app, "Horizontal Frame", nil, nil, DECOR_ALL, 0, 0, 190, 108) FXMatrix.new(self, 2, MATRIX_BY_COLUMNS|LAYOUT_BOTTOM) do |frame| FXLabel.new(frame, "Jm�no:") FXTextField.new(frame, 16).connect(SEL_COMMAND) do |sender, selector, data| puts data end FXLabel.new(frame, "Hodnota:") FXTextField.new(frame, 16).connect(SEL_COMMAND) do |sender, selector, data| puts data end FXLabel.new(frame, "K�d:") FXTextField.new(frame, 16).connect(SEL_COMMAND) do |sender, selector, data| puts data end FXButton.new(frame, "Odeslat", nil, app, FXApp::ID_QUIT) FXButton.new(frame, "Zru�it", nil, app, FXApp::ID_QUIT) end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 MyApp.new do |app| app.normalFont = FXFont.new(app, "-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-iso8859-2") app.init(ARGV) MyWin.new(app) app.create app.run end end
Na obrázku je vidět jak jsou jednotlivé komponenty rozmístněny.
Metody třídy
new
(
parent
,
n
=1
,
opts
=MATRIX_BY_ROWS
,
x
=0
,
y
=0
,
width
=0
,
height
=0
,
padLeft
=DEFAULT_SPACING
,
padRight
=DEFAULT_SPACING
,
padTop
=DEFAULT_SPACING
,
padBottom
=DEFAULT_SPACING
,
hSpacing
=DEFAULT_SPACING
,
vSpacing
=DEFAULT_SPACING
)
{|theMatrix| ...}
The FXMatrix layout manager automatically arranges its child windows in rows and columns. If the matrix style is MATRIX_BY_ROWS, then the matrix will have the given number of rows and the number of columns grows as more child windows are added; if the matrix style is MATRIX_BY_COLUMNS, then the number of columns is fixed and the number of rows grows as more children are added. If all children in a row (column) have the LAYOUT_FILL_ROW (LAYOUT_FILL_COLUMN) hint set, then the row (column) will be stretchable as the matrix layout manager itself is resized. If more than one row (column) is stretchable, the space is apportioned to each stretchable row (column) proportionally. Within each cell of the matrix, all other layout hints are observed. For example, a child having LAYOUT_CENTER_Y and LAYOUT_FILL_X hints will be centered in the Y-direction, while being stretched in the X-direction. Empty cells can be obtained by simply placing a borderless FXFrame widget as a space-holder. Matrix packing options MATRIX_BY_ROWS: Fixed number of rows, add columns as needed MATRIX_BY_COLUMNS: Fixed number of columns, adding rows as needed Jednotlivé parametry znamenají:
p
— rodičovské okno komponenty
opts
— volby rámce 〈Integer 〉
x
, y
— počáteční pozice 〈Integer 〉
w
, h
— šířka a výška 〈Integer 〉
pl
, pr
, pt
, pb
— vnitřní výplň (mezera) vlevo, vpravo nahoře a dole v bodech〈Integer 〉
hs
, vs
— vodorovná (horizontální) a svislá (vertikální) mezera mezi komponentami, uvedeno v bodech 〈Integer 〉
Construct a matrix layout manager with n rows or columns