[haiku-bugs] Re: [Haiku] #7447: *LayoutBuilder::DefaultInsets()

  • From: "yourpalal" <trac@xxxxxxxxxxxx>
  • Date: Sat, 04 Jun 2011 16:32:33 -0000

#7447: *LayoutBuilder::DefaultInsets()
----------------------------------+----------------------------
   Reporter:  jonas.kirilla       |      Owner:  yourpalal
       Type:  enhancement         |     Status:  assigned
   Priority:  normal              |  Milestone:  R1
  Component:  Kits/Interface Kit  |    Version:  R1/Development
 Resolution:                      |   Keywords:
 Blocked By:                      |   Blocking:
Has a Patch:  0                   |   Platform:  All
----------------------------------+----------------------------

Comment (by yourpalal):

 Firstly, sorry to perform ticket-necromancy, but I'd like to tackle this
 now :)

 Replying to [comment:5 bonefish]:
 > Replying to [comment:4 jonas.kirilla]:
 > > Yes, some shorthand for BControlLook-based insets. (But I'm not sure
 if the item spacing BControlLook provides applies to insets.)
 >
 > Maybe a set of constants for different inset situations could be defined
 and `BControlLook` could provide the respective inset values. Maybe that
 even depends on the kind of frame around the inset area.

 This is the idea I would like to go with, much like the current
 B_USE_DEFAULT_SPACING.
 For the record, the reason that constant has such a name, is that it can
 be passed to a spacing function or an inset function, and is equivalent to
 using be_control_look->DefaultItemSpacing(). I put the 'USE' in the name
 to distinguish the fact that it is a symbolic constant (-2 or something),
 not the actual spacing. The [https://dev.haiku-
 os.org/browser/haiku/trunk/src/kits/interface/ControlLook.cpp#L54
 BControlLook::ComposeItemSpacing()] method will be extended (and renamed
 to ComposeSpacing()) to support the new constants.

 > > There are some uses of
 (BTwoDimensionalLayout::)SetInsets(B_USE_DEFAULT_SPACING,
 B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) which
 could perhaps be helped by a single-argument version - SetInsets(float
 side) - or a no-argument version.

 B_USE_DEFAULT_SPACING should probably be renamed, maybe to
 B_USE_ITEM_SPACING.

 > Yep, a single argument version of SetInsets() can certainly be added for
 convenience to both BTwoDimensionalLayout and the builders and also a
 version with two arguments (horizontal/vertical). I'm not in favor of a
 no-argument version, as it is not clear what inset values it would set.

 This is the other portion of the strategy I would like to use. 3 versions
 of SetInsets(): 4 arguments, 2 arguments, 1 argument.

 > > Perhaps a BInsets class, grouping a quad of floats, sort of BRect-
 like, defaulting to non-zero values?
 >
 > Introducing a BInsets class is possible (since the layout management API
 was inspired by Java's I considered it back then), but not for this
 purpose. We should introduce such class only, if we decide that it is
 passed around and used enough to improve convenience. I didn't add it,
 because it turned out that there were really only the `{Set,Get}Insets()`
 methods where it would have been used.
 >
 > > (Or one could make the layout classes default to non-zero insets. I
 don't know what makes the most sense.)
 >
 > Indeed. :-) The default constructor should initialize the object to 0
 insets. Global constants or getters (e.g. in BControlLook) could be added
 to provide insets for different situations. That's also what should be
 analyzed first: What are the situations and how do we want to provide the
 insets? Whether a BInsets class is introduced can be decided when that is
 clearer.

 I think that for now, the insets will need to remain defaulted to 0. This
 is assumed all over the place in our repo, and is actually a pretty sane
 default. Here's what I'm thinking for different spacing constants:
 * B_USE_ITEM_SPACING
 * B_USE_HALF_ITEM_SPACING (this is a common use case I have seen in our
 tree)
 * B_USE_WINDOW_INSETS (INSETS because this shouldn't be used from spacing
 between items)
 * B_USE_SMALL_SPACING
 * B_USE_BIG_SPACING

 I don't know how we would choose values the SMALL/BIG spacing, but it
 could be nice to offer a bit of consistency to developers. For now, they
 could be some multiple of be_control_look->DefaultItemSpacing(). The
 values these constants map to will all be available from BControlLook as
 well.

 As for a BInsets class, I don't think this is required. I don't really see
 it being very useful, and if some developer really wants to use something
 like that, it would be trivial to write a template method that called
 SetInsets() on some object with the values from a BRect.

 Anyway, if nobody objects, I'll implement this in a day or two.

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/7447#comment:6>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: