|
1 | 1 | defmodule Scenic.Component.Button do
|
2 |
| - @moduledoc false |
| 2 | + @moduledoc """ |
| 3 | + Add a button to a graph |
3 | 4 |
|
| 5 | + A button is a small scene that is pretty much just some text drawn over a |
| 6 | + rounded rectangle. The button scene contains logic to detect when the button |
| 7 | + is pressed, tracks it as the pointer moves around, and when it is released. |
| 8 | +
|
| 9 | + ## Data |
| 10 | +
|
| 11 | + `title` |
| 12 | +
|
| 13 | + * `title` - a bitstring describing the text to show in the button |
| 14 | +
|
| 15 | + ## Messages |
| 16 | +
|
| 17 | + If a button press is successful, it sends an event message to the host scene |
| 18 | + in the form of: |
| 19 | +
|
| 20 | + {:click, id} |
| 21 | +
|
| 22 | + ## Styles |
| 23 | +
|
| 24 | + Buttons honor the following standard styles |
| 25 | +
|
| 26 | + * `:hidden` - If `false` the component is rendered. If `true`, it is skipped. |
| 27 | + The default is `false`. |
| 28 | + * `:theme` - The color set used to draw. See below. The default is `:primary` |
| 29 | +
|
| 30 | + ## Additional Styles |
| 31 | +
|
| 32 | + Buttons honor the following list of additional styles. |
| 33 | +
|
| 34 | + * `:width` - pass in a number to set the width of the button. |
| 35 | + * `:height` - pass in a number to set the height of the button. |
| 36 | + * `:radius` - pass in a number to set the radius of the button's rounded |
| 37 | + rectangle. |
| 38 | + * `:alignment` - set the alignment of the text inside the button. Can be one |
| 39 | + of `:left, :right, :center`. The default is `:center`. |
| 40 | + * `:button_font_size` - the size of the font in the button |
| 41 | +
|
| 42 | + Buttons do not use the inherited `:font_size` style as they should look |
| 43 | + consistent regardless of what size the surrounding text is. |
| 44 | +
|
| 45 | + ## Theme |
| 46 | +
|
| 47 | + Buttons work well with the following predefined themes: |
| 48 | + `:primary`, `:secondary`, `:success`, `:danger`, `:warning`, `:info`, |
| 49 | + `:text`, `:light`, `:dark` |
| 50 | +
|
| 51 | + To pass in a custom theme, supply a map with at least the following entries: |
| 52 | +
|
| 53 | + * `:text` - the color of the text in the button |
| 54 | + * `:background` - the normal background of the button |
| 55 | + * `:active` - the background while the button is pressed |
| 56 | +
|
| 57 | + ## Usage |
| 58 | +
|
| 59 | + You should add/modify components via the helper functions in |
| 60 | + [`Scenic.Components`](Scenic.Components.html#button/3) |
| 61 | +
|
| 62 | + ### Examples |
| 63 | +
|
| 64 | + The following example creates a simple button and positions it on the screen. |
| 65 | +
|
| 66 | + graph |
| 67 | + |> button("Example", id: :button_id, translate: {20, 20}) |
| 68 | +
|
| 69 | + The next example makes the same button as before, but colors it as a warning |
| 70 | + button. See the options list above for more details. |
| 71 | +
|
| 72 | + graph |
| 73 | + |> button("Example", id: :button_id, translate: {20, 20}, theme: :warning) |
| 74 | + """ |
4 | 75 | use Scenic.Component, has_children: false
|
5 | 76 |
|
6 | 77 | alias Scenic.Graph
|
|
0 commit comments