Skip to content

Commit

Permalink
Merge pull request #421 from scarpe-team/schwad_oval_nation
Browse files Browse the repository at this point in the history
let us just all have one big oval party but only invite our best friends and not post on social media about it so no one ever knows it happened
  • Loading branch information
Schwad authored Dec 4, 2023
2 parents 3074656 + bbac10d commit 2c81650
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AllCops:
Exclude:
- 'bin/**/*'
- 'exe/**/*'
- 'examples/**/*'
# - 'examples/**/*' Since I'm only doing this locally.
- 'docs/**/*'

Layout/LineLength:
Expand All @@ -19,6 +19,12 @@ Style/RedundantHeredocDelimiterQuotes:
Style/MissingRespondToMissing:
Enabled: false

Metrics/ParameterLists:
Enabled: false

Style/ParallelAssignment:
Enabled: false



Style/MethodCallWithArgsParentheses:
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ GEM
minitest (>= 5.0)
ruby-progressbar
multi_json (1.15.0)
nokogiri (1.15.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-linux)
Expand Down Expand Up @@ -82,6 +84,7 @@ GEM
rubocop-shopify (2.12.0)
rubocop (~> 1.44)
ruby-progressbar (1.11.0)
sqlite3 (1.6.3-arm64-darwin)
sqlite3 (1.6.3-x86_64-darwin)
sqlite3 (1.6.3-x86_64-linux)
unicode-display_width (2.4.2)
Expand All @@ -94,7 +97,10 @@ GEM
webrick (~> 1.7.0)

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-19
x86_64-darwin-20
x86_64-darwin-22
x86_64-linux

Expand Down
3 changes: 3 additions & 0 deletions examples/oval-with-kwargs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Shoes.app do
oval top: 20, left: 20, radius: 160, center: true, fill: fuchsia
end
26 changes: 26 additions & 0 deletions examples/oval.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

#TODO: Support color methods as argument
#TODO: Allow strokewidth to go wider than container?
#TODO: Support strokewidth draw context

Shoes.app(
title: "Schwad's unbelievable desktop application that renders an oval",
height: 700,
) do
flow do
para "Positional arguments:"
oval 30, 30, 80, 200, center: true
end
flow do
para "As a circle"
stroke "blue"
fill "pink"
oval 30, 30, 80, center: true
end
flow do
para "Keyword arguments:"
fill "green"
oval top: 20, left: 20, height: 160, width: 90, center: true, stroke: "red", strokewidth: 4
end
end
4 changes: 1 addition & 3 deletions examples/shapes/star.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Shoes.app do
star 230, 100, 6, 50, 25

end

end
1 change: 1 addition & 0 deletions lacci/lib/shoes/drawables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require "shoes/drawables/rect"
require "shoes/drawables/shape"
require "shoes/drawables/star"
require "shoes/drawables/oval"
require "shoes/drawables/arrow"

require "shoes/drawables/button"
Expand Down
40 changes: 40 additions & 0 deletions lacci/lib/shoes/drawables/oval.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

class Shoes
# Docs: https://github.com/scarpe-team/scarpe/blob/main/docs/static/manual.md#ovalleft-top-radius--shoesshape
class Oval < Shoes::Drawable
shoes_styles :height, :center, :draw_context, :stroke

shoes_style(:left) { |val| convert_to_integer(val, "left") }
shoes_style(:top) { |val| convert_to_integer(val, "top") }
shoes_style(:radius) { |val| convert_to_integer(val, "radius") }
shoes_style(:height) { |val| convert_to_integer(val, "height") }
shoes_style(:width) { |val| convert_to_integer(val, "width") }
shoes_style(:strokewidth) { |val| convert_to_integer(val, "strokewidth") }

def initialize(left = nil, top = nil, radius = nil, height = nil, **options)
super
self.left, self.top, self.radius, self.height =
left || options[:left],
top || options[:top],
radius || options[:radius] || options[:width] / 2, # The radius positional arg change forces us to do this
height || options[:height]

@draw_context = Shoes::App.instance.current_draw_context

create_display_drawable
end

def self.convert_to_integer(value, attribute_name)
begin
value = Integer(value)
raise InvalidAttributeValueError, "Negative num '#{value}' not allowed for attribute '#{attribute_name}'" if value < 0

value
rescue ArgumentError
error_message = "Invalid value '#{value}' provided for attribute '#{attribute_name}'. The value should be a number."
raise InvalidAttributeValueError, error_message
end
end
end
end
1 change: 1 addition & 0 deletions lib/scarpe/wv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Scarpe::Webview::Drawable < Shoes::Linkable
require_relative "wv/drawable"

require_relative "wv/star"
require_relative "wv/oval"
require_relative "wv/radio"

require_relative "wv/arc"
Expand Down
13 changes: 13 additions & 0 deletions lib/scarpe/wv/oval.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Scarpe::Webview
class Oval < Drawable
def initialize(properties)
super(properties)
end

def element(&block)
render("oval", &block)
end
end
end
33 changes: 33 additions & 0 deletions scarpe-components/lib/scarpe/components/calzini/art_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ def star_element(props, &block)
end
end

def oval_element(props, &block)
dc = props["draw_context"] || {}
fill = props["fill"] || (dc["fill"] == "" ? nil : dc["fill"]) || "black"
stroke = props["stroke"] || (dc["stroke"] == "" ? nil : dc["stroke"]) || "black"
strokewidth = props["strokewidth"] || dc["strokewidth"] || "2"
fill = "black" if !fill || fill == ""
radius = props["radius"]
width = radius * 2
height = props["height"] || radius * 2 # If there's a height, it's an oval, if not, circle
center = props["center"] || false
HTML.render do |h|
h.div(id: html_id, style: oval_style(props)) do
h.svg(width: width, height: height, style: "fill:#{fill};") do
h.ellipse(
cx: center ? radius : 0,
cy: center ? height / 2 : 0,
rx: radius,
ry: height ? height / 2 : radius,
style: "stroke:#{stroke};stroke-width:#{strokewidth};",
)
end
block.call(h) if block_given?
end
end
end

private

def arc_style(props)
Expand Down Expand Up @@ -121,6 +147,13 @@ def star_style(props)
}).compact
end

def oval_style(props)
drawable_style(props).merge({
width: dimensions_length(props["width"]),
height: dimensions_length(props["height"]),
})
end

def star_points(props)
angle = 2 * Math::PI / props["points"]
coordinates = []
Expand Down
2 changes: 1 addition & 1 deletion scarpe-components/lib/scarpe/components/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Scarpe::Components::HTML
:h4,
:h5,
].freeze
VOID_TAGS = [:input, :img, :polygon, :source, :link, :path, :rect].freeze
VOID_TAGS = [:input, :img, :polygon, :source, :link, :path, :rect, :ellipse].freeze

TAGS = (CONTENT_TAGS + VOID_TAGS).freeze

Expand Down

0 comments on commit 2c81650

Please sign in to comment.