From cbf92d85987079b6256bfea8a7d87e4e60e089c0 Mon Sep 17 00:00:00 2001 From: Gio Lucas Torres Date: Thu, 13 Oct 2022 11:17:39 -0300 Subject: [PATCH] Added documentation for new events. --- lib/scenic/component/button.ex | 11 ++++++++++- lib/scenic/component/input/dropdown.ex | 9 ++++++++- lib/scenic/component/input/text_field.ex | 5 +++++ test/scenic/component/input/dropdown_test.exs | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/scenic/component/button.ex b/lib/scenic/component/button.ex index 23c69606..1791f8f3 100644 --- a/lib/scenic/component/button.ex +++ b/lib/scenic/component/button.ex @@ -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: diff --git a/lib/scenic/component/input/dropdown.ex b/lib/scenic/component/input/dropdown.ex index b21c06e5..e904d012 100644 --- a/lib/scenic/component/input/dropdown.ex +++ b/lib/scenic/component/input/dropdown.ex @@ -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. @@ -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, @@ -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 diff --git a/lib/scenic/component/input/text_field.ex b/lib/scenic/component/input/text_field.ex index b1cb1b2e..5e83c06a 100644 --- a/lib/scenic/component/input/text_field.ex +++ b/lib/scenic/component/input/text_field.ex @@ -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 diff --git a/test/scenic/component/input/dropdown_test.exs b/test/scenic/component/input/dropdown_test.exs index 037cbc1c..a80225d5 100644 --- a/test/scenic/component/input/dropdown_test.exs +++ b/test/scenic/component/input/dropdown_test.exs @@ -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