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

Initial implementation of slider widget. #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raghucssit
Copy link

No description provided.

Copy link

Test Results

   341 files  ±0     341 suites  ±0   2m 40s ⏱️ +17s
 3 955 tests ±0   3 671 ✅ ±0  284 💤 ±0  0 ❌ ±0 
11 693 runs  ±0  10 808 ✅ ±0  885 💤 ±0  0 ❌ ±0 

Results for commit 3b1e7d6. ± Comparison against base commit 4f08da9.

@DieterMai
Copy link

Your implementation looks way different then what see for native windows. Did you use some other native implementation as reference?
slider compare

*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
Copy link

Choose a reason for hiding this comment

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

You may add yourself.

case SWT.MouseUp -> onMouseUp(event);
case SWT.MouseHorizontalWheel -> onMouseHorizontalWheel(event);
case SWT.MouseVerticalWheel -> onMouseVerticalWheel(event);
case SWT.Paint -> onPaint(event);
Copy link

Choose a reason for hiding this comment

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

I'd order the events by importance (most important Paint should come first), but otherwise good to use the light-weight events.

orientation = style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);

super.style |= horizontal ? SWT.HORIZONTAL : SWT.VERTICAL;

Copy link

Choose a reason for hiding this comment

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

Please remove empty lines after { or before }.

private void onMouseVerticalWheel(Event event) {
if (!isVisible()) {
return;
}
Copy link

Choose a reason for hiding this comment

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

IMHO, if not visible, there should not be any event at all. Did you got some while invisible?


private void onMouseHorizontalWheel(Event event) {
if (!isVisible()) {
return;
Copy link

Choose a reason for hiding this comment

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

same

}

if (event.count > 0) {
increment(2);
Copy link

Choose a reason for hiding this comment

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

What means this hard-coded 2? Why not 1?

private void onPaint(Event event) {
if (!isVisible()) {
return;
}
Copy link

Choose a reason for hiding this comment

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

SWT.Paint should not be sent if not visible.

}

private void onMouseDown(Event event) {
// Drag of the thumb.
Copy link

Choose a reason for hiding this comment

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

Should it work for any mouse button? If not, please check with if (event.button != 1) return;



private void onMouseUp(Event event) {
if (isDragging) {
Copy link

Choose a reason for hiding this comment

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

Try with moving the mouse outside the shell and moving it back. There exists a method to get all mouse events (forgot its name).

}

private void onMouseMove(Event event) {

Copy link

Choose a reason for hiding this comment

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

Remove empty line after {

} else {
thumbHovered = false;
redraw();
}
Copy link

Choose a reason for hiding this comment

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

The if-statement is not necessary - thumbHovered = isThumbHovered; redraw(); should do the same.

int height = drawingArea.height;

// Fill background
if (getBackground() != null) {
Copy link

Choose a reason for hiding this comment

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

getBackground() will always return != null.


// Fill background
if (getBackground() != null) {
gc.setBackground(getBackground());
Copy link

Choose a reason for hiding this comment

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

Don't invoke the getter twice but store in local variable.

public void removeSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null)
error(SWT.ERROR_NULL_ARGUMENT);
Copy link

Choose a reason for hiding this comment

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

Should be on same line or as block statement ({ ... }).

* </ul>
*/
public int getIncrement() {
checkWidget();
Copy link

Choose a reason for hiding this comment

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

Probably these checks can be removed for such plain getters. Later, the separate Renderer needs to use these methods and checking for each method is useless wasted CPU time.

private int minMax(int min, int value, int max) {
return Math.min(Math.max(min, value), max);
}

Copy link

Choose a reason for hiding this comment

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

remove empty line

this.pageIncrement = pageIncrement;
}

private int minMax(int min, int value, int max) {
Copy link

Choose a reason for hiding this comment

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

Should be static. Maybe it could be moved to a different utilities class?

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.

3 participants