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
Conversation
There was a problem hiding this 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;
};
}
src/Library/demos/Scale/main.blp
Outdated
|
||
Adw.StatusPage { | ||
title: "Scale"; | ||
description: _("A simple sliding control"); |
There was a problem hiding this comment.
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
description: _("A simple sliding control"); | |
description: _("Slider control to select a value from a range"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/Library/demos/Scale/main.blp
Outdated
LinkButton { | ||
label: "Tutoral"; | ||
uri: "https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-scale-widgets.html.en"; | ||
} |
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
|
||
scale_two.set_range(true, 50); | ||
scale_two.set_inverted(true); | ||
scale_two.add_mark(10.0, "right", null); |
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
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); |
There was a problem hiding this comment.
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", ...
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
scale_disabled.set_value(25); | ||
scale_disabled.set_show_fill_level(25); | ||
|
||
scale_one.connect("value_changed", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scale_one.connect("value_changed", () => { | |
scale_one.connect("value-changed", () => { |
src/Library/demos/Scale/main.js
Outdated
const scale_two = workbench.builder.get_object("two"); | ||
const scale_disabled = workbench.builder.get_object("disabled"); | ||
|
||
scale_one.set_range(true, 50); |
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
scale_one.set_range(true, 50); | ||
|
||
scale_two.set_range(true, 50); | ||
scale_two.set_inverted(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inverted
is verty unusual - I think we can leave it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
src/Library/demos/Scale/main.js
Outdated
if (scale_value === 50) { | ||
console.log("Max Value Reached"); | ||
} else if (scale_value === 1) { | ||
console.log("Min Value Reached"); | ||
} |
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
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"); | ||
} | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
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 |
There was a problem hiding this 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
src/Library/demos/Scale/main.js
Outdated
scale_two.add_mark(100.0, "right", "D"); | ||
scale_two.set_increments(25.0, 25.0); | ||
|
||
scale_disabled.set_show_fill_level(25); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
scale_one.connect("value-changed", () => { | ||
let scale_value = scale_one.get_value(); | ||
if (scale_value === scale_one.adjustment.upper) { | ||
console.log("Max Value Reached"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("Max Value Reached"); | |
console.log("Maximum value reached"); |
src/Library/demos/Scale/main.js
Outdated
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("Min Value Reached"); | |
console.log("Minimum value reached"); |
src/Library/demos/Scale/main.js
Outdated
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.js
Outdated
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"); | ||
} | ||
}); |
There was a problem hiding this comment.
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
src/Library/demos/Scale/main.blp
Outdated
|
||
Scale one { | ||
orientation: horizontal; | ||
margin-bottom: 20; |
There was a problem hiding this comment.
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
Applied Suggested Changes: Updated JS Code and implemented Changes in Blp File as well. |
There was a problem hiding this 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
Added Scale Entry under User Interface Section in Library
Issue workbenchdev/demos#3