Layout::Manager(3pm)

πŸ“¦
version 0.35 Β· 2 versions
  • 0.35 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.35 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Layout::Manager ✨

okay bestie, welcome to Layout::Manager πŸ’… β€” it's a 2D layout management module, and it's living in the perl manual pages (specifically the User Contributed Perl Documentation section, section 3pm, iykyk). πŸŽ€


🌸 NAME 🌸

Layout::Manager β€” 2D Layout Management πŸ¦‹


🫢 SYNOPSIS 🫢

So like. Layout::Manager gives you a simple interface for building layout managers β€” and a layout manager is just a class that decides the size and position of components inside a container. That's the whole vibe. πŸ’–

A few managers ship with it as reference material, but lowkey the real point of this module is to be a base for outside implementations. It's giving scaffolding. It's giving blueprint. It's giving "here's the foundation, now go be the main character." πŸ‘‘

use Layout::Manager;

my $foo = Layout::Manager->new;
$foo->do_layout($component);

🌈 USING A LAYOUT MANAGER 🌈

Layout::Manager leans on Graphics::Primitive::Container as its source for components. That's the plug. πŸ”Œ

Different implementations of Layout::Manager will want you to add components with slightly different second arguments β€” annoying? maybe. iconic? also maybe β€” but the general case looks like this:

$lm->add_component($comp, $constraints);

What goes in $constraints?? bestie I cannot tell you, you have to read the documentation for the layout manager you're actually using. Every one is different, no cap. πŸ“–

The $comp argument, though, must be a Graphics::Primitive::Component. That one's non-negotiable.

Layout manager works hand-in-hand with Graphics::Primitive, so you're gonna wanna check out the lifecycle documented in Graphics::Primitive::Component. It'll look something like this:

$cont->add_component($foo, { some => metadata });
$driver->prepare($cont);
my $lm = new Layout::Manager::SomeImplementation;
$lm->do_layout($cont);
$driver->pack($cont);
$driver->draw($cont);

When you're ready to lay out your container, you call the do_layout method with a single argument: the component you're laying things out in. And by the time do_layout returns, all of the components should be resized and repositioned according to the rules of your Layout::Manager implementation. Slay. ✨

🧚 PREPARATION 🧚

Subsequent calls to do_layout will be ignored if the Container is prepared. πŸ›‘

The Container's prepared flag gets checked, and so do the flags of all its children β€” so literally any modification to any child component will cause the entire container (and any container children, yes, all of them, fr fr) to be laid out again. Cascading. Chaotic. That's the design. πŸ¦‹


πŸ’œ WRITING A LAYOUT MANAGER πŸ’œ

Layout::Manager hands you all the methods necessary for your implementation, except for one: the do_layout method. That's the one you write. It gets called when it's time to actually lay out the components. That's your moment. Your era. 🌟

The add_component method takes two arguments: the component, and a second, abritrary piece of data. (Yes, the original really does spell it that way β€” we don't fix typos here, we preserve them, that's the rule. 😭) If your layout manager is simple, like Compass, you might only need a simple variable like "NORTH". If you build something more complex, that second argument could be a hashref or an object. You do you. πŸ’…

The value of the components method is an arrayref of hashrefs. Those hashrefs have two keys:

  • component β€” the component to be laid out. πŸŽ€
  • args β€” the argument provided to add_component. πŸ“

πŸ”₯ TIPS πŸ”₯

Layout manager implementations should honor the visible attribute of a component β€” because those components need to be ignored. If it's not visible, it's not getting laid out. Periodt. πŸ™ˆ


πŸ‘‘ METHODS πŸ‘‘

do_layout

Lays out this manager's components in the specified container. That's it. That's the whole thing. ✨


🌸 AUTHOR 🌸

Cory Watson, "<gphat@cpan.org>" πŸ’–


⭐ SEE ALSO ⭐

perl(1), Graphics::Primitive πŸ¦‹


Copyright 2008 - 2010 Cory G Watson

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page bestie!! 🫢 this doc was generated by perl v5.34.0 on 2022-06-15, so if you're reading it from the future just know it's a vintage classic πŸ’…βœ¨ no cap, go lay out some components πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from