[fxruby-users] Text color for individual items in FXTable
Tim Smith
tsmith at tektone.net
Wed Feb 27 11:23:22 EST 2008
Good news, everybody! I found a thread on comp.lang.ruby about a
similar problem setting fonts for individual table items:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/b568f
66fe08a69a5/625209163eb11dd8?#625209163eb11dd8
Like me, he found drawContent's dc parameter unusable. His solution was
to create a new one with FXDCWindow.new. That worked for me and I can
now set individual text colors; code below. If no one objects, I'll
file a bug report about the unusable dc parameter.
Regards, Tim
require 'fox16'; include Fox
class CustomTableItem < FXTableItem
attr_accessor :color
def drawContent table, unusable_dc, x, y, w, h
FXDCWindow.new(table) {|dc|
if @color and not selected?
dc.setForeground @color
def dc.setForeground color
# stop super from setting color back
end
end
dc.setFont unusable_dc.getFont
super table, dc, x, y, w, h
}
end
end
class CustomTable < FXTable
def createItem *parameters
CustomTableItem.new *parameters
end
def setItemTextColor row, column, color
getItem(row, column).color = color
updateItem row, column
end
end
app = FXApp.new
main = FXMainWindow.new app, 'Test'
table = CustomTable.new main
table.setTableSize 2, 2
table.visibleRows = 2
table.visibleColumns = 2
table.setItemText 0, 0, 'one'
table.setItemTextColor 0, 0, FXRGB(255, 0, 0) # red
table.setItemText 0, 1, 'two'
table.setItemTextColor 0, 1, FXRGB(0, 255, 0) # green
table.setItemText 1, 0, 'three'
table.setItemTextColor 1, 0, FXRGB(0, 0, 255) # blue
table.setItemText 1, 1, 'four'
app.create
main.show PLACEMENT_SCREEN
app.run
More information about the fxruby-users
mailing list