-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local fonts and background local image #295
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Shoes.app do | ||
|
||
stack width:100, height:100 do | ||
background "docs/static/avatar.png" | ||
border blue ,strokewidth: 4 | ||
end | ||
|
||
stack width:100, height:100 do | ||
background red | ||
end | ||
|
||
stack width:100, height:100 do | ||
background "rgba(255,200,0,255)" | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Scarpe.app do | ||
font "fonts/Pacifico.ttf" | ||
para "Hello yayyy" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "base64" | ||
require "uri" | ||
|
||
class Scarpe | ||
module Base64 | ||
def valid_url?(string) | ||
uri = URI.parse(string) | ||
uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) | ||
rescue URI::InvalidURIError, URI::BadURIError | ||
false | ||
end | ||
|
||
def encode_file_to_base64(image_filename) | ||
directory_path = File.dirname(__FILE__, 3) | ||
|
||
image_path = File.join(directory_path, image_filename) | ||
puts "directory_path: #{directory_path}" | ||
|
||
image_data = File.binread(image_path) | ||
|
||
encoded_data = ::Base64.strict_encode64(image_data) | ||
|
||
encoded_data | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class Scarpe | ||
class Font < Scarpe::Widget | ||
display_properties :font | ||
|
||
def initialize(font) | ||
@font = font | ||
super | ||
|
||
create_display_widget | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "scarpe/base64" | ||
|
||
class Scarpe | ||
class WebviewFont < WebviewWidget | ||
include Base64 | ||
attr_accessor :font | ||
|
||
def initialize(properties) | ||
@font = properties[:font] | ||
super | ||
end | ||
|
||
def element | ||
puts @font | ||
HTML.render do |h| | ||
h.link(href: @font, rel: "stylesheet") | ||
h.style do | ||
<<~CSS | ||
@font-face { | ||
font-family: Pacifico; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh. Can we change this so it's not always Pacifico? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah oh we can its just a custom name but like get name from filepath? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds like a good way to do it, yeah. I mean, if we can't customise then we can't, but it seems worth a try. |
||
src: url("data:font/truetype;base64,#{encode_file_to_base64(@font)}") format('truetype'); | ||
} | ||
* { | ||
font-family: Pacifico; | ||
} | ||
CSS | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove this puts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah hm ha sorry abt tht