from system.app import app_manager
from system.controls import ImageTextButton, View
from system.static import font_manager, settings

from .app_detail_view import AppDetailView


class AppListView(View):
    def __init__(self):
        super().__init__()

        button_font = font_manager.get_font(
            font_name=font_manager.default_font_name, font_size=100
        )

        app_num = 0
        for app in app_manager.app_list:
            self.add_control(
                ImageTextButton(
                    image=app_manager.app_list[app].image,
                    font=button_font,
                    layout=ImageTextButton.Layout.PictureLeft,
                    on_click_function=self._generate_switch_function(app),
                    position=(0, app_num * 200),
                    size=(settings.APPLICATION_SIZE[0], 200),
                    text=app_manager.app_list[app].display_name
                )
            )
            app_num += 1

    def _generate_switch_function(self, app: str):
        def _function():
            self.parent_app.set_view(AppDetailView(app))
        return _function

from system.app import app_manager
from system.controls import ImageTextButton, View
from system.static import font_manager, settings

from .app_detail_view import AppDetailView


class AppListView(View):
    def __init__(self):
        super().__init__()

        button_font = font_manager.get_font(
            font_name=font_manager.default_font_name, font_size=100
        )

        app_num = 0
        for app in app_manager.app_list:
            self.add_control(
                ImageTextButton(
                    image=app_manager.app_list[app].image,
                    font=button_font,
                    layout=ImageTextButton.Layout.PictureLeft,
                    on_click_function=self._generate_switch_function(app),
                    position=(0, app_num * 200),
                    size=(settings.APPLICATION_SIZE[0], 200),
                    text=app_manager.app_list[app].display_name
                )
            )
            app_num += 1

    def _generate_switch_function(self, app: str):
        def _function():
            self.parent_app.set_view(AppDetailView(app))
        return _function
