danhealy / dragonruby-zif Goto Github PK
View Code? Open in Web Editor NEWZif: A Drop-in Framework for DragonRuby GTK
License: MIT License
Zif: A Drop-in Framework for DragonRuby GTK
License: MIT License
words = @full_text.gsub('\\', '').gsub("\n", '\\n').split(' ')
but then a couple lines later
lines = cur_word.split("\n")
so the "\n" is remove in the gsub above and the spit then doesn't find any.
here's a quick hack that might be wrong, but seems to work slightly better in my code, in the @wrapping_label example, something still seems off, but not sure why, but wanted to get this to you for a more correct fix. Probably there's a better way to inject newline label that's needed.
diff --git a/app/lib/zif/ui/label.rb b/app/lib/zif/ui/label.rb
index ed7bcca..a3cfff4 100644
--- a/app/lib/zif/ui/label.rb
+++ b/app/lib/zif/ui/label.rb
@@ -173,9 +173,20 @@ module Zif
cur_word = words.shift
# If this word contains newlines, split into new words and add the extras back to 'words'
- lines = cur_word.split("\n")
- words.unshift(*lines[1..-1]) if lines.length.positive?
- cur_word = lines[0]
+ lines = cur_word.split('\\n')
+ if lines.length.positive?
+ words.unshift(*lines[1..-1])
+ cur_word = lines[0]
+ else
+ cur_rect = cur_label.rect
+ old_y = cur_label.y
+ cur_label = dup
+ cur_label.text = ''
+ cur_label.recalculate_minimums
+ cur_label.y = old_y - cur_rect[1]
+ new_labels << cur_label
+ next
+ end
existing_text = cur_label.text
cur_label.text = existing_text + (existing_text == '' ? '' : ' ') + cur_word
diff --git a/app/scenes/ui_sample.rb b/app/scenes/ui_sample.rb
index 03995fb..18dbaf9 100644
--- a/app/scenes/ui_sample.rb
+++ b/app/scenes/ui_sample.rb
@@ -57,7 +57,7 @@ module ExampleApp
@cutout.y = 60 + 25
@wrapping_label = FutureLabel.new(
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
+ "Lorem ipsum\ndolor sit\n\namet, consectetur adipiscing elit, \n\nsed do eiusmod \n\n tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
size: -2,
alignment: :left
).tap do |l|
It should be fairly easy to modify Zif::Camera
to implement a parallax effect (e.g. flappy dragon)
This might be a good first project for a new contributor:
ParallaxLayer
class based on SimpleLayer
ActiveLayer
World
scene which initializes some ParallaxLayer
smain.rb
and then modifying the @next_scene
attributes on the existing example scenes.-> Zif.roll(dice: 1, sides: 1)
=> 3
That was unexpected until I looked up the def and then it made sense.
from zif.rb
def self.roll(dice: 4, sides: 16, modifier: 2)
Might be better to default the modifier to zero.
Yes, I could also use the roll_raw call instead, but invoking the rule of least surprise.
The main reason ComplexSprite used a RenderTarget is to treat the collection of sprites as a single entity. This is now possible with #draw_override
Akzidenz-Grotesk Today at 6:21 PM
Odd issue. Clicking on the bottom right of the DR window activates Simulate Lag.danhealy Today at 6:24 PM
On which scene?Akzidenz-Grotesk Today at 6:24 PM
UI
Right in the corner where you would go to resize
I guess only some actions are supported by the webhook, creating issues should be one. Will delete this shortly
The UISample
scene is recreating UI elements from scratch every tick, instead of resizing what has already been created. This is not very performant, so this sort of resizing isn't going to work well in an actual game. It would be nice if it was supported and it might be a good refactoring project.
Zif is doing very little interactively with DR so I am pretty sure I could get away with rspec tests and some minimal mocking. But it leaves it open for bugs that only occur in DR flavor ruby
On the other handassert.true!
is a little underwhelming
ComplexSprite
was written before RenderTarget
, and I suspect that these classes are doing the same job. We should attempt to refactor the UI elements to use RenderTarget
instead.
Due to expecting to call draw_override
, there is an incompatibility when trying to add a Zif::CompoundSprite
to the @sprites
array on another Zif::CompoundSprite
.
An example to illustrate this would be attempting to refactor the ExampleApp::FormField
class to use a CompoundSprite
for the background, like switching it to ExampleApp::MetalCutout
instead of the simple white rectangle.
This class should probably be refactored a bit to handle this situation. The two major complications are:
draw_override
, and should reach into its descendants to draw themx/y
and zoomed relative to its parentsource_w/h
.Latest DRGTK supplies fn.send_each
which may give some perf improvement in ComplexSprite
's draw_override
To demonstrate the benefit of using the framework, apples to apples comparisons of Zif code versus the samples provided in the DR documentation should be written. These are easy first contribution tasks!
Each sample should be contained within a Scene where possible. A Scene to select samples would be great.
ComplexSprite
should be deprecated in favor of CompoundSprite
, but an effort needs to be made to move UI elements away from it first
This works:
self.player_sprite = Zif::Sprite.new.tap do |s|
s.x = player.x
s.y = player.y
s.w = player.size
s.h = player.size
s.path = 'sprites/spritesheet.png'
s.source_h = 8
s.source_w = 8
s.source_x = 0 * 8
s.source_y = 0 * 8
end
this does not:
player_sprite.new_tiled_animation(
named: :walk,
width: 8,
height:8,
path: 'sprites/spritesheet.png',
durations: durations,
)
Recommend going with the principle of least surprise. Some devs will not use the normal DR conventions. Also recommend if a path is not found throwing an exception stating the problem, but I'm not sure if that's common with DragonRuby itself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.