Attachments you submit will be routed for moderation. If you have an account, please
log in first.
Ticket #2235: 0001-updated-Ring-view-layout-details.patch
|
File 0001-updated-Ring-view-layout-details.patch, 7.8 KB
(added by walter, 3 years ago)
|
|
first, apply layout changes to existing Ring
|
-
From 38a15ede4bcdb58e249771b15baa5a84672a2cd1 Mon Sep 17 00:00:00 2001
From: Walter Bender <walter@sugarlabs.org>
Date: Wed, 25 Aug 2010 09:39:51 -0400
Subject: [PATCH 1/2] updated Ring view layout details
---
src/jarabe/desktop/favoriteslayout.py | 99 ++++++++++-----------------------
1 files changed, 30 insertions(+), 69 deletions(-)
diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py
index 7b847ac..160ce0e 100644
|
a
|
b
|
|
| 33 | 33 | |
| 34 | 34 | _CELL_SIZE = 4 |
| 35 | 35 | _BASE_SCALE = 1000 |
| 36 | | _INTERMEDIATE_B = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2 |
| 37 | | _INTERMEDIATE_A = (style.STANDARD_ICON_SIZE + _INTERMEDIATE_B) / 2 |
| 38 | | _INTERMEDIATE_C = (_INTERMEDIATE_B + style.SMALL_ICON_SIZE) / 2 |
| 39 | | _ICON_SIZES = [style.MEDIUM_ICON_SIZE, style.STANDARD_ICON_SIZE, |
| 40 | | _INTERMEDIATE_A, _INTERMEDIATE_B, _INTERMEDIATE_C, |
| 41 | | style.SMALL_ICON_SIZE] |
| 42 | | |
| 43 | 36 | |
| 44 | 37 | class FavoritesLayout(gobject.GObject, hippo.CanvasLayout): |
| 45 | 38 | """Base class of the different layout types.""" |
| … |
… |
|
| 189 | 182 | def allow_dnd(self): |
| 190 | 183 | return True |
| 191 | 184 | |
| | 185 | |
| 192 | 186 | _MINIMUM_RADIUS = style.XLARGE_ICON_SIZE / 2 + style.DEFAULT_SPACING + \ |
| 193 | 187 | style.STANDARD_ICON_SIZE * 2 |
| 194 | 188 | _MAXIMUM_RADIUS = (gtk.gdk.screen_height() - style.GRID_CELL_SIZE) / 2 - \ |
| 195 | 189 | style.STANDARD_ICON_SIZE - style.DEFAULT_SPACING |
| 196 | | _ICON_SPACING_FACTORS = [1.5, 1.4, 1.3, 1.2, 1.1, 1.0] |
| 197 | | _SPIRAL_SPACING_FACTORS = [1.5, 1.5, 1.5, 1.4, 1.3, 1.2] |
| 198 | | _MIMIMUM_RADIUS_ENCROACHMENT = 0.75 |
| 199 | | _INITIAL_ANGLE = math.pi |
| | 190 | _INTERMEDIATE_C = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2 |
| | 191 | _INTERMEDIATE_A = (style.STANDARD_ICON_SIZE * 2 + _INTERMEDIATE_C) / 3 |
| | 192 | _INTERMEDIATE_E = (_INTERMEDIATE_C + style.SMALL_ICON_SIZE * 2) / 3 |
| | 193 | _INTERMEDIATE_B = (_INTERMEDIATE_A + _INTERMEDIATE_C) / 2 |
| | 194 | _INTERMEDIATE_D = (_INTERMEDIATE_C + _INTERMEDIATE_E) / 2 |
| | 195 | _ICON_SIZES = [style.MEDIUM_ICON_SIZE, style.STANDARD_ICON_SIZE, |
| | 196 | _INTERMEDIATE_A, _INTERMEDIATE_B, _INTERMEDIATE_C, |
| | 197 | _INTERMEDIATE_D, _INTERMEDIATE_E, style.SMALL_ICON_SIZE] |
| | 198 | _ICON_SPACING_FACTORS = [1.5, 1.4, 1.3, 1.2, 1.15, 1.1, 1.05, 1.0] |
| 200 | 199 | |
| 201 | 200 | |
| 202 | 201 | class RingLayout(FavoritesLayout): |
| 203 | | """Lay out icons in a ring or spiral around the XO man.""" |
| | 202 | """Lay out icons in a ring around the XO man.""" |
| 204 | 203 | |
| 205 | 204 | __gtype_name__ = 'RingLayout' |
| 206 | 205 | icon_name = 'view-radial' |
| … |
… |
|
| 214 | 213 | def __init__(self): |
| 215 | 214 | FavoritesLayout.__init__(self) |
| 216 | 215 | self._locked_children = {} |
| 217 | | self._spiral_mode = False |
| 218 | 216 | |
| 219 | 217 | def append(self, icon, locked=False): |
| 220 | 218 | FavoritesLayout.append(self, icon, locked) |
| … |
… |
|
| 235 | 233 | self._locked_children[child] = (x, y) |
| 236 | 234 | |
| 237 | 235 | def _calculate_radius_and_icon_size(self, children_count): |
| 238 | | """ Adjust the ring or spiral radius and icon size as needed. """ |
| 239 | | self._spiral_mode = False |
| | 236 | """ Adjust the ring radius and icon size as needed. """ |
| | 237 | # Begin by increasing the radius. |
| 240 | 238 | distance = style.MEDIUM_ICON_SIZE + style.DEFAULT_SPACING * \ |
| 241 | 239 | _ICON_SPACING_FACTORS[_ICON_SIZES.index(style.MEDIUM_ICON_SIZE)] |
| 242 | 240 | radius = max(children_count * distance / (2 * math.pi), _MINIMUM_RADIUS) |
| 243 | 241 | if radius < _MAXIMUM_RADIUS: |
| 244 | 242 | return radius, style.MEDIUM_ICON_SIZE |
| 245 | 243 | |
| 246 | | distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING * \ |
| 247 | | _ICON_SPACING_FACTORS[_ICON_SIZES.index(style.STANDARD_ICON_SIZE)] |
| 248 | | radius = max(children_count * distance / (2 * math.pi), _MINIMUM_RADIUS) |
| 249 | | if radius < _MAXIMUM_RADIUS: |
| 250 | | return radius, style.STANDARD_ICON_SIZE |
| 251 | | |
| 252 | | self._spiral_mode = True |
| 253 | | icon_size = style.STANDARD_ICON_SIZE |
| 254 | | angle, radius = self._calculate_angle_and_radius(children_count, |
| 255 | | icon_size) |
| 256 | | while radius > _MAXIMUM_RADIUS: |
| 257 | | i = _ICON_SIZES.index(icon_size) |
| 258 | | if i < len(_ICON_SIZES) - 1: |
| 259 | | icon_size = _ICON_SIZES[i + 1] |
| 260 | | angle, radius = self._calculate_angle_and_radius( |
| 261 | | children_count, icon_size) |
| 262 | | else: |
| 263 | | break |
| | 244 | # Continue by shrinking the icon size to STANDARD_ICON_SIZE. |
| | 245 | radius = _MAXIMUM_RADIUS |
| | 246 | distance = radius * (2 * math.pi) / children_count |
| | 247 | icon_size = int(distance - style.DEFAULT_SPACING * \ |
| | 248 | _ICON_SPACING_FACTORS[_ICON_SIZES.index(style.STANDARD_ICON_SIZE)]) |
| | 249 | if icon_size >= style.STANDARD_ICON_SIZE: |
| | 250 | return radius, icon_size |
| | 251 | |
| | 252 | # Continue by shrinking the icon size to SMALL_ICON_SIZE. |
| | 253 | icon_size = max(int(distance - style.DEFAULT_SPACING * \ |
| | 254 | _ICON_SPACING_FACTORS[_ICON_SIZES.index( |
| | 255 | style.SMALL_ICON_SIZE)]), style.SMALL_ICON_SIZE) |
| 264 | 256 | return radius, icon_size |
| 265 | 257 | |
| 266 | 258 | def _calculate_position(self, radius, icon_size, icon_index, children_count, |
| 267 | 259 | sin=math.sin, cos=math.cos): |
| 268 | | """ Calculate an icon position on a circle or a spiral. """ |
| | 260 | """ Calculate an icon position on a circle. """ |
| 269 | 261 | width, height = self.box.get_allocation() |
| 270 | | if self._spiral_mode: |
| 271 | | min_width_, box_width = self.box.get_width_request() |
| 272 | | min_height_, box_height = self.box.get_height_request(box_width) |
| 273 | | angle, radius = self._calculate_angle_and_radius(icon_index, |
| 274 | | icon_size) |
| 275 | | x, y = self._convert_from_polar_to_cartesian(angle, radius, |
| 276 | | icon_size, |
| 277 | | width, height) |
| 278 | | else: |
| 279 | | angle = icon_index * (2 * math.pi / children_count) - math.pi / 2 |
| 280 | | x = radius * cos(angle) + (width - icon_size) / 2 |
| 281 | | y = radius * sin(angle) + (height - icon_size - \ |
| | 262 | angle = icon_index * (2 * math.pi / children_count) - math.pi / 2 |
| | 263 | x = radius * cos(angle) + (width - icon_size) / 2 |
| | 264 | y = radius * sin(angle) + (height - icon_size - \ |
| 282 | 265 | (style.GRID_CELL_SIZE / 2)) / 2 |
| 283 | 266 | return x, y |
| 284 | 267 | |
| 285 | | def _convert_from_polar_to_cartesian(self, angle, radius, icon_size, width, |
| 286 | | height): |
| 287 | | """ Convert angle, radius to x, y """ |
| 288 | | x = int(math.sin(angle) * radius) |
| 289 | | y = int(math.cos(angle) * radius) |
| 290 | | x = - x + (width - icon_size) / 2 |
| 291 | | y = y + (height - icon_size - (style.GRID_CELL_SIZE / 2)) / 2 |
| 292 | | return x, y |
| 293 | | |
| 294 | | def _calculate_angle_and_radius(self, icon_count, icon_size): |
| 295 | | """ Based on icon_count and icon_size, calculate radius and angle. """ |
| 296 | | spiral_spacing = _SPIRAL_SPACING_FACTORS[_ICON_SIZES.index(icon_size)] |
| 297 | | icon_spacing = icon_size + style.DEFAULT_SPACING * \ |
| 298 | | _ICON_SPACING_FACTORS[_ICON_SIZES.index(icon_size)] |
| 299 | | angle = _INITIAL_ANGLE |
| 300 | | radius = _MINIMUM_RADIUS - (icon_size * _MIMIMUM_RADIUS_ENCROACHMENT) |
| 301 | | for i in range(icon_count): |
| 302 | | circumference = radius * 2 * math.pi |
| 303 | | n = circumference / icon_spacing |
| 304 | | angle += (2 * math.pi / n) |
| 305 | | radius += (float(icon_spacing) * spiral_spacing / n) |
| 306 | | return angle, radius |
| 307 | | |
| 308 | 268 | def _get_children_in_ring(self): |
| 309 | 269 | children_in_ring = [child for child in self.box.get_layout_children() \ |
| 310 | 270 | if child not in self._locked_children] |
| … |
… |
|
| 351 | 311 | else: |
| 352 | 312 | return 0 |
| 353 | 313 | |
| | 314 | |
| 354 | 315 | _SUNFLOWER_CONSTANT = style.STANDARD_ICON_SIZE * .75 |
| 355 | 316 | """Chose a constant such that STANDARD_ICON_SIZE icons are nicely spaced.""" |
| 356 | 317 | |
Download in other formats: