Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollbars do not reflect CSS changes immediately #4425

Closed
xavierog opened this issue Apr 17, 2024 · 2 comments · Fixed by #4433
Closed

Scrollbars do not reflect CSS changes immediately #4425

xavierog opened this issue Apr 17, 2024 · 2 comments · Fixed by #4433

Comments

@xavierog
Copy link
Contributor

xavierog commented Apr 17, 2024

Context

Checked closed issues? Yes.

Expectations

The scrollbar should reflect CSS changes (scrollbar-color) immediately.

Current behaviour

The scrollbar does not change until one scrolls or mouse-enters the scrollbar.
The MRE below reflects the issue.

#!/usr/bin/env python3
from textual.app import App, ComposeResult
from textual.containers import ScrollableContainer
from textual.widgets import Static, Footer

class MyBoringWidget(Static, can_focus=True):
	DEFAULT_CSS = "MyBoringWidget { height: 90%; background: $primary; border: tall yellow; }"

class ScrollMRE(App):
	CSS = """
	ScrollableContainer {
		scrollbar-color: ansi_bright_red;
		scrollbar-color-active: ansi_bright_red;
		scrollbar-color-hover: ansi_bright_red;
	}
	ScrollableContainer.foo {
		scrollbar-color: ansi_bright_green;
		scrollbar-color-active: ansi_bright_green;
		scrollbar-color-hover: ansi_bright_green;
	}
	Static { text-align: center; }
	"""
	BINDINGS = [
		('ctrl+f', 'toggle', 'Toggle scrollbar handle color'),
		('ctrl+w', 'workaround', 'Toggle workaround'),
	]
	def action_workaround(self):
		self.workaround = not self.workaround

	def action_toggle(self):
		self.scrollable_container.toggle_class('foo')
		if self.workaround:
			scrollbar = self.scrollable_container.vertical_scrollbar
			value = scrollbar.mouse_over
			scrollbar.mouse_over = not value
			scrollbar.mouse_over = value

	def compose(self) -> ComposeResult:
		self.workaround = False
		self.scrollable_container = ScrollableContainer()
		with self.scrollable_container:
			yield Static('Hit Ctrl+f. Expectations: the scrollbar handle should change color immediately')
			yield MyBoringWidget()
			yield Static('Actual behaviour: it does not change until one scrolls')
			yield MyBoringWidget()
			yield Static('Hit Ctrl+w to enable the workwaround')
		yield Footer()

if __name__ == "__main__":
	app = ScrollMRE()
	app.run()

Textual Diagnostics

Versions

Name Value
Textual 0.56.4
Rich 13.7.1

Python

Name Value
Version 3.11.9
Implementation CPython
Compiler GCC 13.2.0
Executable ~/whatever/venv/bin/python3

Operating System

Name Value
System Linux
Release 6.7.9-amd64
Version #1 SMP PREEMPT_DYNAMIC Debian 6.7.9-2 (2024-03-13)

Terminal

Name Value
Terminal Application tmux (3.4)
TERM tmux-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=255, height=43
legacy_windows False
min_width 1
max_width 255
is_terminal False
encoding utf-8
max_height 43
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

xavierog added a commit to xavierog/moulti that referenced this issue Aug 9, 2024
This workaround was meant for Textualize/textual#4425
and is no longer necessary as Moulti now requires Textual >= 0.76.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant