Comments (6)
Transparency is allowed by the pad
function of vty
it seems, but I don't see where it has a counterpart in brick
s API.
from brick.
If I understand this right, I am hearing two requests:
- Is there a way to do padding with transparency?
- Is there a way to do placement in a container without knowing its size?
The answer to the first one is to take a look at translateBy
, and the answer to the second is no: if you don't know how big the parent container is, you can't know how much your translation offset should be. But, it isn't too hard to do this generically. Here's a generic way to make a layer from a widget and place it at the bottom left. (I haven't tested this but it should be just about right.) The idea is to render the child first, then use its size and the parent container size (from the rendering context) to translate the child. Translation gives you the transparency you want, unlike padding. For inspiration you can look at how the "layer" variants of the centering functions are implemented (e.g. hCenterLayer
).
bottomLeftCorner :: Widget a -> Widget a
bottomLeftCorner child =
Widget Greedy Greedy $ do
ctx <- getContext
childResult <- render child
let childHeight = result^.imageL.to imageHeight
offsetX = 0
offsetY = ctx^.availHeightL - childHeight
offset = Location (offsetX, offsetY)
return $ addResultOffset offset $ childResult & imageL .~ translateBy offset
from brick.
Thanks for the tips! I think I got what I want. I packaged it up in some margin*
combinators. They seem to work, judging from fiddling around with them, but no guarantees:
marginLeft :: Padding -> Widget a -> Widget a
marginLeft padding p =
let (pad, sz) = case padding of
Max -> (id, Greedy)
Pad i -> (const i, hSize p)
in Widget sz (vSize p) $ do
(availWidth, lim) <- calculateLim padding availWidthL
result <- render $ hLimit lim p
let offsetX = pad (availWidth - result^.imageL.to imageWidth)
offset = Location (offsetX, 0)
return $ addResultOffset offset $ result & imageL %~ translateX offsetX
marginRight :: Padding -> Widget a -> Widget a
marginRight padding p =
let (pad, sz) = case padding of
Max -> (id, Greedy)
Pad i -> (const i, hSize p)
in Widget sz (vSize p) $ do
(availWidth, lim) <- calculateLim padding availWidthL
result <- render $ hLimit lim p
let childWidth = result^.imageL.to imageWidth
width = childWidth + pad (availWidth - childWidth)
return $ result & imageL %~ resizeWidth width
marginTop :: Padding -> Widget a -> Widget a
marginTop padding p =
let (pad, sz) = case padding of
Max -> (id, Greedy)
Pad i -> (const i, vSize p)
in Widget (hSize p) sz $ do
(availHeight, lim) <- calculateLim padding availHeightL
result <- render $ vLimit lim p
let offsetY = pad (availHeight - result^.imageL.to imageHeight)
offset = Location (0, offsetY)
return $ addResultOffset offset $ result & imageL %~ translateY offsetY
marginBottom :: Padding -> Widget a -> Widget a
marginBottom padding p =
let (pad, sz) = case padding of
Max -> (id, Greedy)
Pad i -> (const i, vSize p)
in Widget (hSize p) sz $ do
(availHeight, lim) <- calculateLim padding availHeightL
result <- render $ vLimit lim p
let childHeight = result^.imageL.to imageHeight
height = childHeight + pad (availHeight - childHeight)
return $ result & imageL %~ resizeHeight height
calculateLim :: Padding -> Lens' Context Int -> RenderM n (Int, Int)
calculateLim padding widthOrHeight = do
c <- getContext
let lim = case padding of
Max -> c^.widthOrHeight
Pad i -> c^.widthOrHeight - i
return (c^.widthOrHeight, lim)
They're pretty similar to padLeft
et al., feel free to use them if you want to.
from brick.
Looking at the implementation I'm not sure what these functions are supposed to do. Can you give a description of just the first one?
from brick.
It's more or less like the pad*
, but the padding is 'transparent'. Think bottomLeftCorner = marginTop Max . marginRight Max
.
So marginLeft
is like padLeft
, but instead of fill ' '
the padding characters, it translate
s over them. The resemblence should be more clear if you inline calculateLim
.
marginTop
is analogous, but marginBottom
and marginRight
have to resize the Image
instead of translating it.
Is that clear enough? If not, I could make a screenshot of what I mean.
from brick.
That makes sense. Thanks!
from brick.
Related Issues (20)
- Pressing option minus on Mac before app runs causes sigsegv HOT 5
- Windows support HOT 7
- Question: entering text from user HOT 6
- [WIP] How to unit test Brick apps HOT 3
- I think I found a typo HOT 1
- How to debug Brick applications HOT 4
- ld: library not found for -liconv clang-13: error: linker command failed with exit code 1 (use -v to see invocation) `clang' failed in phase `Linker'. (Exit code: 1 HOT 1
- Wrap repeating code in a function HOT 18
- handleFormEvent doesn't update form field validation state? HOT 22
- row ... now exceeds region width HOT 8
- Is there any way to wait for an input? For example, wait for confirmation. HOT 8
- There should be something like `fmapState`. HOT 10
- Consider adding `zoomOut` for saving lines when dealing with sum types. HOT 3
- Cannot install `brick` via `cabal update && cabal install brick` on NixOS HOT 9
- Add version of customMain that doesn't require a Vty handle HOT 11
- Documentation Unavailable on Hackage HOT 4
- Can you add brick-trading-journal to featured projects on README? HOT 1
- Mouse-based selection stops working after using the mouse in an app. HOT 17
- Visbility request for FormFieldState instead of FormField HOT 7
- Segmentation fault when eagerly pressing a keyboard key HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brick.