-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UIState to track hot/active widgets (#22)
* pass null_widget as an argument * create widget_id.jl * rename ui_state.jl to utils.jl * add widget!! to have single interface for all widgets (with or without side effects) * add UIState to tracker user's interaction * use UIState in example.jl * rename widget_id.jl to ui_state.jl * move UIState out of SimpleWidgets
- Loading branch information
1 parent
4295abb
commit 3aaf25b
Showing
5 changed files
with
84 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module SimpleWidgets | ||
|
||
include("input.jl") | ||
include("ui_state.jl") | ||
include("utils.jl") | ||
include("widgets.jl") | ||
include("ui_state.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,20 @@ | ||
struct WidgetID | ||
abstract type AbstractWidgetID end | ||
|
||
struct WidgetID <: AbstractWidgetID | ||
line_number::Int | ||
file_name::String | ||
end | ||
|
||
const NULL_WIDGET_ID = WidgetID(0, "") | ||
|
||
went_down(ended_down, half_transition_count) = (half_transition_count >= 2) || ((half_transition_count == 1) && ended_down) | ||
went_up(ended_down, half_transition_count) = (half_transition_count >= 2) || ((half_transition_count == 1) && !ended_down) | ||
abstract type AbstractUIState end | ||
|
||
function try_set_hot_widget(hot_widget, active_widget, widget, condition) | ||
if (active_widget == NULL_WIDGET_ID) && condition | ||
return widget | ||
else | ||
return hot_widget | ||
end | ||
end | ||
const NULL_WIDGET_ID = WidgetID(0, "") | ||
|
||
function try_set_active_widget(hot_widget, active_widget, widget, condition) | ||
if (hot_widget == widget) && (active_widget == NULL_WIDGET_ID) && condition | ||
return widget | ||
else | ||
return active_widget | ||
end | ||
end | ||
function widget!(ui_state::AbstractUIState, args...; kwargs...) | ||
hot_widget, active_widget, null_widget, values = widget!!(ui_state.hot_widget, ui_state.active_widget, ui_state.null_widget, args...; kwargs...) | ||
|
||
function try_reset_hot_widget(hot_widget, active_widget, widget, condition) | ||
if (hot_widget == widget) && (active_widget != widget) && condition | ||
return NULL_WIDGET_ID | ||
else | ||
return hot_widget | ||
end | ||
end | ||
ui_state.hot_widget = hot_widget | ||
ui_state.active_widget = active_widget | ||
ui_state.null_widget = null_widget | ||
|
||
function try_reset_active_widget(hot_widget, active_widget, widget, condition) | ||
if (active_widget == widget) && (hot_widget == widget) && condition | ||
return NULL_WIDGET_ID | ||
else | ||
return active_widget | ||
end | ||
return values | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
went_down(ended_down, half_transition_count) = (half_transition_count >= 2) || ((half_transition_count == 1) && ended_down) | ||
went_up(ended_down, half_transition_count) = (half_transition_count >= 2) || ((half_transition_count == 1) && !ended_down) | ||
|
||
function try_set_hot_widget(hot_widget, active_widget, null_widget, widget, condition) | ||
if (active_widget == null_widget) && condition | ||
return widget | ||
else | ||
return hot_widget | ||
end | ||
end | ||
|
||
function try_set_active_widget(hot_widget, active_widget, null_widget, widget, condition) | ||
if (hot_widget == widget) && (active_widget == null_widget) && condition | ||
return widget | ||
else | ||
return active_widget | ||
end | ||
end | ||
|
||
function try_reset_hot_widget(hot_widget, active_widget, null_widget, widget, condition) | ||
if (hot_widget == widget) && (active_widget != widget) && condition | ||
return null_widget | ||
else | ||
return hot_widget | ||
end | ||
end | ||
|
||
function try_reset_active_widget(hot_widget, active_widget, null_widget, widget, condition) | ||
if (active_widget == widget) && (hot_widget == widget) && condition | ||
return null_widget | ||
else | ||
return active_widget | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters