Esempio n. 1
0
 def position_window_in_grid_cell(window_idx: int, xl: LayoutData,
                                  yl: LayoutData) -> None:
     wg = groups[window_idx]
     edges = Edges(wg.decoration('left'), wg.decoration('top'),
                   wg.decoration('right'), wg.decoration('bottom'))
     xl = layout(xl, lgd.cell_width, edges.left, edges.right)
     yl = layout(yl, lgd.cell_height, edges.top, edges.bottom)
     self.set_window_group_geometry(wg, xl, yl)
Esempio n. 2
0
def borders(data: Iterable[Tuple[WindowGroup, LayoutData, LayoutData]],
            is_horizontal: bool,
            all_windows: WindowList,
            start_offset: int = 1,
            end_offset: int = 1) -> Generator[BorderLine, None, None]:
    borders: List[BorderLine] = []
    active_group = all_windows.active_group
    needs_borders_map = all_windows.compute_needs_borders_map(
        lgd.draw_active_borders)
    try:
        bw = next(all_windows.iter_all_layoutable_groups()).effective_border()
    except StopIteration:
        bw = 0
    if not bw:
        return

    for wg, xl, yl in data:
        if is_horizontal:
            e1 = Edges(xl.content_pos - xl.space_before,
                       yl.content_pos - yl.space_before,
                       xl.content_pos - xl.space_before + bw,
                       yl.content_pos + yl.content_size + yl.space_after)
            e2 = Edges(xl.content_pos + xl.content_size + xl.space_after - bw,
                       yl.content_pos - yl.space_before,
                       xl.content_pos + xl.content_size + xl.space_after,
                       yl.content_pos + yl.content_size + yl.space_after)
        else:
            e1 = Edges(xl.content_pos - xl.space_before,
                       yl.content_pos - yl.space_before,
                       xl.content_pos + xl.content_size + xl.space_after,
                       yl.content_pos - yl.space_before + bw)
            e2 = Edges(xl.content_pos - xl.space_before,
                       yl.content_pos + yl.content_size + yl.space_after - bw,
                       xl.content_pos + xl.content_size + xl.space_after,
                       yl.content_pos + yl.content_size + yl.space_after)
        color = BorderColor.inactive
        if needs_borders_map.get(wg.id):
            color = BorderColor.active if wg is active_group else BorderColor.bell
        borders.append(BorderLine(e1, color))
        borders.append(BorderLine(e2, color))

    last_idx = len(borders) - 1 - end_offset
    for i, x in enumerate(borders):
        if start_offset <= i <= last_idx:
            yield x
Esempio n. 3
0
        def borders_for_window(gid: int) -> Generator[Edges, None, None]:
            xl, yl = layout_data_map[gid]
            left, right = ends(xl)
            top, bottom = ends(yl)
            first_row, last_row = gid in is_first_row, gid in is_last_row
            first_column, last_column = gid in is_first_column, gid in is_last_column

            # Horizontal
            if not first_row:
                yield Edges(left, top, right, top + bw)
            if not last_row:
                yield Edges(left, bottom - bw, right, bottom)

            # Vertical
            if not first_column:
                yield Edges(left, top, left + bw, bottom)
            if not last_column:
                yield Edges(right - bw, top, right, bottom)
Esempio n. 4
0
def window_geometry(xstart: int, xnum: int, ystart: int, ynum: int, left: int,
                    top: int, right: int, bottom: int) -> WindowGeometry:
    return WindowGeometry(left=xstart,
                          top=ystart,
                          xnum=xnum,
                          ynum=ynum,
                          right=xstart + lgd.cell_width * xnum,
                          bottom=ystart + lgd.cell_height * ynum,
                          spaces=Edges(left, top, right, bottom))
Esempio n. 5
0
    def minimal_borders(
            self,
            all_windows: WindowList) -> Generator[BorderLine, None, None]:
        num = all_windows.num_groups
        if num < 2 or not lgd.draw_minimal_borders:
            return
        try:
            bw = next(
                all_windows.iter_all_layoutable_groups()).effective_border()
        except StopIteration:
            bw = 0
        if not bw:
            return
        if num <= self.num_full_size_windows + 1:
            layout = (x[:3] for x in self.simple_layout(all_windows))
            yield from borders(layout, self.main_is_horizontal, all_windows)
            return
        main_layouts: List[Tuple[WindowGroup, LayoutData, LayoutData]] = []
        perp_borders: List[BorderLine] = []
        layouts = (self.simple_layout if num <= self.num_full_size_windows else
                   self.full_layout)(all_windows)
        needs_borders_map = all_windows.compute_needs_borders_map(
            lgd.draw_active_borders)
        active_group = all_windows.active_group
        mirrored = self.layout_opts.mirrored
        for wg, xl, yl, is_full_size in layouts:
            if is_full_size:
                main_layouts.append((wg, xl, yl))
            else:
                color = BorderColor.inactive
                if needs_borders_map.get(wg.id):
                    color = BorderColor.active if wg is active_group else BorderColor.bell
                if self.main_is_horizontal:
                    e1 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos - yl.space_before,
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos - yl.space_before + bw)
                    e3 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos + yl.content_size + yl.space_after - bw,
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                    e2 = Edges(
                        xl.content_pos +
                        ((xl.content_size + xl.space_after -
                          bw) if mirrored else -xl.space_before),
                        yl.content_pos - yl.space_before,
                        xl.content_pos +
                        ((xl.content_size + xl.space_after) if mirrored else
                         (bw - xl.space_before)),
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                else:
                    e1 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos - yl.space_before,
                        xl.content_pos - xl.space_before + bw,
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                    e3 = Edges(
                        xl.content_pos + xl.content_size + xl.space_after - bw,
                        yl.content_pos - yl.space_before,
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                    e2 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos +
                        ((yl.content_size + yl.space_after -
                          bw) if mirrored else -yl.space_before),
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos +
                        ((yl.content_size + yl.space_after) if mirrored else
                         (bw - yl.space_before)),
                    )
                perp_borders.append(BorderLine(e1, color))
                perp_borders.append(BorderLine(e2, color))
                perp_borders.append(BorderLine(e3, color))

        mirrored = self.layout_opts.mirrored
        yield from borders(main_layouts,
                           self.main_is_horizontal,
                           all_windows,
                           start_offset=int(not mirrored),
                           end_offset=int(mirrored))
        yield from perp_borders[1:-1]
Esempio n. 6
0
 def layout_pair(self, left: int, top: int, width: int, height: int,
                 id_window_map: Dict[int, WindowGroup],
                 layout_object: Layout) -> None:
     self.between_borders = []
     self.left, self.top, self.width, self.height = left, top, width, height
     bw = self.effective_border(
         id_window_map) if lgd.draw_minimal_borders else 0
     border_mult = 0 if lgd.draw_minimal_borders else 1
     bw2 = bw * 2
     self.first_extent = self.second_extent = Extent()
     if self.one is None or self.two is None:
         q = self.one or self.two
         if isinstance(q, Pair):
             return q.layout_pair(left, top, width, height, id_window_map,
                                  layout_object)
         if q is None:
             return
         wg = id_window_map[q]
         xl = next(
             layout_object.xlayout(iter((wg, )),
                                   start=left,
                                   size=width,
                                   border_mult=border_mult))
         yl = next(
             layout_object.ylayout(iter((wg, )),
                                   start=top,
                                   size=height,
                                   border_mult=border_mult))
         geom = window_geometry_from_layouts(xl, yl)
         self.first_extent = Extent(left, left + width)
         self.apply_window_geometry(q, geom, id_window_map, layout_object)
         return
     if self.horizontal:
         w1 = max(2 * lgd.cell_width + 1, int(self.bias * width) - bw)
         w2 = max(2 * lgd.cell_width + 1, width - w1 - bw2)
         self.first_extent = Extent(max(0, left - bw), left + w1 + bw)
         self.second_extent = Extent(left + w1 + bw, left + width + bw)
         if isinstance(self.one, Pair):
             self.one.layout_pair(left, top, w1, height, id_window_map,
                                  layout_object)
         else:
             wg = id_window_map[self.one]
             yl = next(
                 layout_object.ylayout(iter((wg, )),
                                       start=top,
                                       size=height,
                                       border_mult=border_mult))
             xl = next(
                 layout_object.xlayout(iter((wg, )),
                                       start=left,
                                       size=w1,
                                       border_mult=border_mult))
             geom = window_geometry_from_layouts(xl, yl)
             self.apply_window_geometry(self.one, geom, id_window_map,
                                        layout_object)
         self.between_borders = [
             Edges(left + w1, top, left + w1 + bw, top + height),
             Edges(left + w1 + bw, top, left + w1 + bw2, top + height),
         ]
         left += bw2
         if isinstance(self.two, Pair):
             self.two.layout_pair(left + w1, top, w2, height, id_window_map,
                                  layout_object)
         else:
             wg = id_window_map[self.two]
             xl = next(
                 layout_object.xlayout(iter((wg, )),
                                       start=left + w1,
                                       size=w2,
                                       border_mult=border_mult))
             yl = next(
                 layout_object.ylayout(iter((wg, )),
                                       start=top,
                                       size=height,
                                       border_mult=border_mult))
             geom = window_geometry_from_layouts(xl, yl)
             self.apply_window_geometry(self.two, geom, id_window_map,
                                        layout_object)
     else:
         h1 = max(2 * lgd.cell_height + 1, int(self.bias * height) - bw)
         h2 = max(2 * lgd.cell_height + 1, height - h1 - bw2)
         self.first_extent = Extent(max(0, top - bw), top + h1 + bw)
         self.second_extent = Extent(top + h1 + bw, top + height + bw)
         if isinstance(self.one, Pair):
             self.one.layout_pair(left, top, width, h1, id_window_map,
                                  layout_object)
         else:
             wg = id_window_map[self.one]
             xl = next(
                 layout_object.xlayout(iter((wg, )),
                                       start=left,
                                       size=width,
                                       border_mult=border_mult))
             yl = next(
                 layout_object.ylayout(iter((wg, )),
                                       start=top,
                                       size=h1,
                                       border_mult=border_mult))
             geom = window_geometry_from_layouts(xl, yl)
             self.apply_window_geometry(self.one, geom, id_window_map,
                                        layout_object)
         self.between_borders = [
             Edges(left, top + h1, left + width, top + h1 + bw),
             Edges(left, top + h1 + bw, left + width, top + h1 + bw2),
         ]
         top += bw2
         if isinstance(self.two, Pair):
             self.two.layout_pair(left, top + h1, width, h2, id_window_map,
                                  layout_object)
         else:
             wg = id_window_map[self.two]
             xl = next(
                 layout_object.xlayout(iter((wg, )),
                                       start=left,
                                       size=width,
                                       border_mult=border_mult))
             yl = next(
                 layout_object.ylayout(iter((wg, )),
                                       start=top + h1,
                                       size=h2,
                                       border_mult=border_mult))
             geom = window_geometry_from_layouts(xl, yl)
             self.apply_window_geometry(self.two, geom, id_window_map,
                                        layout_object)
Esempio n. 7
0
class BorderLine(NamedTuple):
    edges: Edges = Edges()
    color: BorderColor = BorderColor.inactive