Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
import Gtk from "gi://Gtk"; | ||
|
||
const scale_one = workbench.builder.get_object("one"); | ||
const scale_two = workbench.builder.get_object("two"); | ||
|
||
function logMarks(scale_value_two) { | ||
const marks = { | ||
25: "Mark A Reached", | ||
50: "Mark B Reached", | ||
75: "Mark C Reached", | ||
100: "Mark D Reached", | ||
}; | ||
if (scale_value_two in marks) { | ||
console.log(marks[scale_value_two]); | ||
} | ||
} | ||
const marks = { | ||
0: "A", | ||
50: "B", | ||
100: "C", | ||
}; | ||
|
||
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"); | ||
scale_two.set_increments(25.0, 25.0); | ||
for (const [value, label] of Object.entries(marks)) { | ||
scale_two.add_mark(value, Gtk.PositionType.RIGHT, label); | ||
} | ||
scale_two.set_increments(25, 100); | ||
|
||
scale_one.connect("value-changed", () => { | ||
let scale_value = scale_one.get_value(); | ||
const scale_value = scale_one.get_value(); | ||
if (scale_value === scale_one.adjustment.upper) { | ||
console.log("Maximum Value Reached"); | ||
console.log("Maximum value reached"); | ||
} else if (scale_value === scale_one.adjustment.lower) { | ||
console.log("Minimum Value Reached"); | ||
console.log("Minimum value reached"); | ||
} | ||
}); | ||
|
||
scale_two.connect("value-changed", () => { | ||
let scale_value_two = scale_two.get_value(); | ||
logMarks(scale_value_two); | ||
const scale_value = scale_two.get_value(); | ||
const label = marks[scale_value]; | ||
if (!label) return; | ||
|
||
console.log(`Mark ${label} reached`); | ||
}); |