As far as I can tell, within the confines of Elm-UI the text is assigned a fixed size, expressed by a Int number, in pixels: Element.Font.size 400
What is then the proper Elm-UI way of resizing text depending on the viewport?
Is there a way to make the text size values responsive?
Or should I hardcode breakpoints with different fixed sizes?
Or should I use SVG graphics in place of plain text when creating stuff like a big title?
Or… what?
I’m not sure.
I’m dabbling.
At the moment I have a row…
on the left there is a column of elements (a big title, a smaller sub-title, a paragraph of text)
on the right there is an image
the image is an SVG, so it fills the whole space, and I can simply partition the element width using the fill and fillPortion attributes
the Title and Subtitle are my problem
they are normal text, with a BIG font size
I would like for them to shrink and expand just like the SVG image does… unless a specific DeviceClass is reached and then the view structure will change.
But Element.Font.size only accepts an Int value in pixels… no percentage, no Length value.
My questions are:
what would be the Elm-UI way of approaching this problem?
Use DeviceClass to set breakpoints, and then change the original fixed values with new fixed values?
Or would it be possible to use DeviceClass to dynamically produce an Int to be passed to the Font.size function? (and if so… how?)
I think the typical responsive approach is using something like the following:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
DeviceClassified device ->
( { model | device = device }
, Cmd.none
)
---- SUBSCRIPTIONS ----
subscriptions : Model -> Sub Msg
subscriptions model =
onResize <|
\width height ->
DeviceClassified (Element.classifyDevice { width = width, height = height })
If you want to access the width or height to calculate your font size, just store fontSize in your model and calculate it in the update function passing the {width, height} instead of the DeviceClass.
Please note the flags being passed into the init of the elm app:
<script>
var app = Elm.Main.init({ node: document.querySelector('main')
,
flags: {
width: window.innerWidth,
height: window.innerHeight
}})
// you can use ports and stuff here
</script>