ashbb / green_shoes

Green Shoes is one of the colorful Shoes written in pure Ruby.
Other
204 stars 37 forks source link

BasicText.text= do not preserve current style #45

Closed glurp closed 13 years ago

glurp commented 13 years ago

Hello Ashbb,

title is explicit :)

I like to define backgroung /foreground color for some param, but when I modify the text, new text is writing in foreground 'black'.

in this maquette https://gist.github.com/1165270 the fields in status can't be colored...

by

ashbb commented 13 years ago

Hi raubarede,

Try out the following.

require 'green_shoes'
Shoes.app do
  msg = para 'hello', stroke: green
  button 'new text' do
    msg.text = 'good bye'
  end
end

Yes, text= do not preserve current color. Sorry, this is a spec (a restriction).

Please set the style again like this:

require 'green_shoes'
Shoes.app do
  msg = para 'hello', stroke: green
  button 'new text' do
    msg.text = fg('good bye', green)
  end
end

ashbb

glurp commented 13 years ago

Thank you very much,

Regis,

2011/8/23 ashbb < reply@reply.github.com>

Hi raubarede,

Try out the following.

require 'green_shoes'
Shoes.app do
 msg = para 'hello', stroke: green
 button 'new text' do
   msg.text = 'good bye'
 end
end

Yes, text= do not preserve current color. Sorry, this is a spec (a restriction).

Please set the style again like this:

require 'green_shoes'
Shoes.app do
 msg = para 'hello', stroke: green
 button 'new text' do
   msg.text = fg('good bye', green)
 end
end

ashbb

Reply to this email directly or view it on GitHub: https://github.com/ashbb/green_shoes/issues/45#issuecomment-1880516


_ . _ |) | / ` | /` | \ |_ > L| .__/

http://regisaubarede.posterous.com/


glurp commented 13 years ago

Is this perturbate the specifications (color can be in string) :

class Shoes
 class App
   [[:bg, :background], [:fg, :foreground]].each do |m, tag|
      define_method m do |*str|
        color = str.pop
        str = str.join
        unless String===color # <<<
            rgb = "#"+(color[0, 3].map{|e| (e*255.0).to_i}.map{|i| sprintf("%#02X", i)[-2,2]}.join)
        else
            rgb=color # <<<
        end
        "<span #{tag}='#{rgb}'>#{str}</span>"
      end
    end
  end
end
ashbb commented 13 years ago

Hi raubarede,

Yes, I think your patch works. But there may be a rare case to show slightly different color or no color. After add your patch, try out the following.

require 'green_shoes'
Shoes.app do
 title fg('hello', green)
 title fg('hello', eval('green'))
 title fg('hello', 'green')
end

On my Windows7, last title is shown with a slightly different color.

require 'green_shoes'
Shoes.app do
 title fg('hello', 'indigo')
end

On my Windows7, have an error: should be a color specification, not 'indigo' (GLib::Error)

ashbb

glurp commented 13 years ago

require 'green_shoes' Shoes.app do title 'hello', stroke: green rescue para "nok 1" title 'hello', stroke: "green" rescue para "nok 2" title fg('hello', green) rescue para "nok 1" title fg('hello', eval('green')) rescue para "nok 3" title fg('hello', "green") rescue para "nok 4" title fg('hello', "#00DD00") rescue para "nok 5" end

I get nok 2 and nok 4; other title are ok. seem logic ?

2011/8/24 ashbb < reply@reply.github.com>

Hi raubarede,

Yes, I think your patch works. But there may be a rare case to show slightly different color or no color. After add your patch, try out the following.

require 'green_shoes'
Shoes.app do
 title fg('hello', green)
 title fg('hello', eval('green'))
 title fg('hello', 'green')
end

On my Windows7, last title is shown with a slightly different color.

require 'green_shoes'
Shoes.app do
 title fg('hello', 'indigo')
end

On my Windows7, have an error: should be a color specification, not 'indigo' (GLib::Error)

ashbb

Reply to this email directly or view it on GitHub: https://github.com/ashbb/green_shoes/issues/45#issuecomment-1888814


_ . _ |) | / ` | /` | \ |_ > L| .__/

http://regisaubarede.posterous.com/


ashbb commented 13 years ago

Umm,... did you run the above snippet after adding your patch? I got this screenshot. All 5 titles works. But colors are slightly different.

glurp commented 13 years ago

http://regisaubarede.posterous.com/pages/color-gs

here the screenshot with this code in green-shoes :

[[:bg, :background], [:fg, :foreground]].each do |m, tag|
  define_method m do |*str|
    color = str.pop
    str = str.join
    unless String===color
        rgb = color[0, 3].map{|e| (e*255.0).to_i}.map{|i|

sprintf("%#02X", i)[-2,2]}.join else rgb=color.gsub('#','') end "<span #{tag}='##{rgb}'>#{str}" end end

2011/8/24 ashbb < reply@reply.github.com>

Umm,... did you run the above snippet after adding your patch? I got this screenshot. All 5 titles works. But colors are slightly different.

Reply to this email directly or view it on GitHub: https://github.com/ashbb/green_shoes/issues/45#issuecomment-1890646


_ . _ |) | / ` | /` | \ |_ > L| .__/

http://regisaubarede.posterous.com/


ashbb commented 13 years ago

Hi Regis,

I got it. You have two paches. :)

At first, you showed me this one:

[[:bg, :background], [:fg, :foreground]].each do |m, tag|
 define_method m do |*str|
   color = str.pop
   str = str.join
   unless String===color
     rgb = '#' + color[0, 3].map{|e| (e*255.0).to_i}.map{|i| sprintf("%#02X", i)[-2,2]}.join
   else
     rgb=color
   end
   "#{str}"
 end
end

But now you are using this slightly different one:

[[:bg, :background], [:fg, :foreground]].each do |m, tag|
 define_method m do |*str|
   color = str.pop
   str = str.join
   unless String===color
     rgb = color[0, 3].map{|e| (e*255.0).to_i}.map{|i| sprintf("%#02X", i)[-2,2]}.join
   else
    rgb=color.gsub('#','')
   end
   "#{str}"
 end
end

So, if you use first patch, you will get the same screenshot that I got.

ashbb