cleanup and improve UI
This commit is contained in:
@@ -11,34 +11,25 @@ from ren_browser.tabs.tabs import TabsManager
|
|||||||
|
|
||||||
def build_ui(page: Page):
|
def build_ui(page: Page):
|
||||||
import ren_browser.app as app_module
|
import ren_browser.app as app_module
|
||||||
# Page properties
|
|
||||||
page.title = "Ren Browser"
|
|
||||||
page.theme_mode = ft.ThemeMode.DARK
|
page.theme_mode = ft.ThemeMode.DARK
|
||||||
page.appbar = ft.AppBar(title=ft.Text("Ren Browser"))
|
page.appbar = ft.AppBar()
|
||||||
page.padding = 20
|
page.padding = 20
|
||||||
# Maximize window for wide screens
|
|
||||||
page.window.maximized = True
|
page.window.maximized = True
|
||||||
|
|
||||||
# Initialize page fetcher and announce service
|
|
||||||
page_fetcher = PageFetcher()
|
page_fetcher = PageFetcher()
|
||||||
# Sidebar announces list in a scrollable ListView within a NavigationDrawer
|
|
||||||
announce_list = ft.ListView(expand=True, spacing=1)
|
announce_list = ft.ListView(expand=True, spacing=1)
|
||||||
def update_announces(ann_list):
|
def update_announces(ann_list):
|
||||||
announce_list.controls.clear()
|
announce_list.controls.clear()
|
||||||
for ann in ann_list:
|
for ann in ann_list:
|
||||||
label = ann.display_name or ann.destination_hash
|
label = ann.display_name or ann.destination_hash
|
||||||
# Use display_name for tab title, fallback to "Anonymous"; set URL bar to full path
|
|
||||||
def on_click_ann(e, dest=ann.destination_hash, disp=ann.display_name):
|
def on_click_ann(e, dest=ann.destination_hash, disp=ann.display_name):
|
||||||
title = disp or "Anonymous"
|
title = disp or "Anonymous"
|
||||||
# Full URL including page path
|
|
||||||
full_url = f"{dest}:/page/index.mu"
|
full_url = f"{dest}:/page/index.mu"
|
||||||
placeholder = render_plaintext(f"Fetching content for {full_url}")
|
placeholder = render_plaintext(f"Fetching content for {full_url}")
|
||||||
tab_manager._add_tab_internal(title, placeholder)
|
tab_manager._add_tab_internal(title, placeholder)
|
||||||
idx = len(tab_manager.manager.tabs) - 1
|
idx = len(tab_manager.manager.tabs) - 1
|
||||||
# Set URL bar to full URL
|
|
||||||
tab = tab_manager.manager.tabs[idx]
|
tab = tab_manager.manager.tabs[idx]
|
||||||
tab["url_field"].value = full_url
|
tab["url_field"].value = full_url
|
||||||
# Select the new tab and refresh UI
|
|
||||||
tab_manager.select_tab(idx)
|
tab_manager.select_tab(idx)
|
||||||
page.update()
|
page.update()
|
||||||
def fetch_and_update():
|
def fetch_and_update():
|
||||||
@@ -49,18 +40,15 @@ def build_ui(page: Page):
|
|||||||
import ren_browser.app as app_module
|
import ren_browser.app as app_module
|
||||||
app_module.log_error(str(ex))
|
app_module.log_error(str(ex))
|
||||||
result = f"Error: {ex}"
|
result = f"Error: {ex}"
|
||||||
# Skip update if tab has been closed or index out of range
|
|
||||||
try:
|
try:
|
||||||
tab = tab_manager.manager.tabs[idx]
|
tab = tab_manager.manager.tabs[idx]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return
|
return
|
||||||
# Use micron renderer for .mu pages, fallback to plaintext
|
|
||||||
if req.page_path.endswith(".mu"):
|
if req.page_path.endswith(".mu"):
|
||||||
new_control = render_micron(result)
|
new_control = render_micron(result)
|
||||||
else:
|
else:
|
||||||
new_control = render_plaintext(result)
|
new_control = render_plaintext(result)
|
||||||
tab["content_control"] = new_control
|
tab["content_control"] = new_control
|
||||||
# Replace the content control in the tab's column
|
|
||||||
tab["content"].controls[0] = new_control
|
tab["content"].controls[0] = new_control
|
||||||
if tab_manager.manager.index == idx:
|
if tab_manager.manager.index == idx:
|
||||||
tab_manager.content_container.content = tab["content"]
|
tab_manager.content_container.content = tab["content"]
|
||||||
@@ -69,24 +57,20 @@ def build_ui(page: Page):
|
|||||||
announce_list.controls.append(ft.TextButton(label, on_click=on_click_ann))
|
announce_list.controls.append(ft.TextButton(label, on_click=on_click_ann))
|
||||||
page.update()
|
page.update()
|
||||||
AnnounceService(update_callback=update_announces)
|
AnnounceService(update_callback=update_announces)
|
||||||
# Make sidebar collapsible via drawer
|
|
||||||
page.drawer = ft.NavigationDrawer(
|
page.drawer = ft.NavigationDrawer(
|
||||||
controls=[
|
controls=[
|
||||||
ft.Text("Announcements", weight=ft.FontWeight.BOLD),
|
ft.Text("Announcements", weight=ft.FontWeight.BOLD, text_align=ft.TextAlign.CENTER, expand=True),
|
||||||
ft.Divider(),
|
ft.Divider(),
|
||||||
announce_list,
|
announce_list,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
# Add hamburger button to toggle drawer
|
|
||||||
page.appbar.leading = ft.IconButton(
|
page.appbar.leading = ft.IconButton(
|
||||||
ft.Icons.MENU,
|
ft.Icons.MENU,
|
||||||
tooltip="Toggle sidebar",
|
tooltip="Toggle sidebar",
|
||||||
on_click=lambda e: (setattr(page.drawer, 'open', not page.drawer.open), page.update()),
|
on_click=lambda e: (setattr(page.drawer, 'open', not page.drawer.open), page.update()),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Dynamic tabs manager for pages
|
|
||||||
tab_manager = TabsManager(page)
|
tab_manager = TabsManager(page)
|
||||||
# Add Settings button using external settings module
|
|
||||||
from ren_browser.ui.settings import open_settings_tab
|
from ren_browser.ui.settings import open_settings_tab
|
||||||
page.appbar.actions = [ft.IconButton(ft.Icons.SETTINGS, tooltip="Settings", on_click=lambda e: open_settings_tab(page, tab_manager))]
|
page.appbar.actions = [ft.IconButton(ft.Icons.SETTINGS, tooltip="Settings", on_click=lambda e: open_settings_tab(page, tab_manager))]
|
||||||
Shortcuts(page, tab_manager)
|
Shortcuts(page, tab_manager)
|
||||||
@@ -95,6 +79,15 @@ def build_ui(page: Page):
|
|||||||
tab_manager.manager.tabs[tab_manager.manager.index]["url_field"],
|
tab_manager.manager.tabs[tab_manager.manager.index]["url_field"],
|
||||||
tab_manager.manager.tabs[tab_manager.manager.index]["go_btn"],
|
tab_manager.manager.tabs[tab_manager.manager.index]["go_btn"],
|
||||||
],
|
],
|
||||||
|
expand=True,
|
||||||
|
spacing=4,
|
||||||
|
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
||||||
|
)
|
||||||
|
page.appbar.title = ft.Container(
|
||||||
|
content=url_bar,
|
||||||
|
padding=ft.padding.only(top=3),
|
||||||
|
expand=True,
|
||||||
|
alignment=ft.alignment.center_left,
|
||||||
)
|
)
|
||||||
orig_select_tab = tab_manager.select_tab
|
orig_select_tab = tab_manager.select_tab
|
||||||
def _select_tab_and_update_url(i):
|
def _select_tab_and_update_url(i):
|
||||||
@@ -104,42 +97,16 @@ def build_ui(page: Page):
|
|||||||
url_bar.controls.extend([tab["url_field"], tab["go_btn"]])
|
url_bar.controls.extend([tab["url_field"], tab["go_btn"]])
|
||||||
page.update()
|
page.update()
|
||||||
tab_manager.select_tab = _select_tab_and_update_url
|
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(
|
main_area = ft.Column(
|
||||||
expand=True,
|
expand=True,
|
||||||
controls=[
|
controls=[tab_manager.tab_bar, tab_manager.content_container],
|
||||||
tab_manager.tab_bar,
|
|
||||||
url_bar,
|
|
||||||
tab_manager.content_container,
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Layout: main content only (sidebar in drawer)
|
|
||||||
layout = ft.Row(expand=True, controls=[main_area])
|
layout = ft.Row(expand=True, controls=[main_area])
|
||||||
|
|
||||||
# Render main layout with status
|
|
||||||
page.add(
|
page.add(
|
||||||
ft.Column(
|
ft.Column(
|
||||||
expand=True,
|
expand=True,
|
||||||
controls=[
|
controls=[layout],
|
||||||
layout,
|
|
||||||
ft.Row(
|
|
||||||
[
|
|
||||||
ft.Text(
|
|
||||||
f"Renderer: {app_module.RENDERER}",
|
|
||||||
color=ft.Colors.GREY,
|
|
||||||
size=12,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
alignment=ft.MainAxisAlignment.END,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user