Skip to content

Instantly share code, notes, and snippets.

@skinnyjames
Last active December 26, 2024 15:22
Show Gist options
  • Select an option

  • Save skinnyjames/db06ad79a54fa67fd17ae039a1591cbe to your computer and use it in GitHub Desktop.

Select an option

Save skinnyjames/db06ad79a54fa67fd17ae039a1591cbe to your computer and use it in GitHub Desktop.
cursed
# dependencies
require_relative "../src/hokusai"
require_relative "../src/hokusai/backends/sdl2"
require_relative "../src/hokusai/backends/raylib"
module Dynamic
class Block < Hokusai::Block
template <<~EOF
[template]
empty
EOF
uses(empty: Hokusai::Blocks::Empty)
computed! :script
def on_mounted
klass = eval(script)
raise Hokusai::Error.new("Class #{klass} is not a Hokusai::Block") unless klass.ancestors.include?(Hokusai::Block)
node.meta.set_child(0, klass.mount)
end
end
class App < Hokusai::Block
style <<~EOF
[style]
mainStyle {
background: rgb(46, 46, 46);
}
appText {
content: "Hello World";
size: 40;
color: rgb(222,222,222);
}
EOF
template <<~EOF
[template]
vblock {
...mainStyle
}
text { ...appText }
variable { :script="script" }
EOF
uses(
vblock: Hokusai::Blocks::Vblock,
text: Hokusai::Blocks::Text,
variable: Dynamic::Block,
)
def script
<<~RUBY
require "rest-client"
class TestDynamic < Hokusai::Block
template <<~EOF
[template]
hblock
text { :content="dynamic" size="32" color="222,222,222" }
text { content="welcome" size="50" color="222,222,222" }
EOF
uses(
hblock: Hokusai::Blocks::Hblock,
text: Hokusai::Blocks::Text
)
def dynamic
@response ||= RestClient.get("https://geoffrey.skinnyjames.net/api/v1/us/geocode/2424%20adams%20ave%20columbus%20ohio%2043202").body
end
end
TestDynamic
RUBY
end
end
end
Hokusai::Backends::RaylibBackend.run(Dynamic::App) do |config|
# backend specific configuration
config.width = 600
config.height = 500
config.title = "Dynamic Application"
config.after_load do
# most heavy logic, including text wrapping calculations are implemented in C
font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/OpenSans-Regular.ttf")
Hokusai.fonts.register "opensans", font
Hokusai.fonts.activate "opensans"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment