More layout fixes
This commit is contained in:
parent
d053a7f219
commit
3b41f1248a
@ -1,6 +1,7 @@
|
|||||||
import gtk
|
import gtk
|
||||||
import goocanvas
|
import goocanvas
|
||||||
|
|
||||||
|
from sugar.canvas.CanvasView import CanvasView
|
||||||
from sugar.canvas.CanvasBox import CanvasBox
|
from sugar.canvas.CanvasBox import CanvasBox
|
||||||
from sugar.canvas.IconItem import IconItem
|
from sugar.canvas.IconItem import IconItem
|
||||||
|
|
||||||
@ -12,10 +13,10 @@ class BuddyPopup(gtk.Window):
|
|||||||
self._friend = friend
|
self._friend = friend
|
||||||
self._hover = False
|
self._hover = False
|
||||||
self._popdown_on_leave = False
|
self._popdown_on_leave = False
|
||||||
self._width = 20
|
self._width = 13
|
||||||
self._height = 12
|
self._height = 10
|
||||||
|
|
||||||
canvas = goocanvas.CanvasView()
|
canvas = CanvasView()
|
||||||
self.add(canvas)
|
self.add(canvas)
|
||||||
canvas.show()
|
canvas.show()
|
||||||
|
|
||||||
@ -31,18 +32,18 @@ class BuddyPopup(gtk.Window):
|
|||||||
grid.set_constraints(rect, 0, 0, self._width, self._height)
|
grid.set_constraints(rect, 0, 0, self._width, self._height)
|
||||||
root.add_child(rect)
|
root.add_child(rect)
|
||||||
|
|
||||||
text = goocanvas.Text(text=friend.get_name(), font="Sans bold 14",
|
text = goocanvas.Text(text=friend.get_name(), font="Sans bold 18",
|
||||||
fill_color='black', anchor = gtk.ANCHOR_SW)
|
fill_color='black', anchor=gtk.ANCHOR_SW)
|
||||||
grid.set_constraints(text, 1, 2, self._width, self._height)
|
grid.set_constraints(text, 1, 3, self._width, self._height)
|
||||||
root.add_child(text)
|
root.add_child(text)
|
||||||
|
|
||||||
separator = goocanvas.Path(data='M 15 0 L 185 0', line_width=3,
|
separator = goocanvas.Path(data='M 15 0 L 185 0', line_width=3,
|
||||||
fill_color='black')
|
fill_color='black')
|
||||||
grid.set_constraints(separator, 0, 3)
|
grid.set_constraints(separator, 0, 4)
|
||||||
root.add_child(separator)
|
root.add_child(separator)
|
||||||
|
|
||||||
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
||||||
grid.set_constraints(box, 0, 3)
|
grid.set_constraints(box, 0, 5)
|
||||||
|
|
||||||
icon = IconItem(icon_name='stock-make-friend')
|
icon = IconItem(icon_name='stock-make-friend')
|
||||||
icon.connect('clicked', self._make_friend_clicked_cb)
|
icon.connect('clicked', self._make_friend_clicked_cb)
|
||||||
|
@ -17,7 +17,7 @@ class Frame:
|
|||||||
|
|
||||||
grid = Grid()
|
grid = Grid()
|
||||||
|
|
||||||
bg = goocanvas.Rect(fill_color="#4f4f4f")
|
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
|
||||||
grid.set_constraints(bg, 0, 0, 80, 60)
|
grid.set_constraints(bg, 0, 0, 80, 60)
|
||||||
root.add_child(bg)
|
root.add_child(bg)
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ import gtk
|
|||||||
import goocanvas
|
import goocanvas
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
|
from sugar.canvas.IconItem import IconItem
|
||||||
|
|
||||||
class Grid:
|
class Grid:
|
||||||
COLS = 80.0
|
COLS = 80.0
|
||||||
ROWS = 60.0
|
ROWS = 60.0
|
||||||
@ -27,20 +29,28 @@ class Grid:
|
|||||||
def _layout_item(self, item, x, y, width, height):
|
def _layout_item(self, item, x, y, width, height):
|
||||||
scale = 1200 / Grid.COLS
|
scale = 1200 / Grid.COLS
|
||||||
|
|
||||||
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
|
self._allocate_item_position(item, x * scale, y * scale)
|
||||||
matrix.translate(x * scale, y * scale)
|
|
||||||
item.set_transform(matrix)
|
|
||||||
|
|
||||||
# FIXME This is really hacky
|
|
||||||
if width > 0 and height > 0:
|
if width > 0 and height > 0:
|
||||||
try:
|
self._allocate_item_size(item, width * scale, height * scale)
|
||||||
item.props.width = width * scale
|
|
||||||
item.props.height = height * scale
|
# FIXME We really need layout support in goocanvas
|
||||||
except:
|
def _allocate_item_size(self, item, width, height):
|
||||||
try:
|
if isinstance(item, goocanvas.Rect):
|
||||||
item.props.size = width * scale
|
item.props.width = width - item.props.line_width * 2
|
||||||
except:
|
item.props.height = height - item.props.line_width * 2
|
||||||
pass
|
elif isinstance(item, goocanvas.Text):
|
||||||
|
item.props.width = width
|
||||||
|
elif isinstance(item, IconItem):
|
||||||
|
item.props.size = width
|
||||||
|
|
||||||
|
def _allocate_item_position(self, item, x, y):
|
||||||
|
if isinstance(item, goocanvas.Rect):
|
||||||
|
x = x + item.props.line_width
|
||||||
|
y = y + item.props.line_width
|
||||||
|
|
||||||
|
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
|
||||||
|
matrix.translate(x, y)
|
||||||
|
item.set_transform(matrix)
|
||||||
|
|
||||||
def _layout_canvas(self, canvas, x, y, width, height):
|
def _layout_canvas(self, canvas, x, y, width, height):
|
||||||
scale = 1200 / Grid.COLS
|
scale = 1200 / Grid.COLS
|
||||||
|
Loading…
Reference in New Issue
Block a user