FXRuby spacing and layouts

Okay, for my crossword app I’m trying to construct a matrix of squares
each with the following layout:

···

12 ****** |
****** |
****** |
****** |
****** |


where the ‘12’ is a number in a small font, and the ***s are a letter in
a large font. I’m using an FXHorizontalFrame with FXLabels inside. The
problem is, I’m trying to use a proportional font, and use height and
width properties to keep the outer square a constant size, but both
FXHorizontalFrame and FXLabel seem to ignore the height= and width=
directives.

Stripped down code below:
#!/usr/bin/env ruby

require “fox”

include Fox

WHITE = FXRGB(255, 255, 255)
GREEN = FXRGB(240, 255, 240)
BLACK = FXRGB(0, 0, 0)
RED = FXRGB(255, 240, 240)

module SpacingProperties
def unpad
self.padLeft, self.padRight, self.padTop, self.padBottom = [0,0,0,0]
end

def lrpad(n)
self.padLeft, self.padRight = [n,n]
end

def tbpad(n)
self.padTop, self.padBottom = [n,n]
end

def unspace
self.hSpacing, self.vSpacing = [0,0]
end

def squeeze
unpad
unspace
end
end

class FXWindow
include SpacingProperties
end

class FXSquare < FXHorizontalFrame
def initialize(parent, size)
super(parent , FRAME_LINE | LAYOUT_FILL_Y)
self.height = size
self.width = size
self.backColor = WHITE
self.squeeze
end
end

class FXXwordSquare < FXSquare
attr_accessor :letter, :number
def initialize(parent, size)
super(parent, size)
nframe = FXVerticalFrame.new(self, FRAME_NONE)
nframe.squeeze
nframe.backColor = WHITE
@number = FXLabel.new(nframe, rand(30).to_s)
@number.width = 10
@number.unpad
@number.font = FXFont.new(getApp(), “Helvetica”, 6)
@number.backColor = WHITE

@letter = FXLabel.new(self, (?A + rand(26)).chr)
@letter.lrpad(1)
@letter.tbpad(0)
@letter.backColor = WHITE

end
end

class FXXword < FXMatrix
include SpacingProperties
attr_accessor :squares
def initialize(parent, squaresize)
super(parent, 15, FRAME_RIDGE|MATRIX_BY_COLUMNS|LAYOUT_FILL_X|LAYOUT_FILL_Y)
self.width = squaresize15
self.height = squaresize
15
self.lrpad(5)
self.tbpad(5)
self.unspace
@squares = (0…224).map {FXXwordSquare.new(self, 25)}
end
end

class XwordWindow < FXMainWindow
def initialize(app)
# Call base class initializer first
super(app, “xword”, nil, nil, DECOR_ALL, 0, 0, 450, 450)
@xword = FXXword.new(self, 25)
end

def create
super # Create the windows
show(PLACEMENT_SCREEN) # Make the main window appear
end
end

if FILE == $0
application = FXApp.new(“XwordApp”, “FoxApp”)
XwordWindow.new(application)
application.create
application.run
end

Martin DeMello wrote:

class FXSquare < FXHorizontalFrame
def initialize(parent, size)
super(parent , FRAME_LINE | LAYOUT_FILL_Y)
self.height = size
self.width = size
self.backColor = WHITE
self.squeeze
end
end

Change the layout hints for the FXSquare to:

 super(parent, FRAME_LINE | LAYOUT_FIX_WIDTH | LAYOUT_FIX_HEIGHT)

and see if that’s the effect you are looking for. By default, child
widgets will just assume their minimum width and height.

Hope this helps,

Lyle

I have an FXMatrix defined thusly

matrix = FXMatrix.new(self, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X)

to which I’ve added several rows worth Labels and TextFields. Now I want a
button that will span both of those columns. How would I do that? I don’t
see a constant to instruct the layout manager to do this.

Joey

···


Worked like a charm. Thanks!

martin

···

Lyle Johnson lyle@users.sourceforge.net wrote:

Change the layout hints for the FXSquare to:

super(parent, FRAME_LINE | LAYOUT_FIX_WIDTH | LAYOUT_FIX_HEIGHT)

and see if that’s the effect you are looking for. By default, child
widgets will just assume their minimum width and height.

Joey Gibson wrote:

I have an FXMatrix defined thusly

matrix = FXMatrix.new(self, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X)

to which I’ve added several rows worth Labels and TextFields. Now I want a
button that will span both of those columns. How would I do that? I don’t
see a constant to instruct the layout manager to do this.

I don’t think you can do this (cells than span multiple rows or
columns). You can usually get this effect using some combination of
nested layout managers instead (e.g. a one-column matrix whose first row
is itself a 1x2 matrix, and whose second row is the button).

Yeah, that’s the conclusion I was coming to. I did this with essentially
what you described.

JOey

···

On Thu, 16 Jan 2003 03:19:12 +0900, Lyle Johnson lyle@users.sourceforge.net wrote:

I don’t think you can do this (cells than span multiple rows or
columns). You can usually get this effect using some combination of
nested layout managers instead (e.g. a one-column matrix whose first row
is itself a 1x2 matrix, and whose second row is the button).