Skip to content

Commit 6842c30

Browse files
committed
Fix layout issues.
1 parent d1c9919 commit 6842c30

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

src/netbook/_cell.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ def to_nbformat(self) -> nbformat.NotebookNode:
9494
return nbformat.v4.new_output(output_type="stream", name=self.stream_name, text=self.text)
9595

9696
def compose(self) -> tp.Iterable[textual.widgets.Widget]:
97-
with textual.containers.HorizontalScroll():
98-
yield textual.widgets.Static(self.ansi_to_rich(self.text))
97+
yield textual.widgets.Static(self.ansi_to_rich(self.text))
9998

10099

101100
class DisplayData(Output):
@@ -117,24 +116,23 @@ def _find_image(self):
117116
return None
118117

119118
def compose(self) -> tp.Iterable[textual.widgets.Widget]:
120-
with textual.containers.HorizontalScroll():
121-
image_key = self._find_image()
122-
if image_key:
123-
image_bytes = (
124-
pyvips.Image.svgload_buffer(self.data[image_key].encode()).pngsave_buffer()
125-
if image_key == "image/svg+xml"
126-
else base64.b64decode(self.data[image_key])
127-
)
128-
image = self.app.image_class(io.BytesIO(image_bytes))
129-
# We'll set the width/height explicitly since automatically setting it seems hard / impossible.
130-
cell_size = textual_image.widget.get_cell_size()
131-
image.styles.width = round(image._image_width / cell_size.width)
132-
image.styles.height = round(image._image_height / cell_size.height)
133-
yield image
134-
elif self.data.get("text/markdown"):
135-
yield textual.widgets.Markdown(self.data["text/markdown"])
136-
elif self.data.get("text/plain"):
137-
yield textual.widgets.Static(self.ansi_to_rich(self.data["text/plain"]))
119+
image_key = self._find_image()
120+
if image_key:
121+
image_bytes = (
122+
pyvips.Image.svgload_buffer(self.data[image_key].encode()).pngsave_buffer()
123+
if image_key == "image/svg+xml"
124+
else base64.b64decode(self.data[image_key])
125+
)
126+
image = self.app.image_class(io.BytesIO(image_bytes))
127+
# We'll set the width/height explicitly since automatically setting it seems hard / impossible.
128+
cell_size = textual_image.widget.get_cell_size()
129+
image.styles.width = round(image._image_width / cell_size.width)
130+
image.styles.height = round(image._image_height / cell_size.height)
131+
yield image
132+
elif self.data.get("text/markdown"):
133+
yield textual.widgets.Markdown(self.data["text/markdown"])
134+
elif self.data.get("text/plain"):
135+
yield textual.widgets.Static(self.ansi_to_rich(self.data["text/plain"]))
138136

139137

140138
class ExecuteResult(DisplayData):
@@ -165,8 +163,7 @@ def to_nbformat(self) -> nbformat.NotebookNode:
165163
)
166164

167165
def compose(self) -> tp.Iterable[textual.widgets.Widget]:
168-
with textual.containers.HorizontalScroll():
169-
yield textual.widgets.Static(rich.text.Text.from_ansi("\n".join(self.traceback)))
166+
yield textual.widgets.Static(rich.text.Text.from_ansi("\n".join(self.traceback)))
170167

171168

172169
class Cell(textual.containers.Container, can_focus=True):

src/netbook/netbook.css

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ Cell {
5959
}
6060

6161
Output {
62-
min-width: 1fr;
63-
width: auto;
62+
width: 1fr;
6463
&.stderr {
6564
background: maroon;
6665
}
66+
overflow: auto;
6767
}
6868

6969
Counter {
@@ -161,15 +161,6 @@ Cell {
161161
max-height: 18;
162162
Horizontal {
163163
width: auto;
164-
min-width: 1fr;
165-
}
166-
Vertical {
167-
width: auto;
168-
min-width: 1fr;
169-
}
170-
HorizontalScroll {
171-
width: auto;
172-
min-width: 1fr;
173164
}
174165
}
175166
}

0 commit comments

Comments
 (0)