Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Allow to get Color from Analysis #168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

romanzes
Copy link

@romanzes romanzes commented Nov 8, 2019

The idea is to use it like this:

let attrs = analysis.extra_attrs();
for attr in attrs {
    let class = attr.get_attr_class();
    let attr_type = class.get_type();
    match attr_type {
        AttrType::Foreground => {
            let color_attr = pango::AttrColor::from(attr);
            let color = color_attr.get_color();
            println!("red color {:?}", color.red());
        }
        _ => {}
    }
}


impl PartialEq for AttrColor {
fn eq(&self, other: &AttrColor) -> bool {
self.0 == other.0
Copy link
Member

Choose a reason for hiding this comment

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

This should probably call pango_attr_equal()

And a Drop impl that calls pango_attr_destroy() should probably exist too, and a Clone impl that calls pango_attr_copy()

I think the attrs should probably be implemented like the patterns in cairo. The generic pango_attr API works on all of them and then there are "subclasses" of the generic PangoAttr type.

Copy link
Author

Choose a reason for hiding this comment

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

@sdroege would you be able to provide me with some links to the code that I could use as references? Especially to the patterns in cairo. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Take a look here: https://github.com/gtk-rs/cairo/blob/master/src/patterns.rs

There's a base Pattern type and specific struct FooPattern(Pattern) that provide specific API. Pattern impls Drop for memory management, and there are try_from() and deref() impls to get from one to another.

Copy link
Member

Choose a reason for hiding this comment

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

This still applies to the PR and requires some more work

Copy link
Member

Choose a reason for hiding this comment

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

@GuillaumeGomez See above, that's the main missing part here. Let's just defer that to a future release, it involves quite some work and figuring out a nice API. I wouldn't want to merge that just before a release but rather give people some time to try it first.

Copy link
Member

Choose a reason for hiding this comment

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

More like a Widgetand not Button. ;) From my point of view, we should merge this and implement what's left in the next release.

Copy link
Member

Choose a reason for hiding this comment

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

It's useless as it is and will only cause bug reports from people trying to figure out how to use it and not understanding :) And worst case we introduce a new actual bug here that slipped through the review.

I would rather wait until after the release, there's no advantage in having this in this release already and only the risk of introducing a new bug.

Copy link
Member

Choose a reason for hiding this comment

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

You mean except being able to create the attributes which we cannot currently? :p

It seems it's more of a "create and never modify" API from what I saw. So I guess it's mostly fine. Also, where could they get bugs? We don't access to anything...

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about this @EPashkin ?

Copy link
Member

Choose a reason for hiding this comment

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

Waiting for his opinion then :) Maybe I'm just a bit too strict here.

@GuillaumeGomez
Copy link
Member

Need a hand in here?

@sdroege sdroege mentioned this pull request Nov 29, 2019
43 tasks
Velislava Yanchina and others added 2 commits November 30, 2019 15:31
@GuillaumeGomez
Copy link
Member

Ok, I updated the code. The Attribute API is a nightmare...

use glib::translate::from_glib_full;
use glib::translate::ToGlib;
use glib::translate::ToGlibPtr;

impl Attribute {
#[cfg(any(feature = "v1_38", feature = "dox"))]
pub fn new_background_alpha(alpha: u16) -> Option<Attribute> {
Copy link
Member

Choose a reason for hiding this comment

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

This (and all the others too) should probably return an AttributeBackgrondAlpha?

Copy link
Member

Choose a reason for hiding this comment

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

No, it's all casted as Attribute in the source code. Also, it's not really supposed to be "used" so better not give access to the fields.

Copy link
Member

Choose a reason for hiding this comment

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

Ack

src/attribute.rs Outdated

pub fn new_weight(weight: Weight) -> Option<Attribute> {
unsafe { from_glib_full(pango_sys::pango_attr_weight_new(weight.to_glib())) }
}

pub fn get_attr_class(&self) -> AttrClass {
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Copy link
Member

Choose a reason for hiding this comment

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

Went too quickly I think... Putting it back!

}
}

pub fn get_end_index(&self) -> u32 {
Copy link
Member

Choose a reason for hiding this comment

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

These two getters at least seem useful, the setters maybe not

Copy link
Member

Choose a reason for hiding this comment

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

Indeed. Don't remember why I removed them...

let stash = self.to_glib_none_mut();
(*stash.0).end_index = index;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Should implement Clone via pango_attribute_copy(), Drop via pango_attribute_destroy(), PartialEq/Eq via pango_attribute_equal()

Copy link
Member

Choose a reason for hiding this comment

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

Look at the auto impl maybe?

Copy link
Member

Choose a reason for hiding this comment

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

Ah I thought there's only the manual impl of it. Ok then

@GuillaumeGomez
Copy link
Member

Updated.

@EPashkin
Copy link
Member

EPashkin commented Dec 2, 2019

I tried to look at code again after long time,
and now I can't find way to "get Color from Analysis" 😢
so I prefer postpone PR

@GuillaumeGomez
Copy link
Member

You can't, that's the whole point. But at least you can now create all available attributes.

@EPashkin
Copy link
Member

EPashkin commented Dec 2, 2019

Then maybe remove changes in analysis.rs and Gir.toml.
Or user can do something significant with Vec<Attribute>?

This we have constructors and minimal get/set for Attribute (API really strange)
and getters for PangoColor.

@sdroege
Copy link
Member

sdroege commented Dec 2, 2019

That's a good point. The PR as it is now does not even implement what the title says :)

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

Successfully merging this pull request may close these issues.

4 participants