Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Replace optional values with defaults when unset #21

Merged
merged 2 commits into from
Jun 5, 2023
Merged

Conversation

Eskaan
Copy link
Contributor

@Eskaan Eskaan commented Jun 5, 2023

As noted in the todo, you should now be able to leave out most of the config.

I will set this as ready in a few seconds, just need to test it (and with it the whole pr).

@Eskaan Eskaan marked this pull request as ready for review June 5, 2023 12:45
@Eskaan
Copy link
Contributor Author

Eskaan commented Jun 5, 2023

Current default config (click to expand)
// Full verbose version
(
  name: "Default",
  flip: None,
  rotate: North,
  reserve: None,
  columns: Columns(
    flip: None,
    rotate: North,
    main: Some(Main(
      count: 1,
      size: Ratio(0.5),
      flip: None,
      rotate: North,
      split: Some(Vertical),
    )),
    stack: Stack(
      flip: None,
      rotate: North,
      split: Some(Horizontal),
    ),
    second_stack: None,
  ),
)
// Full version (no `Some`)
(
  name: "Default",
  flip: None,
  rotate: North,
  reserve: None,
  columns: Columns(
    flip: None,
    rotate: North,
    main: Main(
      count: 1,
      size: Ratio(0.5),
      flip: None,
      rotate: North,
      split: Vertical,
    ),
    stack: Stack(
      flip: None,
      rotate: North,
      split: Horizontal,
    ),
    second_stack: None,
  ),
)

Here a screenshot:
(Only window order is relevant)

image

The #[serde(default) macro uses the Struct's Default implementation and uses them to add missing struct fields. This is also the reason why not all Options default to None but to the default for the field from the parent struct. I think this is a good solution.

This way, can also leave placeholders by specifying () for structs.
Here a config example with explanation:

layouts: [
  "Foo",
  "Default"
],
layout_definitions: [
  (
    name: "Foo",
    reserve: ReserveAndCenter,
    columns: (
        main: Main(size: 0.4, split: Horizontal),
        stack: (), // No values set => `Stack`s default impl is used on all fields
        second_stack: (split: Horizontal),
        // `rotate` is unset, columns' default impl for the `rotate` field is used
    )
  ),
  (), // No values set => default config (with name "Default")
],

@Eskaan Eskaan requested a review from hertg June 5, 2023 13:12
Copy link
Member

@hertg hertg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing it out! :)

@hertg hertg merged commit a344b3d into leftwm:main Jun 5, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants