I can't align middle a list_box in ruby shoes. I have test a few things, including :right => "50" or :left => "50", but it still not work.
Shoes.app do
stack :width => "100%", :height => "45%" do
a = list_box :items => ["lol","b"], :width => 50, :align => "center"
end
end
I did not find a direct way but you can use this hack
module Shoes::Types
def centr
left=(self.parent.width-self.style[:width])/2
self.move(left,self.top)
end
def middle
top=(self.parent.height-self.style[:height])/2
self.move(self.left,top)
end
end
Shoes.app do
#c=stack :width=>50, :height=>30 do
a=list_box :items => ["lol","b"], :width => 50, :height=>30
end
#c.centr.middle
end
What is done is actually first to extend the functionality of slots so that you can place them in the center or middle of the containing slot. Then you wrap your listbox in a tiny slot, which you center.
Related
I've been fighting with Tkinter in ruby to try and get a proper scrollable frame working.
I've had the most success with this tutorial: https://www.youtube.com/watch?v=VmlgrrXAqb4
I have translated what he does in the video into ruby and it "works", but only kinda. When I run the application I get a window similar to his with all of the buttons, but the scrollbar handle doesn't appear in it's frame and I can scroll past the content of the frame in both directions.
I'm trying to build an application that has a heavy use of scrolling, but I can't get past this. I am posting as a last resort. I've tried most of the examples I can find online, but I keep getting unexpected behavior. It is worth noting that I am on MacOS in case someone tries the code on Windows or Linux and it works for some reason.
require 'tk'
require 'tkextlib/tkimg'
win = TkRoot.new
win.geometry "500x500"
win.resizable false,false
wrapper1 = Tk::Tile::Frame.new win
wrapper2 = Tk::Tile::Frame.new win
mycanvas = TkCanvas.new wrapper1
mycanvas.pack :side => "left", :fill => "both", :expand => "yes"
yscrollbar = TkScrollbar.new :parent => wrapper1, :command => Proc.new {|*args| mycanvas.yview *args}
yscrollbar.pack :side => "left", :fill => "y"
mycanvas.configure(:yscrollcommand => Proc.new {|*args| yscrollbar.set *args })
mycanvas.bind "<Configure>", Proc.new {mycanvas.scrollregion = mycanvas.bbox("all")}
myframe = Tk::Tile::Frame.new mycanvas
TkcWindow.new(mycanvas, 0, 0, :anchor => "nw", :window => myframe)
wrapper1.pack :fill => "both", :expand => "yes", :padx => 10, :pady => 10
wrapper2.pack :fill => "both", :expand => "yes", :padx => 10, :pady => 10
for i in 0..50
button = TkButton.new(myframe)
button.text = "Button " + i.to_s
button.pack
end
Tk.mainloop
I figured out what was wrong.
#The line of code below where the Configure event is bound needs to be:
mycanvas.bind "Configure" #...
#instead of:
mycanvas.bind "<Configure>" #...
I try to retrieve the value of the first column from an item retrieved from a treeview using "item.get("#0")" but I got this error "RuntimeError: Display column #0 cannot be set". This method works for the other columns.
Can anyone help to figure out a solution?
Regards,
Marc
Here is a standalone example code:
require 'tk'
require 'tkextlib/tile'
$root = TkRoot.new
$frame = Tk::Tile::Frame.new($root)
$tree = Tk::Tile::Treeview.new($frame)
$tree['columns'] = ['action_text','action_description']
$tree.column_configure("#0", :width => 100)
$tree.heading_configure("#0", :text => 'la 1er colonne')
$tree.column_configure('action_text', :width => 100, :anchor => 'center')
$tree.heading_configure('action_text', :text => 'Text')
$tree.column_configure('action_description', :width => 100, :anchor => 'w')
$tree.heading_configure('action_description', :text => 'Description')
# Inserted at the root, program chooses id:
$tree.insert('', 'end', :id => 'widgets', :text => 'Widget Tour')
# Same thing, but inserted as first child:
$tree.insert('', 0, :id => 'gallery', :text => 'Applications')
# Treeview chooses the id:
item = $tree.insert('', 'end', :text => 'Tutorial')
# Inserted underneath an existing node:
$tree.insert( 'widgets', 'end', :text => 'Canvas')
$tree.insert( item, 'end', :text => 'Tree')
$tree.insert('', 2, :text => 'tata')
$tree.insert('', 'end', :text => 'envolee', :values => ['le centre', 'la description'])
$frame.grid(:column => 0, :row => 0, :sticky => 'nsew') {padding "3 3 12 12"}
$tree.grid(:column => 0, :row => 0, :sticky => 'nsew')
TkGrid.columnconfigure($root, 0, :weight => 1)
TkGrid.rowconfigure($root, 0, :weight => 1)
TkGrid.columnconfigure($frame, 0, :weight => 1)
TkGrid.rowconfigure($frame, 0, :weight => 1)
def create_action
item = $tree.selection_get[0]
puts item
puts "ID:"
puts item.id
puts "Index:"
puts item.index
puts "action_text:"
puts item.get('action_text')
puts "1:"
puts item.get('#1')
puts $tree.get(item.id, '#0')
puts "0:"
puts item.get("#0")
end
$tree.bind("Double-1") { create_action }
Tk.mainloop
I do not know if I understand exactly what you want to do,
item.text
might be a solution.
Hover element dosen't work. Where is problem? How fix it?
Shoes.app :width => 635, :height => 410 do
background image "http://PATH_TO_IMAGE"
a = stack :width => 360, :height => 200, :margin_left => 250, :margin_top => 200 do
hover do
a.clear { para "Some Text qwe qwe qwerty", :stroke => black }
end
leave do
a.clear { background image "http://PATH_TO_IMAGE" }
end
end
end
I think in principle you cannot use image as the argument for background.
I also am not sure if that is effect you want to achieve but it shows what you did wrong:
Shoes.app :width => 635, :height => 410 do
a = stack :width => 360, :height => 200 do
image "http://PATH_TO_IMAGE"
hover do
a.clear {para "Some Text qwe qwe qwerty", :stroke => black }
end
leave do
a.clear { image "http://PATH_TO_IMAGE" }
end
end
end
I'm trying to layout 6 images per page with prawn in Ruby:
case (idx % 6) # ugly
when 0 : (pdf.start_new_page; pdf.image img, :position => :left, :vposition => :top, :width => 270)
when 1 : pdf.image img, :position => :right, :vposition => :top, :width => 270
when 2 : pdf.image img, :position => :left, :vposition => :center, :width => 270
when 3 : pdf.image img, :position => :right, :vposition => :center, :width => 270
when 4 : pdf.image img, :position => :left, :vposition => :bottom, :width => 270
when 5 : pdf.image img, :position => :right, :vposition => :bottom, :width => 270
end
Not sure what I'm doing wrong, but it prints the first 3 images to the PDF, then creates a new page and prints the last three:
Page 1:
<img> <img>
<blank> <blank>
<blank> <blank>
Page 2:
<blank> <blank>
<blank> <img>
<img> <img>
Any suggestions would help.
Image is going to flow (like text does) when you aren't explicitly positioning items.
Wrap each call in a float() { ... } and that will do the trick.
Alternatively, use prawn/grid for positioning.
The default vertical alignment in a flow slot is apparently to top-align the elements. Here's a sample:
Shoes.app (:title => "Vertical Alignment", :width => 300, :height => 150) do
background "#DFA"
flow :margin => 30 do
title "BIG"
tagline "MEDIUM"
inscription "SMALL"
end
end
How do I get the flow slot to center-align its elements short of calculating a :rise value for each element? I would have expected a vertical-alignment style for flow slots and a horizontal-alignment style for stack slots, but I don't see anything like that. What did I miss?
To my knowledge, there's no style for vertical alignment. There is horizontal alignment which is useful in stacks:
Shoes.app (:title => "Horizontal Alignment", :width => 300, :height => 150) do
background "#DFA"
stack :margin => 30 do
title "BIG", :align => 'center'
tagline "MEDIUM", :align => 'center'
inscription "SMALL", :align => 'center'
end
end
Keep in mind that Shoes is very much still a work in progress, so _why will probably get around to it eventually.