51
4
Write a program that creates a two-state checkbox that people can interact with using a mouse.
Specifically, your program should achieve all of the following:
Have a 8×8 pixel (or larger if desired) region of the screen that is the clickable area of the checkbox. Henceforth this region is simply called the checkbox.
When the mouse cursor is moved within the checkbox and the default* mouse button is pressed, the checkbox should toggle states.
Checked becomes unchecked. Unchecked becomes checked.The checkbox should not move when it is toggled.
In the checked state, the checkbox may be any colors.
In the unchecked state, the checkbox may be any colors as long as at least 16 pixels are visually distinct from the checked state.
In a single program instance, all checked states should be visually identical to one another and all unchecked states should be visually identical to one another.
Don't end the program until it's explicitly terminated (e.g. via exit button or Alt+F4), so a user can click the checkbox as much as they want.
*You may assume the default mouse button is always left click, but it's also fine to use the default as defined by mouse software or the OS, which may not actually be left click depending on the user.
Notes
It does not matter what is outside of your checkbox region. It could just be the desktop. It could be a portion of a console that changes on every toggle.
It does not matter what state your checkbox starts in.
The checkbox region may have any dimensions at or above 8×8 pixels. It need not be square.
You may make minor allowances for settings that are out of your control such as console font size, browser zoom, monitor resolution, etc. As long your program works in a reasonable test setting it should be valid.
If your program opens a window, you may assume it has been dragged to an appropriate location on the screen if necessary (e.g. top left corner).
You may use markup languages such as HTML or other languages we usually don't consider as full-fledged programming languages.
Your checkbox must be be toggleable using the default mouse button. It's alright if it also toggles for other forms of input (e.g. right mouse button), with the exception of mouse motion. i.e. the state should not change if the mouse is merely moved within the checkbox.
Screenshots of your checkbox in action are highly encouraged!
Scoring
The shortest code in bytes wins.
Example
A canonical HTML example in 23 bytes.
<input type="checkbox">
For me in Google Chrome, this makes a 12×12 pixel checkbox and about 30 pixels clearly change between checked and unchecked states.
I make the allowance that browser zoom is at 100%.
2Can the checkbox cover the entire screen? – user41805 – 2017-02-05T11:19:52.400
@KritixiLithos Yes, that would be valid.Though note that you may, if desired, count a particular 8x8 region as the official checkbox, even if a larger region works. – Calvin's Hobbies – 2017-02-05T11:22:22.023
@Helka Homba - is it allowed for an app to display other controls, aside the checkbox itself ? – zeppelin – 2017-02-05T12:54:21.833
Is it OK for the checkbox to toggle on other sorts of input? (For example, is a solution correct if the checkbox toggles on any sort of user input, regardless of whether it's a mouse click, a mouse movement, or a keypress? It'd toggle on a mouse click, but it'd toggle on other stimuli too.) – None – 2017-02-05T16:27:11.977
Would touching a touchscreen instead of using a mouse be acceptable? – 12Me21 – 2017-02-05T17:00:16.787
When the mouse cursor is moved within the checkbox and the default mouse button is pressed Can we also toggle if the user clicks outside the checkbox or with another mouse button apart from the left one? – Dennis – 2017-02-05T18:25:27.787
1@zeppelin "It does not matter what is outside of your checkbox region. It could just be the desktop. It could be a portion of a console that changes on every toggle." So, as long as the checkbox is there, it doesn't matter what else is. – Calvin's Hobbies – 2017-02-05T20:42:28.777
@ais523 / 12Me21 / Dennis it's ok if other forms of input, except for mouse-motion, (like keypress/touch/right click) also toggle the checkbox, whether inside the region or outside, as long as the default mouse button works to toggle the checkbox as well. – Calvin's Hobbies – 2017-02-05T20:49:23.753
Finally a task where KV lang, or any lang that creates an instance from
checkbox
string just wins. But I fear there's some character/byte in some gibberish that does the same thing and if not, someone will write it just to solve this. :D – KeyWeeUsr – 2017-02-05T22:05:50.203Can the checkbox display after another region is clicked? For example, the program runs, part of what displays is a button, upon clicking the button, a checkbox which satisfies all other conditions is visible. – briantist – 2017-02-06T02:59:14.013
@briantist No, I think the checkbox should show up right away – Calvin's Hobbies – 2017-02-06T06:19:01.733
May we abuse external programs which has checkboxes? – Matthew Roh – 2017-02-09T05:22:55.400
"It does not matter what state your checkbox starts in." Does it matter if the initial state is distinct from the checked and the unchecked state? – thykka – 2017-02-09T08:23:59.493
Wait, does the checkbox have to be on the screen? 'cause we already have one on the keyboard! – Matthew Roh – 2017-03-28T09:28:41.840