NimarkoGram Docs
RU
Docs/Settings subpages

Settings subpages

Group related preferences on a separate screen.

On this pageGroup display preferencesWhen the rows are builtCheck persistence

Group display preferences

When a plugin grows several related fields, give them a dedicated screen. Start with the first plugin and replace its class with the definition below, keeping the metadata. The root screen shows one Display row. Tapping the row opens two preferences.

Python
from base_plugin import BasePlugin
from ui.settings import Selector, Switch, Text

class Appearance(BasePlugin):
    def create_settings(self):
        return [Text(text="Display",
                     create_sub_fragment=self.display_rows)]

    def display_rows(self):
        return [
            Switch(key="show_author", text="Show author", default=True),
            Selector(key="density", text="Density", default=0,
                     items=["Normal", "Compact"]),
        ]

When the rows are built

Pass a no-argument function to create_sub_fragment. The client calls it when opening the subpage and receives a fresh list of rows. This lets you build fields from the current plugin state. Move a slow data read to a background job so opening the screen stays responsive.

Check persistence

Select Compact and turn off the author field. Go back one screen and reopen Display. In plugin code, self.get_setting("density", 0) should return 1 and self.get_setting("show_author", True) should return False. Keys belong to the plugin. Two subpages using density edit the same preference. Give them different keys if each page needs an independent choice.