* Add the basic ContentSwitcher widget
* Docstring tidy
* Add a visible_content property to the ContentSwitcher
* Clarify that children of ContentSwitcher with no IDs get ignored
* Simplify setting the display value
* Add the start of an example ContentSwitcher for the docs
* Tweak the example layout to better fit in small spaces
* Add the content switcher to the API docs
* Add a guide entry for the ContentSwitcher
This one is a wee bit more involved than most other widget entries in the
guide in that it doesn't obviously do anything itself, but needs
developer-input to make it do something useful. As such the outline here
isn't as clean as it could be, but I think it conveys everything necessary
without getting too complicated.
* Add the reactive attribute table to the ContentSwitcher guide
* Update the README
* Add a refresh after everything has been flipped in the switcher
As noted in the code, this should not be necessary and I don't believe it
has anything to do with this code. I would suspect some lower-level issue
with flipping between different widgets within a container. I need to find a
way to make an isolated reproduction that isn't about this particular
widget. Meanwhile though this works with the refresh().
* Swap current from var to reactive
This solves the explicit refresh issue, but only because the refresh is
implied due to the use of a reactive over a var. As such this sort of
addresses #1979 by ignoring the issue rather than diving into it.
I still suspect that I shouldn't need to do this, and that perhaps there's a
refresh issue when you flip display. So I'll keep #1979 kicking around and
at some point see if I can recreate in isolation.
* Add unit tests for the content switcher
* Add snapshot tests for the ContentSwitcher
* Clarify that an exception can be thrown on a bad ID
* Try and help other Pythons
* Add a pause at the end of the second switcher snapshot test
I'm getting a lot of fails in CI; none of them are actual problems.
Hopefully this will cure it.
* Paaaaaaaaause
More of a test than anything else really. My particular snapshot test is
failing but kinda randomly in each environment each time -- sometimes
Windows, sometimes GNU/Linux, different Python versions.
So... yeah, let's try this and see if it makes it through; otherwise I may
need to rethink this.
* New pause
So it turns out that _ doesn't do anything any more; and instead there's a
"wait:<n>" syntax! So let's give that a try.
* Learning my alphabet...
* Fix a typo in the docs.
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
* Add missing full stop.
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
* Add a missing word
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
* Try a longer wait on the switcher
I'm starting to suspect that this doesn't come down to a timing issue;
especially given that the snapshot report seems to be showing some oddity in
the length of the vertical scrollbar. But... I want to be as sure as
possible so let's double the length of the wait.
Bit a bit of me is starting to wonder if I've somehow managed to create the
perfect storm for scrollbars and you don't always get the same result every
time.
Seems unlikely, but if it's not timing it's that or lots of cosmic rays.
* Test a longer pause on the content switcher test
The idea here being that it takes 200ms for the button to pop again.
* Refresh the snapshots
This time. THIS TIME!
* Experiment: is the issue the same name for two tests?
* Experiment: drop the different source files, try terminal size
Having got over the issue of the button not ending up in the same state,
we're stuck with the scrollbar having different sizes. Having tried other
options let's go with tweaking the terminal size.
* Do a little less work when changing current
Rather than set everything invisible then the new one visible, every time
current is changed, instead just make sure everything is invisible up front
and then just swap the affected children each time.
This does mean that if someone messes with the children under the hood they
may see oddness happening, but less work while being less defensive seems
fair here.
---------
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
Unlike a few other widgets, the RadioSet is pretty much all about reacting
to the selection result; the question of how you go about it has already
come up and while the message is documented, complete with all properties,
it can't hurt to have an illustrative example of code that uses it.
Here I add an extra RadioSet example that sits with the message in the
reference. This should help the reader better follow how to use it, and also
gives something to link to if someone hasn't got that far into the
documentation yet but is attempting to use the RadioSet.
A large part of the code to go with this is to show off a radio set; I feel
it makes sense to use the same code for both bits of documentation given
that a radio button only really makes sense inside a radio set.
Following on from #1751: originally Switch was called Checkbox and the
moving part was, for the component class, called a checkbox--switch; after
renaming the widget to Switch that component class ended up being
switch--switch; which wasn't ideal.
We decided to go with it as-is, but I just realised that internally the code
calls it a slider. So this leans into that and I'm renaming the component
class switch--slider. This removes the doubling-up of the name and also
makes the code more consistent.
A new form of Checkbox will be arriving in Textual soon, working in
conjunction with a RadioButton. What was called Checkbox is perhaps a wee
bit heavyweight in terms of visual design, but is a style of widget that
should remain.
With this in mind we're renaming the current Checkbox to Switch. In all
other respects its workings remains the same, only the name has changed.
Things for people to watch out for:
- Imports will need to be updated.
- Queries will need to be updated; special attention will need to be paid to
any queries that are string-based.
- CSS will need to be changed if any Checkbox styling is happening, or if
any Checkbox component styles are being used.
See #1725 as the initial motivation and #1746 as the issue for this
particular change.
* checkbox widget
* fixes
* Checkbox additions, fix content width in horizontal layout
* Update docs, add tests for checkbox
* Remove some test code
* Small renaming of test class
Co-authored-by: Will McGugan <willmcgugan@gmail.com>