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

library: Add Scale entry #204

Merged
merged 7 commits into from Mar 8, 2023
Merged

library: Add Scale entry #204

merged 7 commits into from Mar 8, 2023

Conversation

SoNiC-HeRE
Copy link
Contributor

Added Scale Entry under User Interface Section in Library
Issue workbenchdev/demos#3

Copy link
Contributor

@sonnyp sonnyp left a comment

Choose a reason for hiding this comment

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

I think we should add a vertical example and have one of them with draw-value: true

Let's use the UI panel whenever possible. I know it's not obvious but you can do most of this directly from there , hopefully Workbench will make that more obvious to new developers.

example:

    Scale one {
      orientation: horizontal;
      margin-bottom: 20;
      adjustment: Gtk.Adjustment {
        lower: 0;
        upper: 100;
        value: 70;
      };
    }


Adw.StatusPage {
title: "Scale";
description: _("A simple sliding control");
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's not a very common control I think we can be a bit more descriptive

Suggested change
description: _("A simple sliding control");
description: _("Slider control to select a value from a range");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Comment on lines 28 to 49
LinkButton {
label: "Tutoral";
uri: "https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-scale-widgets.html.en";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if the current tutorial doesn't have an entry for slider - let's remove this link


scale_two.set_range(true, 50);
scale_two.set_inverted(true);
scale_two.add_mark(10.0, "right", null);
Copy link
Contributor

Choose a reason for hiding this comment

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

"right" doesn't work

also since this is a horizontal slider - let's use bottom

it should be Gtk.PositionType.BOTTOM for the second argument

scale_two.add_mark(20.0, "right", null);
scale_two.add_mark(30.0, "right", null);
scale_two.add_mark(40.0, "right", null);
scale_two.add_mark(50.0, "right", null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think 2 or 3 marks are enough

can you add labels to them? I'd suggest letters "A", "B", ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll add 2 marks with labels

scale_disabled.set_value(25);
scale_disabled.set_show_fill_level(25);

scale_one.connect("value_changed", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
scale_one.connect("value_changed", () => {
scale_one.connect("value-changed", () => {

const scale_two = workbench.builder.get_object("two");
const scale_disabled = workbench.builder.get_object("disabled");

scale_one.set_range(true, 50);
Copy link
Contributor

Choose a reason for hiding this comment

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

set_range takes 2 numbers

scale_one.set_range(true, 50);

scale_two.set_range(true, 50);
scale_two.set_inverted(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

invertedis verty unusual - I think we can leave it out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

Comment on lines 22 to 21
if (scale_value === 50) {
console.log("Max Value Reached");
} else if (scale_value === 1) {
console.log("Min Value Reached");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a good idea but instead of repeating please retrieve the min and max value directly from the object

you can do so with scale_one.adjustment.lower and upper

Comment on lines 29 to 35
scale_two.connect("value_changed", () => {
let scale_value_two = scale_two.get_value();
if (scale_value_two === 50) {
console.log("Max Value Reached");
} else if (scale_value_two === 1) {
console.log("Min Value Reached");
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need the same example a second time

maybe print the current value instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@SoNiC-HeRE
Copy link
Contributor Author

Applied the Changes as Suggested , Implemented a Vertical Slider and stuck to a 3 slider layout for cleaner UI. Implemented 4 marks on the Vertical Slider and Updated JS Code

@SoNiC-HeRE SoNiC-HeRE requested a review from sonnyp March 6, 2023 19:42
Copy link
Contributor

@sonnyp sonnyp left a comment

Choose a reason for hiding this comment

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

not building/working

please review your own changes before submitting for review

scale_two.add_mark(100.0, "right", "D");
scale_two.set_increments(25.0, 25.0);

scale_disabled.set_show_fill_level(25);
Copy link
Contributor

Choose a reason for hiding this comment

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

set_show_fill_level takes a boolean, not an integer
makes sure that you're using the APIs correctly—not just that things work

also show-fille-level is a property so it can be moved to main.blp if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I'll move it to main.blp

scale_one.connect("value-changed", () => {
let scale_value = scale_one.get_value();
if (scale_value === scale_one.adjustment.upper) {
console.log("Max Value Reached");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log("Max Value Reached");
console.log("Maximum value reached");

if (scale_value === scale_one.adjustment.upper) {
console.log("Max Value Reached");
} else if (scale_value === scale_one.adjustment.lower) {
console.log("Min Value Reached");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log("Min Value Reached");
console.log("Minimum value reached");

Comment on lines 5 to 8
scale_two.add_mark(25.0, "left", "A");
scale_two.add_mark(50.0, "right", "B");
scale_two.add_mark(75.0, "right", "C");
scale_two.add_mark(100.0, "right", "D");
Copy link
Contributor

Choose a reason for hiding this comment

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

ha yes - Blueprint doesn't support marks unfortunaly so we have to do it in JS

https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/62

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already in JS. So shall i leave it unchanged?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes - it's good as is

Comment on lines 22 to 33
scale_two.connect("value-changed", () => {
let scale_value_two = scale_two.get_value();
if (scale_value_two === 25) {
console.log("Mark A Reached");
} else if (scale_value_two === 50) {
console.log("Mark B Reached");
} else if (scale_value_two === 75) {
console.log("Mark C Reached");
} else if (scale_value_two === 100) {
console.log("Mark D Reached");
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of repeating the mark values - please create them and find them from the same values.

For example - store the marks in an object and use that to add the marks and find the label in value-chaged


Scale one {
orientation: horizontal;
margin-bottom: 20;
Copy link
Contributor

@sonnyp sonnyp Mar 7, 2023

Choose a reason for hiding this comment

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

please use multiples of 6 for margins paddings and so on

it's the GNOME guideline

6, 12, 18, 24, etc

@SoNiC-HeRE
Copy link
Contributor Author

Applied Suggested Changes: Updated JS Code and implemented Changes in Blp File as well.

Copy link
Contributor

@sonnyp sonnyp left a comment

Choose a reason for hiding this comment

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

Thanks.

Regarding marks, this is what I meant: 4f8e9c5

@sonnyp sonnyp merged commit 59e12f2 into workbenchdev:main Mar 8, 2023
sonnyp pushed a commit to SoNiC-HeRE/Workbench that referenced this pull request Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants