KeyWorksRW / wxUiEditor

RAD tool used to create and maintain wxWidgets UI elements.
Apache License 2.0
66 stars 7 forks source link

Support embedded bitmaps in wxRuby code generation #1098

Closed KeyWorksRW closed 1 year ago

KeyWorksRW commented 1 year ago

Description:

wxRuby3 doesn't have anything equivalent to PyEmbeddedImage which made it easy to embed images into wxPython. We could probably do something similar using base64 encoding:

require 'base64'

my_image_data = <<~BASE64
  SGVsbG8sIHdvcmxkIQ==
BASE64

my_image = Base64.decode64(my_image_data)

For SVG images, we could treat it similar to how we do it in Python -- first use zlib to compress the string, then store it in the file as Base64 and finally using zlib.decompress(Base64.decode64(...))

KeyWorksRW commented 1 year ago

Another possible option would be to create a class, similar to the following:

require 'base64'

class RubyEmbeddedImage
  def initialize(data, isBase64=true)
    @data = data
    @isBase64 = isBase64
  end

  def get_data
    data = @data
    if @isBase64
      data = Base64.decode64(@data)
    end
    data
  end

  def get_image
    stream = StringIO.new(get_data)
    Wx::Image.new(stream)
  end
end

my_image_data = <<~BASE64
  SGVsbG8sIHdvcmxkIQ==
BASE64

my_image = RubyEmbeddedImage(my_image_data).get_image()

I haven't tried any of this, so it would probably need some tweaking, but in theory something like this should work. This would be in the images.rb file we generate so that all the app's images could potentially be in one place.

KeyWorksRW commented 1 year ago

Embedding of bitmaps is now working fine within a form. The Images form still needs this implemented. I'm waiting to find out if the various from_() functions will be implemented in wxRuby3 before adding support for embedded SVG files.

Randalphwa commented 1 year ago

The Image list has been implemented in Ruby. SVG files are also now supported via zip compression/decompression.