Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Using Squib to generate cards.
My csv layout is pretty simple. One of the fields could be empty - "", and depending on that field I have to do call various functions. How do I properly achieve that?
Been trying options like data['empty_field'].empty? and that would give me something weird - that would always think it's not empty. I assume that way I get array of 'empty_field' objects and that, of course, isn't empty. But how do I get object that Squib is currently iterating on?
I've achieve what I wanted. But I consider it being dirty hack, rather than solution.
I had to edit my C# tool to emit empty string of power field where type3 field would be empty. This way I get rid of if/else in Ruby code and it works as intended.
However issue still remains, can't wrap my head around Ruby
Attaching here my latest attempt
pr = dataNor['type3'].map do |a|
a == 'data/ui/type3/placeholder.png' ? true : false
end
if pr == true
text str: dataNor['power'], x: '5.5mm', y: '6.5mm', font_size: 25, color: :white, align: :center, valign: :middle, width: '10mm', height: '10mm', font: 'Warnock Pro SmBd Caption'
else
png file: dataNor['type3']
end
By printing pr I know that check is working, resulting in false only where type3 is defined, however if/else would never call if body, and only calls else body where it should
Update:
The issue seems to have been fixed by this construction:
dataNor['type3'].map do |a|
if a == 'data/ui/type3/placeholder.png'
text str: dataNor['power'], x: '5.5mm', y: '6.5mm', font_size: 25, color: clr, align: :center, valign: :middle, width: '10mm', height: '10mm', font: 'Warnock Pro SmBd Caption'
else
png file: dataNor['type3']
end
end
Related
I have a text object in ruby 2D showing score. How do I update the text?
I have this so far
update do
text = Text.new("Score: #{#score}")
end
Instead of replacing it, it is creating a new text object on top of it. How could you replace it instead of adding it on?
Based on docs it seems like you need to instantiate the Text object outside of the update loop. This will draw it to the screen "forever" until you call the remove method.
In your current code you are just instantiating a new object every time, and Ruby 2D is secretly keeping it around even though you don't have it assigned to a variable.
Unlike some other 2D libraries like Gosu, Ruby 2D does not stop drawing something until you explicitly tell it to.
Try
#text = Text.new("Score: #{#score}")
update do
...
#text.remove # At a time you want to stop displaying that text.
...
end
Adding and removing objects in Ruby 2D
here a simple example how to use the Text class in ruby2d
require 'ruby2d'
sector = 3
txt = Text.new(
sector.to_s,
x: 10, y: 10,
size: 20,
color: 'white',
z: 10
)
on :key_down do |event|
case event.key
when 'a'
sector += 1
txt.text = sector.to_s
when 's'
sector -= 1
txt.text = sector.to_s
end
end
show
I have print.min.js referenced in my angularjs project. I have it printing successfully (very simple!) for most of my needs. I have run into a case where the browser print dialog does not appear when a user presses my 'Print' button. The issue seems to be related to file size. I don't know the size threshold yet, but it seems after a few pages in length, the process hangs in print.min.js somewhere. Smaller files (2 - 3 pages or so) print without issue. Any thoughts?
Thanks!
Joe
By default, Print.js will process the computed styles for each html element. When printing large and / or complex html, this process may take a while. Specially on slower machines.
To prevent this, the library has a parameter scanStyles that can be set to false.
However, for this to work properly, you may want to style your html with css classes instead of inline style. Since the library isn't scanning the computed styles, it needs to receive the css you want to use when printing.
For example, when printing an element of id myElement on a page with two attached stylesheets, myStylesheet.css and vendor.css:
printJS(
{
printable: 'myElement',
type: 'html',
scanStyles: false,
css: ['myStyleSheet', 'vendor.css']
}
)
This supports css print media query as well.
You can also pass custom inline style if necessary:
printJS(
{
printable: 'myElement',
type: 'html',
scanStyles: false,
css: ['myStyleSheet', 'vendor.css'],
style: 'h1 { color: blue; }, someClass { font-size: 1rem; }'
}
)
http://printjs.crabbly.com/#configuration
I don't know if anybody else has met this problem. I updated my Xcode to 8.2.1 today. When I tried to place several buttons on a scrollView, I found a type inference error. The core code is shown below:
for i in 0 ..< 6 {
let titleButton = UIButton(frame: CGRect(x: CGFloat(i) * titleWidth, y: 0, width: titleWidth, height: titleHeight))
sv.addSubview(titleButton)
}
The code had no problem to place 6 buttons on the scrollView(sv), but when I tried to set a title for each button Using call:setTitle(_ title: String?, for state: UIControlState) under the initialization of the button, Xcode did not show method completion suggest. I found the reason is 'titleButton' is inferred as error type by Xcode.
Then I tried:
for i in 0 ..< 6 {
let frame = CGRect(x: CGFloat(i) * titleWidth, y: 0, width: titleWidth, height: titleHeight)
let titleButton = UIButton(frame: frame)
sv.addSubview(titleButton)
}
And found 'frame' is inferred as error type, so the type inference failure of 'titleButton' seems from the frame. Finally I found that the variable 'i' from the beginning of this for statement is inferred as error type, that is the origin.
I didn't find similar problem in past Xcode versions. If I really need to use 'i' in my logic among for-loop, is there someone who has an idea to solve the inference error?
To fix this, I have to indicate the type myself as follow:
let titleButton : UIButton = UIButton(frame: frame)
Then under this, the method completion suggestion works fine. Hope Apple can fix the type inference error quickly...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Im making a Single View Application in Swift and I want to create a button that appears on the screen once you get a certain score. How can I do this?
Also, if possible, I want the button to disappear after you click it.
The solution by which i solved it is timer ...
var score : Int = 0
override func viewDidLoad() {
super.viewDidLoad()
btnTest.hidden = true
_ = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector:Selector("printer"), userInfo: nil, repeats: true)
}
func printer() {
score++
if score == 10 {
btnTest.hidden = false
}
}
you can set your updation on score variable.
there is also some other ways to do it
hope you found your solution
Thank you.
Welcome to SO. This site isn't a good fit for "teach me the basics of programming" type questions like this.
I'll give you something to start from though. Created a score property in your view controller. Implement a didSet method on your score property. Put the logic to show your button in your didSet method.
Create a button and in your code hide it in viewDidLoad then reveal it whenever your score reaches the amount you wish. But it is correct that you should be providing code and not asking just how to do something. Stack overflow is for debugging errors not asking how code should be written.
I am having problems getting the clipboard contents from within an app, using ruby shoes.
I have tried the solution Shoes problems: clipboard and scroll bar, which does not work, as well as several other self-made solutions. According to http://shoesrb.com/manual/App.html, these attempts should work. My current attempt is:
def someFunction
#theapp = Shoes.app(title: "AppName", width: 400) {
#clip = edit_box width: 400, height: 400, text: app.clipboard do
app.clipboard = #clip.text
end
}
end
As well as referencing app.clipboard, I have attempted Shoes.clipboard, Shoes.app.clipboard, self.clipboard, and #theapp.clipboard, all of which have failed. Some of them have even caused a blank window to appear without any elements in it. How can I fix this strange issue?
Try capturing the content of the edit_box in a block parameter:
Shoes.app do
edit_box do |clip|
app.clipboard = clip.text
end
end
Your question helped us to fix a bug in the upcoming release of Shoes 4. Thanks :)