Sha256: 2f767a0d93a79b0ba66d76b8833efc69b0d53bf84b7a39e5f269228a840563d8

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

class Shoes
  class Link < Span
    include Common::Style
    include Common::Fill
    include Common::Stroke
    include Common::Hover

    attr_reader :app, :gui, :blk
    style_with :common_styles, :text_block_styles
    STYLES = { underline: true, stroke: ::Shoes::COLORS[:blue], fill: nil }

    def initialize(my_app, texts, styles = {}, blk = nil)
      @app = my_app
      style_init styles
      @gui = Shoes.backend_for self

      setup_click blk
      super texts, @style
    end

    # Force hovering evaluation up in parent where we have actual dimensions
    def eval_in_parent?
      true
    end

    # Doesn't use Common::Clickable because of URL flavor option clicks
    def setup_click(blk)
      if blk.nil?
        blk = if @style[:click].respond_to? :call
                @style[:click]
              else
                # Slightly awkward, but we need App, not InternalApp, to call visit
                proc { app.app.visit @style[:click] }
              end
      end

      click(&blk)
    end

    def click(&blk)
      @gui.click blk if blk
      @blk = blk
    end

    def pass_coordinates?
      false
    end

    def in_bounds?(x, y)
      @gui.in_bounds?(x, y)
    end

    def remove
      @gui.remove
    end

    def hidden?
      text_block_guard && @text_block.hidden?
    end

    def visible?
      text_block_guard && @text_block.visible?
    end

    private

    def text_block_guard
      if @text_block
        true
      else
        @app.warn 'Stray link without TextBlock detected! Links have to be part of a text block like a para or title'
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-core-4.0.0.pre6 lib/shoes/link.rb