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 = squaresize15
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