Skip to content

Commit

Permalink
add type parameters to some structs (#55)
Browse files Browse the repository at this point in the history
* add type parameter for cursor in UserInputState

* add type parameter to file name in WidgetID

* remove unused do_widget! method for CheckBox

* add type parameter to InputButton

* add type parameter for line and instance in WidgetID

* add back unused do_widget! method for CheckBox. will remove it in
different PR

* remove unnecessary type constraint in reset! method

* add type parameter to BoxLayout
  • Loading branch information
Sid-Bhatia-0 authored Aug 5, 2022
1 parent 13d083d commit b40115a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
26 changes: 13 additions & 13 deletions src/input.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
struct InputButton
struct InputButton{I}
ended_down::Bool
num_transitions::Int
num_transitions::I
end

abstract type AbstractUserInputState end

mutable struct UserInputState <: AbstractUserInputState
cursor::SD.Point
key_escape::InputButton
key_up::InputButton
key_down::InputButton
key_left::InputButton
key_right::InputButton
mouse_left::InputButton
mouse_right::InputButton
mouse_middle::InputButton
mutable struct UserInputState{I1, I2} <: AbstractUserInputState
cursor::SD.Point{I1}
key_escape::InputButton{I2}
key_up::InputButton{I2}
key_down::InputButton{I2}
key_left::InputButton{I2}
key_right::InputButton{I2}
mouse_left::InputButton{I2}
mouse_right::InputButton{I2}
mouse_middle::InputButton{I2}
characters::Vector{Char}
end

Expand All @@ -28,7 +28,7 @@ press(input_button) = InputButton(true, input_button.num_transitions + one(input
release(input_button) = InputButton(false, input_button.num_transitions + one(input_button.num_transitions))
reset(input_button) = InputButton(input_button.ended_down, zero(input_button.num_transitions))

function reset!(user_input_state::UserInputState)
function reset!(user_input_state)
user_input_state.key_escape = reset(user_input_state.key_escape)
user_input_state.key_up = reset(user_input_state.key_up)
user_input_state.key_down = reset(user_input_state.key_down)
Expand Down
4 changes: 2 additions & 2 deletions src/layout.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
abstract type AbstractLayout end

mutable struct BoxLayout <: AbstractLayout
reference_bounding_box::SD.Rectangle{Int}
mutable struct BoxLayout{I} <: AbstractLayout
reference_bounding_box::SD.Rectangle{I}
end

@enum Alignment begin
Expand Down
16 changes: 8 additions & 8 deletions src/user_interaction.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
abstract type AbstractWidgetID end

struct WidgetID <: AbstractWidgetID
file::String
line::Int
instance::Int
struct WidgetID{S, I} <: AbstractWidgetID
file::S
line::I
instance::I
end

abstract type AbstractUserInteractionState end

mutable struct UserInteractionState <: AbstractUserInteractionState
hot_widget::WidgetID
active_widget::WidgetID
null_widget::WidgetID
mutable struct UserInteractionState{S, I} <: AbstractUserInteractionState
hot_widget::WidgetID{S, I}
active_widget::WidgetID{S, I}
null_widget::WidgetID{S, I}
end

const NULL_WIDGET_ID = WidgetID("", 0, 0)

0 comments on commit b40115a

Please sign in to comment.