Add padding to content container, maximize window on wide screen.

This commit is contained in:
Sudo-Ivan
2025-05-28 22:46:22 -05:00
parent 791641c3c4
commit 17f4930878
2 changed files with 32 additions and 8 deletions

View File

@@ -14,7 +14,8 @@ class TabsManager:
self.manager = SimpleNamespace(tabs=[], index=0)
# UI components
self.tab_bar = ft.Row(spacing=4)
self.content_container = ft.Container(expand=True)
# Add padding inside content area to avoid text touching the border
self.content_container = ft.Container(expand=True, bgcolor=ft.Colors.BLACK, padding=ft.padding.all(10))
# Initialize with default "Home" tab only, using selected renderer
default_content = render_micron("Welcome to Ren Browser") if app_module.RENDERER == "micron" else render_plaintext("Welcome to Ren Browser")
@@ -32,12 +33,11 @@ class TabsManager:
# Create per-tab URL bar and GO button
url_field = ft.TextField(label="URL", value=title, expand=True)
go_btn = ft.IconButton(ft.Icons.OPEN_IN_BROWSER, tooltip="Load URL", on_click=lambda e, i=idx: self._on_tab_go(e, i))
# Wrap the content in a Column: URL bar + initial content
# Wrap the content in a Column: initial content only (URL bar is handled externally)
content_control = content
tab_content = ft.Column(
expand=True,
controls=[
ft.Row([url_field, go_btn]),
content_control,
],
)
@@ -45,6 +45,7 @@ class TabsManager:
self.manager.tabs.append({
"title": title,
"url_field": url_field,
"go_btn": go_btn,
"content_control": content_control,
"content": tab_content,
})
@@ -110,7 +111,8 @@ class TabsManager:
import ren_browser.app as app_module
new_control = render_micron(placeholder_text) if app_module.RENDERER == "micron" else render_plaintext(placeholder_text)
tab["content_control"] = new_control
tab["content"].controls[1] = new_control
# Replace the content control in the tab's Column
tab["content"].controls[0] = new_control
# Refresh the displayed content if this tab is active
if self.manager.index == idx:
self.content_container.content = tab["content"]

View File

@@ -16,8 +16,8 @@ def build_ui(page: Page):
page.theme_mode = ft.ThemeMode.DARK
page.appbar = ft.AppBar(title=ft.Text("Ren Browser"))
page.padding = 20
page.window_width = 800
page.window_height = 600
# Maximize window for wide screens
page.window.maximized = True
# Initialize page fetcher and announce service
page_fetcher = PageFetcher()
@@ -59,7 +59,7 @@ def build_ui(page: Page):
new_control = render_plaintext(result)
tab["content_control"] = new_control
# Replace the content control in the tab's column
tab["content"].controls[1] = new_control
tab["content"].controls[0] = new_control
if tab_manager.manager.index == idx:
tab_manager.content_container.content = tab["content"]
page.update()
@@ -85,11 +85,33 @@ def build_ui(page: Page):
# Dynamic tabs manager for pages
tab_manager = TabsManager(page)
Shortcuts(page, tab_manager)
# Main area: tab bar and content
url_bar = ft.Row(
controls=[
tab_manager.manager.tabs[tab_manager.manager.index]["url_field"],
tab_manager.manager.tabs[tab_manager.manager.index]["go_btn"],
],
)
orig_select_tab = tab_manager.select_tab
def _select_tab_and_update_url(i):
orig_select_tab(i)
tab = tab_manager.manager.tabs[i]
url_bar.controls.clear()
url_bar.controls.extend([tab["url_field"], tab["go_btn"]])
page.update()
tab_manager.select_tab = _select_tab_and_update_url
def _update_content_width(e=None):
# Use page.width for current content width
width = page.width - (page.padding * 2)
if width < 0:
width = 0
tab_manager.content_container.width = width
_update_content_width()
page.on_resized = lambda e: (_update_content_width(), page.update())
main_area = ft.Column(
expand=True,
controls=[
tab_manager.tab_bar,
url_bar,
tab_manager.content_container,
],
)