summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/X11/Boxes.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-18 00:18:39 +0100
committerjao <jao@gnu.org>2022-09-18 00:18:39 +0100
commit1d801183a54d3d6bf734d485ace744cdf78f3a77 (patch)
tree08c490887755dc8fc566d9e570d75361421dd868 /src/Xmobar/X11/Boxes.hs
parent2e9bc4187f0094d202fc11aa05f0637edcabf9bb (diff)
downloadxmobar-1d801183a54d3d6bf734d485ace744cdf78f3a77.tar.gz
xmobar-1d801183a54d3d6bf734d485ace744cdf78f3a77.tar.bz2
qualified imports
Diffstat (limited to 'src/Xmobar/X11/Boxes.hs')
-rw-r--r--src/Xmobar/X11/Boxes.hs73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/Xmobar/X11/Boxes.hs b/src/Xmobar/X11/Boxes.hs
index 87a081f..4ea7144 100644
--- a/src/Xmobar/X11/Boxes.hs
+++ b/src/Xmobar/X11/Boxes.hs
@@ -7,51 +7,62 @@
-- Maintainer: jao@gnu.org
-- Stability: unstable
-- Portability: unportable
---Start date: Fri Sep 16, 2022 04:01
+-- Start date: Fri Sep 16, 2022 04:01
--
-- Borders and boxes
--
------------------------------------------------------------------------------
-module Xmobar.X11.Boxes (boxLines, borderRect) where
+module Xmobar.X11.Boxes (Line, boxLines, BoxRect, borderRect) where
-import Xmobar.Run.Parsers
-import Xmobar.Config.Types
+import qualified Xmobar.Config.Types as T
+import qualified Xmobar.Run.Parsers as P
+
+type Line = (Double, Double, Double, Double)
+type BoxRect = (Double, Double, Double, Double)
-- | Computes the coordinates of a list of lines representing a Box.
-- The Box is to be positioned between x0 and x1, with height ht, and drawn
-- with line width lw. The returned lists are coordinates of the beginning
-- and end of each line.
-boxLines :: Box -> Double -> Double -> Double -> [(Double, Double, Double, Double)]
-boxLines (Box bd offset lw _ margins) ht x0 x1 =
+boxLines :: P.Box -> Double -> Double -> Double -> [Line]
+boxLines (P.Box bd offset lw _ margins) ht x0 x1 =
case bd of
- BBTop -> [rtop]; BBBottom -> [rbot]; BBVBoth -> [rtop, rbot]
- BBLeft -> [rleft]; BBRight -> [rright]; BBHBoth -> [rleft, rright]
- BBFull -> [rtop, rbot, rleft, rright]
- where (BoxMargins top right bot left) = margins
- (BoxOffset align m) = offset
- ma = fromIntegral m
- (p0, p1) = case align of L -> (0, -ma); C -> (ma, -ma); R -> (ma, 0)
- lc = fromIntegral lw / 2
- [mt, mr, mb, ml] = map fromIntegral [top, right, bot, left]
- xmin = x0 - ml - lc
- xmax = x1 + mr + lc
- ymin = mt + lc
- ymax = ht - mb - lc
- rtop = (xmin + p0, ymin, xmax + p1, ymin)
- rbot = (xmin + p0, ymax, xmax + p1, ymax)
- rleft = (xmin, ymin + p0, xmin, ymax + p1)
- rright = (xmax, ymin + p0, xmax, ymax + p1)
+ P.BBTop -> [rtop]
+ P.BBBottom -> [rbot]
+ P.BBVBoth -> [rtop, rbot]
+ P.BBLeft -> [rleft]
+ P.BBRight -> [rright]
+ P.BBHBoth -> [rleft, rright]
+ P.BBFull -> [rtop, rbot, rleft, rright]
+ where
+ (P.BoxMargins top right bot left) = margins
+ (P.BoxOffset align m) = offset
+ ma = fromIntegral m
+ (p0, p1) = case align of
+ T.L -> (0, -ma)
+ T.C -> (ma, -ma)
+ T.R -> (ma, 0)
+ lc = fromIntegral lw / 2
+ [mt, mr, mb, ml] = map fromIntegral [top, right, bot, left]
+ xmin = x0 - ml - lc
+ xmax = x1 + mr + lc
+ ymin = mt + lc
+ ymax = ht - mb - lc
+ rtop = (xmin + p0, ymin, xmax + p1, ymin)
+ rbot = (xmin + p0, ymax, xmax + p1, ymax)
+ rleft = (xmin, ymin + p0, xmin, ymax + p1)
+ rright = (xmax, ymin + p0, xmax, ymax + p1)
-- | Computes the rectangle (x, y, width, height) for the given Border.
-borderRect :: Border -> Double -> Double -> (Double, Double, Double, Double)
+borderRect :: T.Border -> Double -> Double -> BoxRect
borderRect bdr w h =
case bdr of
- TopB -> (0, 0, w - 1, 0)
- BottomB -> (0, h - 1, w - 1, 0)
- FullB -> (0, 0, w - 1, h - 1)
- TopBM m -> (0, fi m, w - 1, 0)
- BottomBM m -> (0, h - fi m, w - 1, 0)
- FullBM m -> (fi m, fi m, w - 2 * fi m, h - 2 * fi m)
- NoBorder -> (-1, -1, -1, -1)
+ T.TopB -> (0, 0, w - 1, 0)
+ T.BottomB -> (0, h - 1, w - 1, 0)
+ T.FullB -> (0, 0, w - 1, h - 1)
+ T.TopBM m -> (0, fi m, w - 1, 0)
+ T.BottomBM m -> (0, h - fi m, w - 1, 0)
+ T.FullBM m -> (fi m, fi m, w - 2 * fi m, h - 2 * fi m)
+ T.NoBorder -> (-1, -1, -1, -1)
where fi = fromIntegral