Skip to content

Commit

Permalink
Added documentation for new events.
Browse files Browse the repository at this point in the history
  • Loading branch information
GPrimola committed Oct 13, 2022
1 parent c7a5d9e commit cbf92d8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/scenic/component/button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ defmodule Scenic.Component.Button do
If a button press is successful, it sends an event message to the host scene
in the form of:
{:click, id}
`{:click, id}`
This event is only sent after the button is released. There're also, though,
two other events that you can receive:
`{:btn_pressed, id}`
and
`{:btn_released, id}`
These messages can be received and handled in your scene via
`c:Scenic.Scene.handle_event/3`. For example:
Expand Down
9 changes: 8 additions & 1 deletion lib/scenic/component/input/dropdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ defmodule Scenic.Component.Input.Dropdown do
`{:value_changed, id, selected_item_id}`
It also send the following events:
`{:dropdown_opened, id}` - sent when the dropdown opens
`{:dropdown_closed, id}` - sent when the dropdown closes
`{:dropdown_item_hover, id, item_id}` - sent when and item is hovered
## Options
Dropdowns honor the following list of options.
Expand Down Expand Up @@ -431,6 +437,7 @@ defmodule Scenic.Component.Input.Dropdown do
%Scene{
assigns: %{
down: true,
id: component_id,
items: items,
graph: graph,
selected_id: selected_id,
Expand All @@ -441,7 +448,7 @@ defmodule Scenic.Component.Input.Dropdown do
# set the appropriate hilighting for each of the items
graph = update_highlighting(graph, items, selected_id, id, theme)

:ok = send_parent_event(scene, {:dropdown_item_hover, id})
:ok = send_parent_event(scene, {:dropdown_item_hover, component_id, id})

scene =
scene
Expand Down
5 changes: 5 additions & 0 deletions lib/scenic/component/input/text_field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ defmodule Scenic.Component.Input.TextField do
`{:value_changed, id, value}`
It also sends other two events when focus is gained or lost, respectively:
`{:focus_in, id}`
`{:focus_out, id}`
## Styles
Text fields honor the following styles
Expand Down
4 changes: 2 additions & 2 deletions test/scenic/component/input/dropdown_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ defmodule Scenic.Component.Input.DropdownTest do

Input.send(vp, @hover_a)
force_sync(vp.pid, comp_pid)
assert_receive({:fwd_event, {:dropdown_item_hover, 1}}, 100)
assert_receive({:fwd_event, {:dropdown_item_hover, :dropdown, 1}}, 100)

Input.send(vp, @hover_b)
force_sync(vp.pid, comp_pid)
assert_receive({:fwd_event, {:dropdown_item_hover, 2}}, 100)
assert_receive({:fwd_event, {:dropdown_item_hover, :dropdown, 2}}, 100)

refute_receive(_, 10)
end
Expand Down

0 comments on commit cbf92d8

Please sign in to comment.