Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add trait to get layout anchors for a view #108

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

Isaac-Leonard
Copy link

@Isaac-Leonard Isaac-Leonard commented Sep 10, 2023

Add trait to get layout anchors for a view, implement it on common components and add some functions that make use of it to simplify creating layout constraints

@Isaac-Leonard Isaac-Leonard changed the title Add trait to get layout anchors for a view, implement it on common co… Add trait to get layout anchors for a view Sep 10, 2023
@Isaac-Leonard
Copy link
Author

I've put all the implementations and functions that make use of it all in one file for now, I think they'd probably be better off in each components file but this is probably easier to see what I'm intending for now.
I'm wondering too if there might be a way to add a default for each method that gets the view id and creates the anchors from that like how they are constructed initially each component.

@ryanmcgrath
Copy link
Owner

So I think this is a gray area for me... it's definitely getting outside of what AppKit/UIKit offer by default, but cacao's taken the opinionated position before so I could be convinced to support this.

I would say a few changes come to mind tho:

  • The layout anchor getters could probably be safely thrown onto the Layout trait without much issue, to reduce trait importing (mental) overhead.

  • top_to_bottom would be improved (IMO) with the following api:

pub struct ColumnLayout {
    pub spacing: usize // psuedocode, do whatever type here
}

pub fn column<I, C>(parent: &Layout, layout: ColumnLayout, children: I)
where
    I:  IntoIterator<Item = &C>,
    C: Layout,
{
    // Manage adding views, setting spacing, etc
}

This feels more declarative in nature to me, e.g I could then write:

impl MyGenericView {
    pub fn build(&self) {
        column(&self.view_handle, ColumnLayout {
            spacing: 8
        }, [
            &self.child_view_1,
            &self.child_view_2,
            // etc
        ]);
    }
}

The above is all pseudocode and not tested but hopefully showcases the idea.

fill_safe_area I'm less enthused about and might want that in a contrib or helpers module, but I'll muse on that one for a bit.

@Isaac-Leonard
Copy link
Author

Isaac-Leonard commented Sep 15, 2023 via email

@ryanmcgrath
Copy link
Owner

Hmm, interesting.

FYI this might be a thing you'll need to rebase since we merged the objc2 PR recently. Apologies for the hassle but it should overall be better for the library going forward. :(

…mponents and add some functions that make use of it to simplify creating layout constraints
@Isaac-Leonard
Copy link
Author

Hey, not sure if its just me but I can't seem to get a bunch of warnings and errors when running cargo +nightly clippy and warnings with cargo check and build:
Here's the start of the clippy output:
warning: error reading Clippy's configuration file: deprecated field cyclomatic-complexity-threshold. Please use cognitive-complexity-threshold instead
--> /Users/isaac/Programming/rust/cacao-fork/clippy.toml:1:1
|
1 | cyclomatic-complexity-threshold = 30
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: cacao (build script) generated 1 warning
Compiling cacao v0.4.0-beta2 (/Users/isaac/Programming/rust/cacao-fork)
warning: unnecessary parentheses around match arm expression
--> src/appkit/app/enums.rs:122:49
|
122 | PresentationOption::AutoHideDock => (1 << 0),
| ^ ^
|
= note: #[warn(unused_parens)] on by default
help: remove these parentheses
|
122 - PresentationOption::AutoHideDock => (1 << 0),
122 + PresentationOption::AutoHideDock => 1 << 0,
|

Am I doing something wrong o might there be an issue with my set up?

…nction

Acked-by: Isaac Leonard <isaac.mjs.leonard@gmail.com>
@ryanmcgrath
Copy link
Owner

Offhand I dunno - but if that's deprecated the replacement does the same thing, we can certainly just swap the key out.

@Isaac-Leonard
Copy link
Author

There's 51 warnings with cargo check and over 100 with clippy though, is just an issue on my system or is it with the repo?
I'm happy to go through and fix them if the latter

Note the api has been reworked.
The get_from_backing_obj() method has been changed to get_backing_obj
and now returns a Ref to the Object rather then calling a callback
with it.
This is because there was no way to make the callback method work
without generics but we can't have generics if we want to make it
object safe
@Isaac-Leonard
Copy link
Author

Okay, so I think I've implemented everything now that's needed to use Layout as a dye trait.
I had to create a new trait for the set_frame method as I didn't really know how that could work without generics, I updated the frame example with the change.
I had to change how ObjcAccess works too as the get_from_backing_obj method couldn't work without the generic return type.
Instead I've made a new method that just returns the reference to the inner Id that callers can then just dereference and do what they were doing before.
I'm not sure if I've be putting Shared or Owned for the ownership generic of Id though, for now I've just got Owned.
I've also not had any experience with objective C so I'm not sure if I'm creating layout anchors correctly,.
I'm creating them the same way its done in the constructor for view but not sure if this creates non-allowed duplicates or anything.
I believe all of these changes may allow me to implement a more reactive framework on top of cacao too now.

@ryanmcgrath
Copy link
Owner

ryanmcgrath commented Sep 16, 2023 via email

@Isaac-Leonard
Copy link
Author

No no, stuff I've been working on in my own project was also leading down this route, either way I was probably going to fork and do something similar.

@Isaac-Leonard
Copy link
Author

I've started working on a framework of sorts based on the changes I've made:
https://github.com/Isaac-Leonard/cacao_framework
Currently have a simple counter button working though you need to pass the click id through to it from the top of the app.
I'm going to try make this work with more native components, write a macro to simplify specifying options and let it render nested components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants