Class: Clogs::Background

Inherits:
SlotDecoration show all
Defined in:
lib/clogs/drawables/shapes.rb

Instance Attribute Summary

Attributes inherited from Drawable

#abs_x, #abs_y, #children, #height, #parent, #shoes_linkable_id, #styles, #width, #x, #y

Instance Method Summary collapse

Methods inherited from SlotDecoration

#measure, #measure_for_slot

Methods inherited from Drawable

#add_child, #app, #clickable?, #contains?, #destroy_self, #draw, #each_peer, #focus_gained, #focus_lost, #focusable?, for_shoes_class, #hidden?, #initialize, #margin, #measure, #needs_layout!, #notify, #on_click, #on_key, #on_mouse_move, #on_release, #paint, #positioned?, #properties_changed, #redraw!, #remove_child, #requested_height, #requested_width, #set_parent, #style

Constructor Details

This class inherits a constructor from Clogs::Drawable

Instance Method Details

#background_paint(x, y, w, h) ⇒ Object

Shoes lets a background be a colour, or a gradient written as background red..blue.



270
271
272
273
274
275
276
277
278
279
280
# File 'lib/clogs/drawables/shapes.rb', line 270

def background_paint(x, y, w, h)
  fill = style(:fill) || style(:color)
  if fill.is_a?(Range) || (fill.is_a?(Array) && fill.length == 2 && fill.first.is_a?(Array))
    from, to = fill.is_a?(Range) ? [fill.first, fill.last] : fill
    UI.gradient_brush(UI::BRUSH_LINEAR_GRADIENT, [x, y], [x, y + h],
      [[0.0, Style.color(from)], [1.0, Style.color(to)]])
  else
    _ = w
    Style.color(fill, nil)
  end
end

#paint_for_slot(painter, x, y, w, h) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/clogs/drawables/shapes.rb', line 252

def paint_for_slot(painter, x, y, w, h)
  @abs_x = x
  @abs_y = y
  @width = w
  @height = h
  paint = background_paint(x, y, w, h)
  return unless paint

  curve = style(:curve).to_i
  if curve.positive?
    painter.draw(fill: paint) { |p| Clogs.rounded_rect(p, x, y, w, h, curve) }
  else
    painter.fill_rect(x, y, w, h, paint)
  end
end