Skip to content

Commit

Permalink
Feat: Add slider with value (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Mar 27, 2024
1 parent 7c9490b commit 1916c4b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="flex">
<input type="range" [min]="min()" [max]="max()" [step]="step()" [value]="value()" (input)="value.set(Number(input1.value))" class="form-control" [id]="inputId()" #input1 />
<input type="number" [min]="min()" [max]="max()" [step]="step()" class="form-control" [value]="value()" (input)="value.set(Number(input2.value))" #input2 />
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
div > input {
&:first-child {
flex: 85% 1 1;
margin-right: 1vw;
}
&:last-child {
flex: 15% 1 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Component, effect, input, signal, WritableSignal} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR, ReactiveFormsModule} from "@angular/forms";
import {OnChange, OnTouched} from "../../types/value-accessor";

@Component({
selector: 'app-slider-with-value',
standalone: true,
imports: [
ReactiveFormsModule
],
templateUrl: './slider-with-value.component.html',
styleUrl: './slider-with-value.component.scss',
providers: [
{
provide: NG_VALUE_ACCESSOR,
multi: true,
useExisting: SliderWithValueComponent,
},
]
})
export class SliderWithValueComponent implements ControlValueAccessor {
protected readonly Number = Number;

private onChange: WritableSignal<OnChange<number> | null> = signal(null);
private onTouched: WritableSignal<OnTouched | null> = signal(null);

public inputId = input<string>();
public required = input(false);
public min = input<number | null>(null);
public max = input<number | null>(null);
public step = input<number | null>(null);

public disabled = signal(false);

public value = signal(0);

constructor() {
effect(() => {
if (this.onChange() === null) {
return;
}
(this.onChange()!)(this.value());
if (this.onTouched() !== null) {
(this.onTouched()!)();
}
});
}

public registerOnChange(fn: OnChange<number>): void {
this.onChange.set(fn);
}

public registerOnTouched(fn: OnTouched): void {
this.onTouched.set(fn);
}

public setDisabledState(isDisabled: boolean): void {
this.disabled.set(isDisabled);
}

public writeValue(obj: number): void {
this.value.set(obj);
}
}
32 changes: 15 additions & 17 deletions src/app/pages/generate-image/generate-image.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
</div>
@if (form.value.faceFixers?.length) {
<div class="form-group">
<label for="inputFaceFixerStrength">{{ 'app.generate.face_fixer_strength' | transloco }}
({{ form.controls.faceFixerStrength.value! | formatNumber:2 }})</label>
<input type="range" min="0" max="1" step="0.01" formControlName="faceFixerStrength" class="form-control" id="inputFaceFixerStrength"/>
<!--suppress XmlInvalidId -->
<label for="inputFaceFixerStrength">{{ 'app.generate.face_fixer_strength' | transloco }}</label>
<app-slider-with-value [min]="0" [max]="1" [step]="0.01" formControlName="faceFixerStrength" inputId="inputFaceFixerStrength" />
</div>
}
<div class="form-group">
Expand Down Expand Up @@ -186,28 +186,26 @@
<app-effective-value [value]="modifiedOptions()?.height" [original]="form.value.height" />
</div>
<div class="form-group">
<label for="inputDenoisingStrength">{{ 'app.generate.denoising_strength' | transloco }}
({{ form.controls.denoisingStrength.value! | formatNumber:2 }})</label>
<input type="range" min="0.01" max="1" step="0.01" formControlName="denoisingStrength" class="form-control"
id="inputDenoisingStrength"/>
<!--suppress XmlInvalidId -->
<label for="inputDenoisingStrength">{{ 'app.generate.denoising_strength' | transloco }})</label>
<app-slider-with-value [min]="0.01" [max]="1" [step]="0.01" formControlName="denoisingStrength" inputId="inputDenoisingStrength" />
</div>
<div class="form-group">
<label for="inputCfgScale">{{ 'app.generate.cfg_scale' | transloco }}
({{ form.controls.cfgScale.value! | formatNumber:1 }})</label>
<input type="range" min="0" max="100" step="0.5" formControlName="cfgScale" class="form-control"
id="inputCfgScale"/>
<!--suppress XmlInvalidId -->
<label for="inputCfgScale">{{ 'app.generate.cfg_scale' | transloco }}</label>
<app-slider-with-value [min]="0" [max]="100" [step]="0.5" formControlName="cfgScale" inputId="inputCfgScale" />
<app-effective-value [value]="modifiedOptions()?.cfgScale" [original]="form.value.cfgScale" />
</div>
<div class="form-group">
<label for="inputSteps">{{ 'app.generate.steps' | transloco }}
({{ form.controls.steps.value! | formatNumber }})</label>
<input type="range" min="1" max="500" step="1" formControlName="steps" class="form-control" id="inputSteps"/>
<!--suppress XmlInvalidId -->
<label for="inputSteps">{{ 'app.generate.steps' | transloco }}</label>
<app-slider-with-value [min]="1" [max]="500" [step]="1" formControlName="steps" inputId="inputSteps" />
<app-effective-value [value]="modifiedOptions()?.steps" [original]="form.value.steps" />
</div>
<div class="form-group">
<label for="inputClipSkip">{{ 'app.generate.clip_skip' | transloco }}
({{ form.controls.clipSkip.value! | formatNumber }})</label>
<input type="range" min="1" max="12" step="1" formControlName="clipSkip" class="form-control" id="inputClipSkip"/>
<!--suppress XmlInvalidId -->
<label for="inputClipSkip">{{ 'app.generate.clip_skip' | transloco }}</label>
<app-slider-with-value [min]="1" [max]="12" [step]="1" formControlName="clipSkip" inputId="inputClipSkip" />
</div>
<div class="row">
<div class="col-md-6">
Expand Down
4 changes: 3 additions & 1 deletion src/app/pages/generate-image/generate-image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {getFaceFixers, getGenericPostProcessors, getUpscalers} from "../../helpe
import _ from 'lodash';
import {BaselineModel} from "../../types/sd-repo/baseline-model";
import {AutoGrowDirective} from "../../directives/auto-grow.directive";
import {SliderWithValueComponent} from "../../components/slider-with-value/slider-with-value.component";

interface Result {
width: number;
Expand Down Expand Up @@ -103,7 +104,8 @@ interface Result {
LoraTextRowComponent,
IsFaceFixerPipe,
IsUpscalerPipe,
AutoGrowDirective
AutoGrowDirective,
SliderWithValueComponent
],
templateUrl: './generate-image.component.html',
styleUrl: './generate-image.component.scss'
Expand Down

0 comments on commit 1916c4b

Please sign in to comment.