2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

compassのsprite-mapでlayout:smartにしつつ、余白の設定をするには

Last updated at Posted at 2015-10-06

compassのsprite-mapでlayout:smartにしつつ余白の設定をしたい。

compass仕様

  • layout:smartとは
    sprite内の画像配置方法の一つ。

    自動で効率よく(=幅を取らない形で)並べてくれるレイアウト。
  • layout:smartにした場合は余白の設定ができない。

    compass本家マニュアル

Configuration options do not effect the layout

→余白が設定できないといより、layout:smartの場合、設定したoptionは無視されるってことだと思われる。

要件

  • 画面全体をzoomして表示する必要がある。

問題

  • spriteの縦or横が長くなり過ぎると、画面をzoomした際spriteの端画像がずれが目立つ。
  • 同様に、余白が無いとzoomした際に隣の画像がはみ出てしまうことがある。

→つまりlayout:smartにしてspriteの縦横サイズを抑えつつ、余白を設定できれば解決!

対応方法

  • 調べたら同じようなことをやりたい人がいる模様

Generate sprites with compass with smart layout and spacing - stack overflow

  • こちらに答え(やりたいこと)が出ていた

Compassのsprite-mapのlayout: smartでspacingを有効にする - console.lealog();

  • 今回の要件はチームメンバー全員が同じようにcompass compileできるようにしたいので以下方式を採用

本家のモジュールをコンパイル時だけ拡張する

拡張モジュールはリポジトリ内に抱える形で、config.rbで参照する。

qiita.rb
# config.rbの先頭で拡張モジュールを参照する
require './PATH/extend.rb'

↑の'./PATH/extend.rb'の中身はこんな感じ

これでOKでした。

ちなみに

こんな議論がされていました。
余白を指定したいならsmartは使うな、的なことを本家の方がおっしゃっています

sprite with smart layout not support sprite-spacing?

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?