I''m having some difficulty trying to bold the text in a FXLabel object. The catch is that I *don''t* want to specify a font. Is it possible to tell the text to use a bold style without specifying the font? I''d like the app to use the bold style of whatever system font is in use by default. Is it possible to do this? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/3cdee676/attachment.html>
Bartosz DziewoĆski
2010-Apr-15 12:45 UTC
[fxruby-users] How can you bold the text in a label?
2010/4/15 Paul Carvalho <tester.paul at gmail.com>:> I''m having some difficulty trying to bold the text in a FXLabel object. ?The > catch is that I *don''t* want to specify a font. > Is it possible to tell the text to use a bold style without specifying the > font? ?I''d like the app to use the bold style of whatever system font is in > use by default.Have you tried to use nil/empty string font face and use font style hint "System"? Or try any font together with the hint? I haven''t tried it myself, but according to docs it might work. -- Matma Rex - http://matma-rex.prv.pl/
I''m not at my development computer right now so I can''t tell you the exact code I tried, but I can say that, yes, I did try to use a nil/empty string font face and Ruby choked on it -- didn''t like it. I tried "system" as a font face and that *really* didn''t do what I wanted either! =) I entered "arial" and then the one label font changed - I had forgotten that the default system font is not Arial. So the one label really stands out now because it''s a totally different font.. which is not what I want. I don''t want to hard-code a font that is different from the system font, especially if the app will run on different platforms and I don''t know what the default fonts will be. I can try some other variations tonight. I''ve already spent over 4 hours on this and haven''t gotten it to work. Maybe I just needed a break to see something that I''ve missed. I thought it would be something that would have come up by now.. I''ve seen lots of apps where a label is bolded to indicate a required field. I just haven''t found any FXRuby examples of this *without* also specifying the font at the same time. Cheers. P. 2010/4/15 Bartosz Dziewo?ski :> > Have you tried to use nil/empty string font face and use font style > hint "System"? Or try any font together with the hint? > > I haven''t tried it myself, but according to docs it might work. > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/c35311fc/attachment.html>
There are definitely better ways of doing this, but here is a basic example: Begin code ----------------- #! /usr/bin/env ruby require ''rubygems'' require ''fox16'' include Fox class SimpleWindow < FXMainWindow def initialize(app) super(app, "My Simple Window", :opts => DECOR_ALL, :width => 640, :height => 480) draw_widgets() end def draw_widgets() label = FXLabel.new(self, "This is my label that is normal.") label.font = FXFont.new(getApp(), select_font()) label2 = FXLabel.new(self, "This is my label that is bold.") label2.font = FXFont.new(getApp(), select_font(FONTWEIGHT_BOLD)) end def select_font(weight = FONTWEIGHT_NORMAL) f = FXFontDesc.new() f.encoding = FONTENCODING_DEFAULT f.face = "Helvetica" f.flags = 0 f.setwidth = FONTSETWIDTH_WIDE f.size = 100 f.slant = FONTSLANT_REGULAR f.weight = weight return (f) end def create() super() show(PLACEMENT_SCREEN) end end if(__FILE__ == $0) app = FXApp.new("Example", "Example") win = SimpleWindow.new(app) app.create() app.run() end -------------- End Code... I Hope this helps! http://www.fxruby.org/doc/api/classes/Fox/FXFont.html On Thu, Apr 15, 2010 at 12:30 PM, Paul Carvalho <tester.paul at gmail.com>wrote:> I''m not at my development computer right now so I can''t tell you the exact > code I tried, but I can say that, yes, I did try to use a nil/empty string > font face and Ruby choked on it -- didn''t like it. > > I tried "system" as a font face and that *really* didn''t do what I wanted > either! =) > > I entered "arial" and then the one label font changed - I had forgotten > that the default system font is not Arial. So the one label really stands > out now because it''s a totally different font.. which is not what I want. > > I don''t want to hard-code a font that is different from the system font, > especially if the app will run on different platforms and I don''t know what > the default fonts will be. > > I can try some other variations tonight. I''ve already spent over 4 hours > on this and haven''t gotten it to work. Maybe I just needed a break to see > something that I''ve missed. > > I thought it would be something that would have come up by now.. I''ve seen > lots of apps where a label is bolded to indicate a required field. I just > haven''t found any FXRuby examples of this *without* also specifying the font > at the same time. > > Cheers. P. > > > 2010/4/15 Bartosz Dziewo?ski : > > >> Have you tried to use nil/empty string font face and use font style >> hint "System"? Or try any font together with the hint? >> >> I haven''t tried it myself, but according to docs it might work. >> >> > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-- If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/6b827cdc/attachment.html>
sorry, I missed that one line where you said you didn''t want to specify the font.. You could probably just use the code I posted and use self.font.font instead of "Helvetica" ... This would use whatever FXMainWindow is using, which is most likely the OS''s default font... Good Luck! On Thu, Apr 15, 2010 at 1:04 PM, Joey Kinsella < jkinsella at ancillaryservices.com> wrote:> There are definitely better ways of doing this, but here is a basic > example: > > Begin code > ----------------- > > #! /usr/bin/env ruby > > require ''rubygems'' > require ''fox16'' > > include Fox > > class SimpleWindow < FXMainWindow > def initialize(app) > super(app, "My Simple Window", :opts => DECOR_ALL, > :width => 640, :height => 480) > > draw_widgets() > end > > def draw_widgets() > label = FXLabel.new(self, "This is my label that is normal.") > label.font = FXFont.new(getApp(), select_font()) > > label2 = FXLabel.new(self, "This is my label that is bold.") > label2.font = FXFont.new(getApp(), select_font(FONTWEIGHT_BOLD)) > > end > > def select_font(weight = FONTWEIGHT_NORMAL) > f = FXFontDesc.new() > f.encoding = FONTENCODING_DEFAULT > f.face = "Helvetica" > f.flags = 0 > f.setwidth = FONTSETWIDTH_WIDE > f.size = 100 > f.slant = FONTSLANT_REGULAR > f.weight = weight > > return (f) > > end > > def create() > super() > show(PLACEMENT_SCREEN) > end > end > > if(__FILE__ == $0) > app = FXApp.new("Example", "Example") > win = SimpleWindow.new(app) > > app.create() > app.run() > end > > -------------- > End Code... > > I Hope this helps! > http://www.fxruby.org/doc/api/classes/Fox/FXFont.html > > On Thu, Apr 15, 2010 at 12:30 PM, Paul Carvalho <tester.paul at gmail.com>wrote: > >> I''m not at my development computer right now so I can''t tell you the exact >> code I tried, but I can say that, yes, I did try to use a nil/empty string >> font face and Ruby choked on it -- didn''t like it. >> >> I tried "system" as a font face and that *really* didn''t do what I wanted >> either! =) >> >> I entered "arial" and then the one label font changed - I had forgotten >> that the default system font is not Arial. So the one label really stands >> out now because it''s a totally different font.. which is not what I want. >> >> I don''t want to hard-code a font that is different from the system font, >> especially if the app will run on different platforms and I don''t know what >> the default fonts will be. >> >> I can try some other variations tonight. I''ve already spent over 4 hours >> on this and haven''t gotten it to work. Maybe I just needed a break to see >> something that I''ve missed. >> >> I thought it would be something that would have come up by now.. I''ve seen >> lots of apps where a label is bolded to indicate a required field. I just >> haven''t found any FXRuby examples of this *without* also specifying the font >> at the same time. >> >> Cheers. P. >> >> >> 2010/4/15 Bartosz Dziewo?ski : >> >> >>> Have you tried to use nil/empty string font face and use font style >>> hint "System"? Or try any font together with the hint? >>> >>> I haven''t tried it myself, but according to docs it might work. >>> >>> >> _______________________________________________ >> fxruby-users mailing list >> fxruby-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/fxruby-users >> > >-- If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/0d54de1b/attachment.html>