Skip to content

Commit

Permalink
several small miscellaneous changes (#56)
Browse files Browse the repository at this point in the history
* remove unused do_widget! method for CheckBox

* minor rearrangement in user_interaction.jl

* use isone in went_down and went_up

* use typeof(input_button) instead of hardcoding InputButton

* rename input.jl to user_input.jl

* fix filename in SimpleIMGUI.jl

* rename alignment names

* simplify get_num_printable_characters

* update argument order in get_widget_value for Slider

* remove some debug text

* fix get_num_printable_characters for empty string

* simplify text for button and slider in example

* left align default text in text box

* reduce width of button, slider, and text box

* use content-based width for check box
  • Loading branch information
Sid-Bhatia-0 authored Aug 5, 2022
1 parent b40115a commit a545ef6
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 144 deletions.
79 changes: 36 additions & 43 deletions examples/example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * SI.get_num_printable_characters(text),
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
text,
font,
Expand All @@ -166,12 +166,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * 12,
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
"Button",
font,
Expand All @@ -188,14 +188,14 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.RIGHT2,
SI.RIGHT_OUT,
padding,
SD.get_height(font),
360,
240,
image,
SI.CENTER,
-1,
"Button clicks: $(num_button_clicks)",
"$(num_button_clicks)",
font,
SI.ContextualColor(0x00b0b0b0, 0x00b7b7b7, 0x00bfbfbf),
SI.ContextualColor(0x00000000, 0x00000000, 0x00000000),
Expand All @@ -213,12 +213,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * 12,
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
"Slider",
font,
Expand All @@ -236,14 +236,14 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.RIGHT2,
SI.RIGHT_OUT,
padding,
SD.get_height(font),
360,
240,
image,
SI.CENTER,
-1,
"Slider value: $(slider_value)",
"$(slider_value)",
font,
SI.ContextualColor(0x00b0b0b0, 0x00b7b7b7, 0x00bfbfbf),
0x00000000,
Expand All @@ -259,12 +259,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * 12,
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
"TextBox",
font,
Expand All @@ -283,12 +283,12 @@ function start()
user_input_state.mouse_left,
user_input_state.characters,
layout,
SI.RIGHT2,
SI.RIGHT_OUT,
padding,
SD.get_height(font),
360,
240,
image,
SI.CENTER,
SI.LEFT_IN,
-1,
font,
SI.ContextualColor(0x00b0b0b0, 0x00b7b7b7, 0x00bfbfbf),
Expand All @@ -305,11 +305,6 @@ function start()
push!(debug_text, "mouse_middle: $(user_input_state.mouse_middle)")
push!(debug_text, "hot_widget: $(user_interaction_state.hot_widget)")
push!(debug_text, "active_widget: $(user_interaction_state.active_widget)")
push!(debug_text, "button_value: $(button_value)")
push!(debug_text, "slider_value: $(slider_value)")
push!(debug_text, "text_box_value: $(text_box_value)")
push!(debug_text, "radio_button_value: $(radio_button_value)")
push!(debug_text, "drop_down_value: $(drop_down_value)")

layout.reference_bounding_box = reference_bounding_box
SI.do_widget!(
Expand All @@ -319,12 +314,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * 12,
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
"RadioButton",
font,
Expand All @@ -348,12 +343,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.RIGHT2,
SI.RIGHT_OUT,
padding,
SD.get_height(font),
SD.get_width(font) * (max_num_chars + 2),
image,
SI.LEFT1,
SI.LEFT_IN,
-1,
item,
font,
Expand All @@ -366,7 +361,6 @@ function start()
end
reference_bounding_box = SI.get_bounding_box(reference_bounding_box, layout.reference_bounding_box)
end
push!(debug_text, "radio_button_value: $(radio_button_value)")

layout.reference_bounding_box = reference_bounding_box
SI.do_widget!(
Expand All @@ -376,12 +370,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * 12,
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
"DropDown",
font,
Expand All @@ -404,12 +398,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.RIGHT2,
SI.RIGHT_OUT,
padding,
SD.get_height(font),
SD.get_width(font) * (max_num_chars + 2),
image,
SI.LEFT1,
SI.LEFT_IN,
-1,
drop_down_item_list[drop_down_selected_item],
font,
Expand All @@ -430,12 +424,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * (max_num_chars + 2),
image,
SI.LEFT1,
SI.LEFT_IN,
-1,
item,
font,
Expand All @@ -449,8 +443,6 @@ function start()
reference_bounding_box = SI.get_bounding_box(reference_bounding_box, layout.reference_bounding_box)
end
end
push!(debug_text, "drop_down_value: $(drop_down_value)")
push!(debug_text, "drop_down_selected_item: $(drop_down_selected_item)")

layout.reference_bounding_box = reference_bounding_box
SI.do_widget!(
Expand All @@ -460,12 +452,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * 12,
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
"CheckBox",
font,
Expand All @@ -475,6 +467,7 @@ function start()
)
reference_bounding_box = layout.reference_bounding_box

text = "Show debug text"
show_debug_text = SI.do_widget!(
SI.CHECK_BOX,
user_interaction_state,
Expand All @@ -483,14 +476,14 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.RIGHT2,
SI.RIGHT_OUT,
padding,
SD.get_height(font),
360,
SD.get_width(font) * (SI.get_num_printable_characters(text) + 2),
image,
SI.LEFT1,
SI.LEFT_IN,
-1,
"Show debug text",
text,
font,
0x00cccccc,
0x00cccccc,
Expand All @@ -508,12 +501,12 @@ function start()
user_input_state.cursor,
user_input_state.mouse_left,
layout,
SI.DOWN2_LEFT1,
SI.DOWN_OUT_LEFT_IN,
padding,
SD.get_height(font),
SD.get_width(font) * SI.get_num_printable_characters(text),
image,
SI.UP1_LEFT1,
SI.UP_IN_LEFT_IN,
-1,
text,
font,
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleIMGUI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SimpleIMGUI

import SimpleDraw as SD

include("input.jl")
include("user_input.jl")
include("layout.jl")
include("user_interaction.jl")
include("widgets.jl")
Expand Down
14 changes: 2 additions & 12 deletions src/drawing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ function get_color(user_interaction_state, this_widget, color::ContextualColor)
end
end

function get_num_printable_characters(text)
num_printable = 0

for character in text
if isprint(character)
num_printable += 1
end
end

return num_printable
end
get_num_printable_characters(text) = count(isprint, text)

function get_intersection_extrema(image, shape)
i_min_shape, i_max_shape = SD.get_i_extrema(shape)
Expand Down Expand Up @@ -120,7 +110,7 @@ end

function draw_widget!(image, bounding_box, widget_type::TextBox, user_interaction_state, this_widget, text, alignment, padding, font, background_color, border_color, text_color)
if get_num_printable_characters(text) * SD.get_width(font) > bounding_box.width
alignment = RIGHT1
alignment = RIGHT_IN
end

draw_text_line_in_a_box!(
Expand Down
Loading

0 comments on commit a545ef6

Please sign in to comment.